Skip to Content

Python – Multiply Two Complex Numbers

In this tutorial, we will look at how to multiply two complex numbers together in Python with the help of some examples.

multiply two complex numbers in Python

When you multiply two complex numbers, for example, a+bj and c+dj, the resulting complex number is (ac-bd)+(ad+bc)j. Note that multiplying the imaginary unit with itself results in the real value -1,
j*j = -1.

How to multiply two or more complex numbers in Python?

You can use the multiplication operator * to multiply two or more complex numbers in Python. The following is the syntax –

# multiply complex numbers z1 and z2
z1*z2

It gives you the complex number resulting from multiplying the components (both real and imaginary) with each other.

Examples

Let’s now look at some examples of using the above syntax to multiply some complex numbers together.

Example 1 – Multiply two complex numbers

Let’s multiply two complex numbers (both having non-zero real and imaginary parts) together using the * operator.

# two complex numbers
z1 = 2+3j
z2 = 3+4j
# multiply complex numbers
print(z1*z2)

Output:

(-6+17j)

We get the resulting complex number. When we multiply (2+3j) with (3+4j), we get
2*3 + 2*4j + 3j*3 + 3j*4j which you can simply to (6-12) + (8+9)j, thus resulting in -6+17j.

Note that the multiplication operation in mathematics is commutative, that is,
z1*z2 = z2*z1

# multiply complex numbers
print(z2*z1)

Output:

(-6+17j)

We get the same result as above.

Example 2 – Multiply a real number with a complex number

Let’s now multiply a real number (a number without any imaginary component) and a complex number together.

# a real number and a complex number
z1 = 2
z2 = 3+4j
# multiply complex numbers
print(z1*z2)

Output:

(6+8j)

We get the resulting complex number.

You can see when you multiply a real number with a complex number the real number acts as a scaling factor to scale the complex number.

Example 3 – Multiply an imaginary number with a complex number

Let’s now multiply an imaginary number with a complex number.

# an imaginary number and a complex number
z1 = 2j
z2 = 3+4j
# multiply complex numbers
print(z1*z2)

Output:

(-8+6j)

We get the resulting complex number.

Summary

In this tutorial, we looked at how we can use the multiplication operator, * in Python to multiply two or more complex numbers in Python. In complex number multiplication (similar to normal multiplication) each component of one number is multiplied with each component of the other number (irrespective of whether it’s real or imaginary).

You may also be interested in –


Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.


Author

  • Piyush

    Piyush is a data scientist passionate about using data to understand things better and make informed decisions. In the past, he's worked as a Data Scientist for ZS and holds an engineering degree from IIT Roorkee. His hobbies include watching cricket, reading, and working on side projects.