Complex Numbers
Complex Numbers
SCIENTIFIC
PROGRAMMING
Computational Methods in Nuclear Physics
NS 1003
BASICS OF SCIENTIFIC
PROGRAMMING
𝑥2 - 4 = 0
Solving quadratics
𝑥2 - 4 = 0
𝑥2 = 4
x= ± 4
x=±2
Solve
𝑥2 + 1 = 0
Solving quadratics
𝑥2 + 1 = 0
𝑥 2 = -1 ;no real solutions
Then; 𝑥 2 = -1
x = ± −1
x=±i
It's any
number
you can
imagine
7
i 2 = −1
i = i i = −i
3 2
i = i i = −1 −1 = 1
4 2 2
i = i i = 1 i = i
5 4
...
8
USING I
Now we can handle quantities that
occasionally show up in mathematical
solutions
−a = −1 a = i a
What about
−49 −18
9
−49 −18
i.7
7i
10
COMPLEX NUMBERS
3
3 + 4i −6 + i 4.5 + i 2 6
2
Visualization
12
COMPLEX PLANE
y
Imaginary Axis
Real Axis x
13
FORM OF COMPLEX NUMBER
Imaginary Axis
( x, y )
z = x + iy r
z
Real Axis
14
COMPLEX NUMBERS IN PYTHON
z = 3.14 + 2.71j
type(z)
3. The real part can be accessed.
x=3
y=2
z = complex(x,y);
print ("The real part of complex number is : ",end="")
print (z.real)
4. The imaginary part can be be accessed.
x=3
y=2
z = complex(x,y);
|3 + 2i| = 131/2
5. When a complex number is passed as an argument
to abs() function, it returns the magnitude of the
complex number.
z = 3 + 2j
print('Absolute value of 3 + 2j is:', abs(z))
Argument/Phase of the complex number
33
Addition
z1 = 2 + 3j
z2 = 4 + 5j
z1 + z2
(6+8j)
z = 2 + 3j
z + 7 # Add complex to integer
(9+3j)
Subtraction
z1 = 2 + 3j
z2 = 4 + 5j
z1 - z2
(-2-2j)
Multiplication
The
product of two or more complex
numbers gets more interesting:
z1 = 2 + 3j
z2 = 4 + 5j
z1 * z2
(-7+22j)
Multiplication of Two Complex Numbers
37
Solve z1.z2
z1 = 2 + 3j
z2 = 4 + 5j
Division
z1 = 2 + 3j
z2 = 4 + 5j
DIVISION OF TWO COMPLEX NUMBERS
Multiply numerator and denominator by the
conjugate of the denominator
3i 3i 5 + 2i
=
5 − 2i 5 − 2i 5 + 2i
15i + 6i 2
=
25 − 4i 2
−6 + 15i 6 15
= =− + i
29 29 29
40
z1 = 2 + 3j
z2 = 4 + 5j
Find z1/z2
Note that complex numbers don’t
support floor division, also known as integer
division:
z1 // z2 ---------Error
z1 // 3.14 ---------Error
Example 3:
−16 −49
43
Exponentiation
z = 3 + 2j
Find 𝑧 2
z = 3 + 2j
z**2
(5+12j)
pow(z, 2)
(5+12j)
Example 4
a = 3 + 2i and b = 4 + 5i.
Find the;
Magnitude of a
Angle of a
Real part of a
Imaginary part of a
Conjugate of a
𝑎
a+b, a –b, 𝑏, a×b, 𝑎2