Python cmath.acos() Method with Examples

cmath.acos() Method in Python:

The cmath.acos() method returns the complex number’s arc cosine.

There are two types of branch cuts:

  1. Extends to the right from 1 to ∞ along the real axis.
  2. Extends to the left from -1 to -∞ along the real axis.

Syntax:

cmath.acos(x)

Parameters

x: This is Required. It is a number that can be used to calculate the arc cosine of

Return Value:

Returns a complex value that represents a number’s arc cosine.

If the return value is expressed as a real number, it has an imaginary part of 0.

Examples:

Example1:

Input:

Given Complex Number = 3+4j

Output:

The given complex number's (3+4j)  arc cosine value = 
(0.9368124611557198-2.305509031243477j)

Example2:

Input:

Given realpart = 5
Given imaginary part = 2

Output:

The given complex number's (5+2j)  arc cosine value = 
(0.38656464251987466-2.37054853731792j)

Note: The above input format is for dynamic input.

cmath.acos() Method with Examples in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Import cmath module(for complex number operations) using the import keyword.
  • Give the complex number as static input and store it in a variable.
  • Pass the given complex number as an argument to the cmath.acos() method that returns the given complex number’s arc cosine value.
  • Store it in another variable.
  • Print the arc cosine value of the given complex number.
  • The Exit of the Program.

Below is the implementation:

# Import cmath module(for complex number operations) using the import keyword.
import cmath
# Give the complex number as static input and store it in a variable.
gvn_numb = 3+4j
# Pass the given complex number as an argument to the cmath.acos() method that
# returns the given complex number's arc cosine value.
# Store it in another variable.
rslt = cmath.acos(gvn_numb)
# Print the arc cosine value of the given complex number.
print("The given complex number's", gvn_numb, " arc cosine value = ")
print(rslt)

Output:

The given complex number's (3+4j)  arc cosine value = 
(0.9368124611557198-2.305509031243477j)

Method #2: Using Built-in Functions (User Input)

Approach:

  • Import cmath module(for complex number operations) using the import keyword.
  • Give the real part and imaginary part of the complex number as user input using map(), int(), split().
  • Store it in two variables.
  • Using a complex() function convert those two variables into a complex number and store it in a variable.
  • Pass the given complex number as an argument to the cmath.acos() method that returns the given complex number’s arc cosine value.
  • Store it in another variable.
  • Print the arc cosine value of the given complex number.
  • The Exit of the Program.

Below is the implementation:

# Import cmath module(for complex number operations) using the import keyword.
import cmath
# Give the real part and imaginary part of the complex number as user input
# using map(), int(), split().
# Store it in two variables.
realnumb, imaginarynumb = map(int, input(
    'Enter real part and complex part of the complex number = ').split())
# Using a complex() function convert those two variables into a complex number.
complexnumb = complex(realnumb, imaginarynumb)
# Pass the given complex number as an argument to the cmath.acos() method that
# returns the given complex number's arc cosine value.
# Store it in another variable.
rslt = cmath.acos(complexnumb)
# Print the arc cosine value of the given complex number.
print("The given complex number's", complexnumb, " arc cosine value = ")
print(rslt)

Output:

Enter real part and complex part of the complex number = 5 2
The given complex number's (5+2j) arc cosine value = 
(0.38656464251987466-2.37054853731792j)