11
Complex Numbers in MATLAB
Lecture Series - 2
by
Shameer Koya
2
Complex Plane
Real Axis x
y
Imaginary Axis
3
Form of Complex Number
Real Axis
Imaginary Axis
( , )x y

z
r
x iy z
4
Conversion Between Forms
cosx r 
siny r 
Polar to Rectangular:
Rectangular to Polar:
2 2
r x y 
1
ang( ) tan
y
x
 
 z
5
Euler’s Formula
cos sin (cos sin )r ir r i      z
i
re
z
i
re r

Common Engineering Notation:
cos sini
e i
  
6Convert the complex number to polar form:
4 3i z
2 2 2 2
(4) (3) 5r x y    
1 3
tan 36.87 0.6435 rad
4
 
  
5 36.87 or z
0.6435
5 i
ez
7Convert the complex number to polar form:
4 3i  z
2 2 2 2
( 4) (3) 5r x y     
1 13 3
tan 180 tan
4 4
180 36.87 143.13 2.498 rad
   
   
 
   
2.498
5 i
ez
8
Convert the complex number to
rectangular form:
2
4 i
ez
4cos2 1.6646x   
4sin2 3.6372y  
1.6646 3.6372i  z
9Addition of Two Complex Numbers
1 1x iy 1z
2 2x iy 2z
1 1 2 2
1 2 1 2( )
x iy x iy
x x i y y

   
   
sum 1 2z z + z
A geometric interpretation of addition is
shown on the next slide.
10
Addition of Two Complex Numbers
Real Axis
Imaginary Axis
1z
2z
2z
sumz
11
Subtraction of Two Complex Numbers
1 1x iy 1z
2 2x iy 2z
A geometric interpretation of subtraction
is shown on the next slide.
1 1 2 2
1 2 1 2
( )
( )
x iy x iy
x x i y y

   
   
diff 1 2z z - z
12
Subtraction of Two Complex Numbers
Real Axis
Imaginary Axis
1z
2z
 2z
diffz
 2z
13Multiplication in Polar Form
1
1
i
re
1z
2
2
i
r e
2z
  1 2
1 2
1 2
( )
1 2
i i
i
re r e
rr e
 
 


prod 1 2z = z z
14Division in Polar Form
1
1
i
re
1z
2
2
i
r e
2z
 
 
1
2
1 2
1
2
( )1
2
i
i
i
re
r e
r
e
r


 


1
div
2
z
z =
z
15
Multiplication in Rectangular Form
1 1x iy 1z
2 2x iy 2z
1 1 2 2
2
1 2 1 2 2 1 1 2
( )( )x iy x iy
x x ix y ix y i y y
  
   
prodz
1 2 1 2 1 2 2 1( )x x y y i x y x y   prodz
16
Complex Conjugate
Start with
i
x iy re
  z
The complex conjugate is
i
x iy re 
  z
2 2 2
The product of and is
( )( )
z z
x y r  z z
17
Division in Rectangular Form
1 1
2 2
x iy
x iy

 

1
div
2
z
z
z
1 1 2 2
2 2 2 2
1 2 1 2 2 1 1 2
2 2
2 2
1 2 1 2 2 1 1 2
2
( )( )
( )( )
( )
( )
x iy x iy
x iy x iy
x x y y i x y x y
x y
x x y y i x y x y
r
 

 
  


  

divz
18
Exponentiation of Complex Numbers:
Integer Power
N
powerz = (z)
( )
cos sin
i N N iN
N N
re r e
r N ir N
 
 
 
 
powerz
cos Re( )iN
N e 
 
sin Im( )iN
N e 
 
MATLAB Complex Operations
 Complex number
 Construct complex data from real and imaginary
components
>> c = complex(a,b)
>> z = 3 + 4i
z =
3.0000 + 4.0000i
>> z = 3 + 4j
z =
3.0000 + 4.0000i
19
20
MATLAB Complex Number Operations:
Entering in Polar Form
>> z = 5*exp(0.9273i)
z =
3.0000 + 4.0000i
>> z = 5*exp((pi/180)*53.13i)
z =
3.0000 + 4.0000i
This result indicates that polar to rectangular
conversion occurs automatically upon entering the
number in polar form.
21
Rectangular to Polar Conversion
>> z = 3 + 4i
z =
3.0000 + 4.0000i
>> r = abs(z)
r =
5
>> theta = angle(z)
theta =
0.9273
22
Real and Imaginary and Conjugate
>>real(z)
ans =
3
>> imag(z)
ans =
4
>> z1 = conj(z)
z1 =
3.0000 - 4.0000i
Complex Algebra
 Z1 = 3+4i
 Z2 = 2-5i
 Z3 = Z1+Z2
 Z4 = Z1-Z2
 Z5 = Z1*Z2
 Z6 = Z1/Z2
23
Plotting complex number
 Use simple ‘plot’ function
 Plot (real, imaginary)
 Use ‘compass’ function
 Compass (z)
24
Exercise
 a= 3+2i b= 4+5i
 Find
 Magnitude of a
 Angle of a
 Real part of a
 Imaginary part of a
 Conjugate of a
 Plot a and b using ‘plot’ and ‘compass’
 a+b, a-b, a/b, a*b, a2
25
26
Thanks
Questions ??

Matlab complex numbers

  • 1.
    11 Complex Numbers inMATLAB Lecture Series - 2 by Shameer Koya
  • 2.
    2 Complex Plane Real Axisx y Imaginary Axis
  • 3.
    3 Form of ComplexNumber Real Axis Imaginary Axis ( , )x y  z r x iy z
  • 4.
    4 Conversion Between Forms cosxr  siny r  Polar to Rectangular: Rectangular to Polar: 2 2 r x y  1 ang( ) tan y x    z
  • 5.
    5 Euler’s Formula cos sin(cos sin )r ir r i      z i re z i re r  Common Engineering Notation: cos sini e i   
  • 6.
    6Convert the complexnumber to polar form: 4 3i z 2 2 2 2 (4) (3) 5r x y     1 3 tan 36.87 0.6435 rad 4      5 36.87 or z 0.6435 5 i ez
  • 7.
    7Convert the complexnumber to polar form: 4 3i  z 2 2 2 2 ( 4) (3) 5r x y      1 13 3 tan 180 tan 4 4 180 36.87 143.13 2.498 rad               2.498 5 i ez
  • 8.
    8 Convert the complexnumber to rectangular form: 2 4 i ez 4cos2 1.6646x    4sin2 3.6372y   1.6646 3.6372i  z
  • 9.
    9Addition of TwoComplex Numbers 1 1x iy 1z 2 2x iy 2z 1 1 2 2 1 2 1 2( ) x iy x iy x x i y y          sum 1 2z z + z A geometric interpretation of addition is shown on the next slide.
  • 10.
    10 Addition of TwoComplex Numbers Real Axis Imaginary Axis 1z 2z 2z sumz
  • 11.
    11 Subtraction of TwoComplex Numbers 1 1x iy 1z 2 2x iy 2z A geometric interpretation of subtraction is shown on the next slide. 1 1 2 2 1 2 1 2 ( ) ( ) x iy x iy x x i y y          diff 1 2z z - z
  • 12.
    12 Subtraction of TwoComplex Numbers Real Axis Imaginary Axis 1z 2z  2z diffz  2z
  • 13.
    13Multiplication in PolarForm 1 1 i re 1z 2 2 i r e 2z   1 2 1 2 1 2 ( ) 1 2 i i i re r e rr e       prod 1 2z = z z
  • 14.
    14Division in PolarForm 1 1 i re 1z 2 2 i r e 2z     1 2 1 2 1 2 ( )1 2 i i i re r e r e r       1 div 2 z z = z
  • 15.
    15 Multiplication in RectangularForm 1 1x iy 1z 2 2x iy 2z 1 1 2 2 2 1 2 1 2 2 1 1 2 ( )( )x iy x iy x x ix y ix y i y y        prodz 1 2 1 2 1 2 2 1( )x x y y i x y x y   prodz
  • 16.
    16 Complex Conjugate Start with i xiy re   z The complex conjugate is i x iy re    z 2 2 2 The product of and is ( )( ) z z x y r  z z
  • 17.
    17 Division in RectangularForm 1 1 2 2 x iy x iy     1 div 2 z z z 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1 2 2 2 2 2 1 2 1 2 2 1 1 2 2 ( )( ) ( )( ) ( ) ( ) x iy x iy x iy x iy x x y y i x y x y x y x x y y i x y x y r               divz
  • 18.
    18 Exponentiation of ComplexNumbers: Integer Power N powerz = (z) ( ) cos sin i N N iN N N re r e r N ir N         powerz cos Re( )iN N e    sin Im( )iN N e   
  • 19.
    MATLAB Complex Operations Complex number  Construct complex data from real and imaginary components >> c = complex(a,b) >> z = 3 + 4i z = 3.0000 + 4.0000i >> z = 3 + 4j z = 3.0000 + 4.0000i 19
  • 20.
    20 MATLAB Complex NumberOperations: Entering in Polar Form >> z = 5*exp(0.9273i) z = 3.0000 + 4.0000i >> z = 5*exp((pi/180)*53.13i) z = 3.0000 + 4.0000i This result indicates that polar to rectangular conversion occurs automatically upon entering the number in polar form.
  • 21.
    21 Rectangular to PolarConversion >> z = 3 + 4i z = 3.0000 + 4.0000i >> r = abs(z) r = 5 >> theta = angle(z) theta = 0.9273
  • 22.
    22 Real and Imaginaryand Conjugate >>real(z) ans = 3 >> imag(z) ans = 4 >> z1 = conj(z) z1 = 3.0000 - 4.0000i
  • 23.
    Complex Algebra  Z1= 3+4i  Z2 = 2-5i  Z3 = Z1+Z2  Z4 = Z1-Z2  Z5 = Z1*Z2  Z6 = Z1/Z2 23
  • 24.
    Plotting complex number Use simple ‘plot’ function  Plot (real, imaginary)  Use ‘compass’ function  Compass (z) 24
  • 25.
    Exercise  a= 3+2ib= 4+5i  Find  Magnitude of a  Angle of a  Real part of a  Imaginary part of a  Conjugate of a  Plot a and b using ‘plot’ and ‘compass’  a+b, a-b, a/b, a*b, a2 25
  • 26.