Python cMath Module
Basic Complex Number Functions:
cmath.sqrt()
: Calculates the square root of a complex number.cmath.exp()
: Calculates the exponential of a complex number.cmath.log()
: Calculates the natural logarithm of a complex number.cmath.log10()
: Calculates the base-10 logarithm of a complex number.cmath.sin()
: Calculates the sine of a complex number.cmath.cos()
: Calculates the cosine of a complex number.cmath.tan()
: Calculates the tangent of a complex number.cmath.asin()
: Calculates the arcsine of a complex number.cmath.acos()
: Calculates the arccosine of a complex number.cmath.atan()
: Calculates the arctangent of a complex number.cmath.sinh()
: Calculates the hyperbolic sine of a complex number.cmath.cosh()
: Calculates the hyperbolic cosine of a complex number.cmath.tanh()
: Calculates the hyperbolic tangent of a complex number.
Other Complex Number Functions:
cmath.phase()
: Returns the phase angle of a complex number.cmath.polar()
: Converts a complex number to polar coordinates.cmath.rect()
: Converts polar coordinates to a complex number.cmath.isinf()
: Checks if a complex number has an infinite real or imaginary part.cmath.isnan()
: Checks if a complex number is NaN (not a number).
Complex Number Constants:
cmath.pi
: Mathematical constant π (pi) for complex numbers.cmath.e
: Mathematical constant e (Euler's number) for complex numbers.cmath.inf
: Mathematical representation of positive infinity for complex numbers.cmath.nan
: Mathematical representation of NaN (not a number) for complex numbers.
Example of Usage:
import cmath
# Basic Complex Number Functions
sqrt_value = cmath.sqrt(4 + 3j)
log_value = cmath.log(2 + 2j)
sin_value = cmath.sin(1 + 1j)
# Complex Number Constants
pi_value = cmath.pi
e_value = cmath.e
# Other complex number functions and constants can be used similarly
The cmath
module provides mathematical functions specifically tailored for complex numbers, allowing for various complex number calculations and manipulations in Python.