Sunday, June 10, 2018

How are complex numbers handled in Python?

Python uses the same notation used in electrical engineering (or physics)while dealing with complex numbers.

A complex number is represented by x+yi  where x and y are real and i=-1. Also x-yi is called the conjugate of x+yi.

If you multiply i by i the result is -1.

This image from Wikipedia makes it clear.


PythonComplex_0


This is how python handles complex numbers.


PythonComplex_1

Built-in functions abs() and pow() also work with complex numbers.


PythonComplex_2

No comments: