Complex Numbers in Python and intro to class
To define a complex number in python use j
, equivalent to i
in maths, which is nothing but our old friend iota
square root of negative one.
\(j = \sqrt{-1}\) \(z = a+bj\)
Complex numbers arithmetic
z = 5+2j
w = 5+5j
print('Addition: ',z+w)
print('Substraction: ',z-w)
print('Multiplication: ',z*w)
print('Division: ',z/w)
Output
Addition: (10+7j)
Substraction: -3j
Multiplication: (15+35j)
Division: (0.7-0.3j)