Working on the science of data, machine learning or scientific calculations, we often have to perform calculations with numerical data types, including complex numbers. In this article, we will use the CMath module in Python to perform operations on complex numbers using various methods provided for in the module.

Calculate the phase of a complex number

The phase of the complex number is defined as the angle between the actual axis and the vector representing the integrated number. Using the cmath module, we can find the phase of the complex number using the Phase () method. The phase method accepts the integrated number as input data and returns the number with a floating comma, representing the phase of the integrated number as follows.

Complex numbers in the polar coordinate system

In the polar coordinate system, the complex number is defined as a motorcade consisting of a comprehensive number module as the first element and phase of a complex number as a second element. We can find the polar coordinates of a complex number using the Polar () method in Python. The Polar () method takes a complex number as input and returns a motorcade representing polar coordinates as follows.

If we know the module and phase of a complex number, i.e. If we know the polar coordinates of a complex number, we can get a complex number using the RECT () method. The RECT () method accepts the module as the first argument and the phase of the integrated number as the second argument and returns the corresponding integrated number as follows.

The CMath module also provides certain mathematical constants, such as infinity, Nan and PI, which are useful in mathematical calculations. Some constants are given in the following example.

Trigonometric functions in the cmath module

For mathematical calculations of complex numbers, the CMath module provides a set of trigonometric functions. All trigonometric functions take a complex number as input data, and also return a complex number, which is the corresponding result of trigonometric functions. Examples are given below.

Hyperbolic functions in the cmath module

Like trigonometric functions, the CMath module also provides hyperbolic functions and reverse hyperbolic functions for mathematical calculations in Python. All these functions take a complex number as input data and return a complex number representing a hyperbolic or trigonometric conclusion. Examples are given below.

Logarithmic functions in the cmath module

The CMath module provides two methods, namely Log () and LOG10 () for logarithmic calculations of complex numbers. The LOG () function takes a complex number as the first argument and an optional argument representing the basis of a logarithmic function. When we convey only a complex number as the input data of the LOG () function, it returns a natural logarithm of the integrated number with the base "E". When we also convey the second argument, that is, the base, to the log () function, it calculates the logarithm of the integrated number with the provided basis. This can be seen on the following example.

The LOG10 () method calculates the logarithm of the complex number on the basis of 10 as follows.

The functions of erects in the degree in the CMath Python module

The CMath module provides two powerful functions, namely EXP () and SQRT () for calculations in Python. The EXP () function accepts a complex number as input and returns a complex number representing the exponential value of the input data. This can be seen on the following example.

The SQRT () function also takes a complex number as input and returns a complex number representing a square root from the input data, as shown below.

In this article, we studied the functions and methods in the CMath module to perform mathematical operations on complex numbers in Python.

Even more useful information in our channels:

HTTPS: //t. T.

#machinelearning #artificialintelligence #ai #datascience #programming #Deechnology #Deeuplearning #bigData #bigdata