Python cMath Module

Basic Complex Number Functions:

  1. cmath.sqrt(): Calculates the square root of a complex number.

  2. cmath.exp(): Calculates the exponential of a complex number.

  3. cmath.log(): Calculates the natural logarithm of a complex number.

  4. cmath.log10(): Calculates the base-10 logarithm of a complex number.

  5. cmath.sin(): Calculates the sine of a complex number.

  6. cmath.cos(): Calculates the cosine of a complex number.

  7. cmath.tan(): Calculates the tangent of a complex number.

  8. cmath.asin(): Calculates the arcsine of a complex number.

  9. cmath.acos(): Calculates the arccosine of a complex number.

  10. cmath.atan(): Calculates the arctangent of a complex number.

  11. cmath.sinh(): Calculates the hyperbolic sine of a complex number.

  12. cmath.cosh(): Calculates the hyperbolic cosine of a complex number.

  13. cmath.tanh(): Calculates the hyperbolic tangent of a complex number.

Other Complex Number Functions:

  1. cmath.phase(): Returns the phase angle of a complex number.

  2. cmath.polar(): Converts a complex number to polar coordinates.

  3. cmath.rect(): Converts polar coordinates to a complex number.

  4. cmath.isinf(): Checks if a complex number has an infinite real or imaginary part.

  5. cmath.isnan(): Checks if a complex number is NaN (not a number).

Complex Number Constants:

  1. cmath.pi: Mathematical constant π (pi) for complex numbers.

  2. cmath.e: Mathematical constant e (Euler's number) for complex numbers.

  3. cmath.inf: Mathematical representation of positive infinity for complex numbers.

  4. 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.

Did you find this article valuable?

Support Namya Shah by becoming a sponsor. Any amount is appreciated!