The complex library implements the complex class to contain complex numbers in cartesian form and several functions and overloads to operate with them. 👁 complex2
- real() - It returns the real part of the complex number.
- imag() - It returns the imaginary part of the complex number.
Real part: 10
Imaginary part: 2
Time Complexity: O(1)
Auxiliary Space: O(1)
- abs() - It returns the absolute of the complex number.
- arg() - It returns the argument of the complex number.
The absolute value of (3,4) is: 5
The argument of (3,4) is: 0.927295
Time Complexity: O(1)
Auxiliary Space: O(1)
- polar() - It constructs a complex number from magnitude and phase angle. real = magnitude*cosine(phase angle) imaginary = magnitude*sine(phase angle)
The complex whose magnitude is 2 and phase angle is 0.5 is (1.75517,0.958851)
Time Complexity: O(1)
Auxiliary Space: O(1)
- norm() - It is used to find the norm(absolute value) of the complex number. If z = x + iy is a complex number with real part x and imaginary part y, the complex conjugate of z is defined as z'(z bar) = x - iy, and the absolute value, also called the norm, of z is defined as : 👁 complex-2
The norm of (3,4) is 25.
Time Complexity: O(1)
Auxiliary Space: O(1)
- conj() - It returns the conjugate of the complex number x. The conjugate of a complex number (real,imag) is (real,-imag).
The conjugate of (10,2) is (10,-2)
Time Complexity: O(1)
Auxiliary Space: O(1)
- proj() - It returns the projection of z(complex number) onto the Riemann sphere. The projection of z is z, except for complex infinities, which are mapped to the complex value with a real component of INFINITY and an imaginary component of 0.0 or -0.0 (where supported), depending on the sign of the imaginary component of z.
proj(1,2) = (1,2)
proj(inf,-1) = (inf,-0)
proj(0,-inf) = (inf,-0)
Time Complexity: O(1)
Auxiliary Space: O(1)
- sqrt() - Returns the square root of x using the principal branch, whose cuts are along the negative real axis.
Square root of -4 is (0,2)
Square root of (-4,-0), the other side of the cut, is (0,-2)
Time Complexity: O(log(n))
Auxiliary Space: O(1)
Next article: Complex numbers in C++ | Set 2