/* jquery */ /* jquery accordion style*/ /* jquery init */

Python Math - Complex Numbers

Python Coding

Imaginary Numbers and Complex Numbers are vital to solving many mathematical problems - including the study of waves, electric motor efficency and fractals.

Python uses the j symbol to represent the imaginary part of a Complex Numbers.

An example of how this is done is shown in the Python Interactive Mode session below...

>>> a = 4 + 3j
>>> print(a)
(4+3j)

Once created a Complex Number can be treated much like any other number, as below...

>>> a = 1 + 2j
>>> b = 2 + 4j
>>> print('Addition =', a + b)
Addition = (3+6j)
>>> print('Subtraction =', a - b)
Subtraction = (-1-2j)
>>> print('Multiplication =', a * b)
Multiplication = (-6+8j)
>>> print('Division =', a / b)
Division = (2+0j)

And you can extract a Complex Number's real and imaginary components as below...

>>> a = 1 + 2j
>>> b = 3 + 5j
>>> c = a + b
>>> c.real
4.0
>>> c.imag
7.0

More Python Math Coding

No comments: