Complex Numbers in Python

We offer you a brighter future with placement-ready courses - Start Now!!

Complex numbers are an extension of the real numbers that include a new imaginary component. The imaginary component is denoted by the letter ‘i’ and is defined as the square root of negative one (-1). Complex numbers have a real and imaginary part, and can be expressed in the form ‘a+bi’. Python provides built-in support for complex numbers and includes various functions to perform arithmetic operations on them. In this blog, we will explore how to simplify complex numbers using Python.

Simplify Complex Numbers With Python

Simplifying complex numbers involves expressing them in a simpler form. The simplest form of a complex number is in the form ‘a+bi’ where a and b are real numbers. Simplifying complex numbers can be done using Python’s built-in functions. Here are the steps to simplify a complex number:

  • Convert the complex number to its polar form using the ‘polar’ function.
  • Simplify the modulus and argument of the polar form.
  • Convert the polar form back to rectangular form using the ‘rect’ function.

Let’s look at an example to understand this in detail.

Example:

Suppose we have a complex number (1+1j). We can simplify this complex number using the above steps as follows:

Step 1: Convert the complex number to its polar form.

import cmath
z = 1 + 1j
z_polar = cmath.polar(z)
print(z_polar)

Output:

(1.4142135623730951, 0.7853981633974483)

Step 2: Simplify the modulus and argument of the polar form.

import math
r = round(z_polar[0], 2)
theta = round(z_polar[1], 2)
theta_deg = round(math.degrees(theta), 2)
print(r, theta, theta_deg)

Output:

1.41 0.79 45.26

Step 3: Convert the polar form back to rectangular form.

z_simplified = cmath.rect(r, theta)
print(z_simplified)

Output:

(0.9924218950696528+1.001598114108827j)

Conclusion

In conclusion, simplifying complex numbers involves converting them to polar form, simplifying the modulus and argument, and converting them back to rectangular form. Python provides built-in support for complex numbers and includes various functions to perform arithmetic operations on them. By following the above steps, we can simplify complex numbers with ease using Python.

Did you like this article? If Yes, please give PythonGeeks 5 Stars on Google | Facebook


PythonGeeks Team

PythonGeeks Team is dedicated to creating beginner-friendly and advanced tutorials on Python programming, AI, ML, Data Science and more. From web development to machine learning, we help learners build strong foundations and excel in their Python journey.

Leave a Reply

Your email address will not be published. Required fields are marked *