You are on page 1of 19

Name:___________________________ Date:______________

Program & Year:___________________

Experiment 1
MATLAB and Complex Numbers

Objectives
By the end of the experiment, the student should be able to
 define the different MATLAB windows and tools.
 find the difference between a constant, variable and expression.
 demonstrate the different mathematical operations of complex numbers.
 construct a script file for computing complex number.

Tools Required
 Personal Computer/Desktop Computer/Computer Workstation
 MATLAB software

I. COMPLEX NUMBERS

IMAGINARY NUMBER - is a real number with an imaginary operator j.

Ex. j5 , j6 , j8

where: j =  -1 j3 = - j
j2 = -1 j4 = 1

COMPLEX NUMBER - is the sum of the difference of a real number and an imaginary
number.

Ex. 5 + j2 , 6 - j8
Graphical Representation of Complex Numbers

Imaginary Axis 4


3

-4 -3 -2 -1 1 2 3 4
-1
Real Axis

-2

b (a, b)

Polar and Cartesian Form of Complex Numbers

cos θ = a / r ; sin θ = b / r
a = r cos θ ; b = r sin θ
tan θ = y/ x

Using Pythagorean Theorem:

|z| = r = √( a2 + b2)
FORMS OF COMPLEX NUMBERS

( x , y ) Rectangular Form

r = x + jy (also called Cartesian Form)


where :
x = real quantity
y = imaginary quantity

Polar Form

Z = r  0
where:
r = magnitude
= distance of the pt. (a,b) from the
origin
= modulus of the complex no. Z
( always a non-negative number
and is denoted |z| )
 = angle with respect to the positive x
axis in degrees.
= argument of Z denoted as arg (z)

Note:  is positive when measured counter clockwise and negative when measured
clockwise with respect to the positive x axis.

Expressing Z = a + jb in polar form

Z = r cos θ + j r sin θ
= r ( cos θ + j sin θ )
Z=rθ

Note that
r  - θ = r ( cos(-θ) + j sin (-θ))
= r (cos - j sin θ)
= z (bar)

Thus,
If z = a + jb then z = a – jb and
z = r ( - θ)
Trigonometric Form

Z = r ( cos  + j sin  )
Z = r cos  + j r sin θ

Exponential Form

Z = r e j
where:
r = magnitude
 = angle in radians

Note:
 in degrees =  / 1800

Euler’s Equation

A cos  + j A sin  = A e j 

Coordinate Conversion

Rectangular form to Polar form

Z = a + jb  r 
where:
r =  a 2 + b2
 = tan -1 ( b/a )

Polar form to Rectangular form

Z = r   a + jb
Where:
x = r cos 
y = r sin 

Complex Conjugate
change the sign of the imaginary part.
Ex.
-7 + j = -7 – j
6 + j5 = 6 – j5
6 = there is no imaginary part to alter
j = -j
Operations of Complex numbers

Addition / Subtraction

A. Rectangular Form

A = x + jy ; B = a + jb

A + B = (x + a) + j (y + b)

B. Polar Form

X = A 1 ; Y = B 2

X = A cos 1 + j A sin 1
Y = B cos 2 + j B sin 2

X + Y = (A cos 1 + B cos 2)


+ j (A sin 1 + B sin 2)

=  [(A cos 1 + B cos 2)2


+ (A sin 1 + B sin 2)2 ]

 tan-1 ( A sin 1 + B sin 2 )


( A cos 1 + B cos 2 )

II. Multiplication

Rectangular Form

A = x + jy ; B = a + jb
A x B = (x + jy) x (a + jb)
A x B = ax + jbx + jay + j2 by
A x B = ( ax - by ) + j( ay + bx )

Polar Form

X = A 1 ; Y = B 2
X  Y = A  B  ( 1 + 2 )
III. Division

Rectangular Form

A = x + jy ; B = a + jb
A = x + jy  a - jb
B a + jb  a - jb
A = ax + jay - jbx - j2 by
B a2 - j2 b2
A = ( ax + by ) + j ( ay - bx )
B a 2 + b2
A = ( ax + by ) + j ( ay - bx )
B a2 + b2 a2 + b2

Polar Form

X = A 1 ; Y = B 2
X = A  1 = A  1- 2
Y B  2 B

Powers and Roots

Real Powers
( A   )n = An    n
= ( A e j    / 180 ) n
= ( An e j    / 180  n )
= ( An    /180  n  180/ )
= An    n

Real Roots
n ( A   ) = n  A  ( /n )

= ( A e j    / 180 ) 1/n
= ( A 1/n e j    / 180  1/n )
= ( A 1/n    /180  1/n  180/ )
= n  A  ( /n )

Complex Powers
( A   ) x + jy = R  
= ( A e j    / 180 ) x + jy
= ( e lnA  e j    / 180 ) x + jy
= ( e lnA + j    / 180 ) x + jy
= ( e xlnA + jx   / 180 + jylnA + j2 y   / 180 )
= ( e ( xlnA - y   / 180 ) + j ( ylnA + x   / 180 ) )
= ( e ( xlnA - y   / 180 )  e j ( ylnA + x   / 180 ) )
= R  e j
R = e ( xlnA - y   / 180 )
 = ( ylnA + x   / 180 )  180 / 

Complex Roots

( A   ) = S  
x + jy

= (A e j    / 180) 1 / ( x + jy )
= (e lnA  e j    / 180) 1 / ( x + jy )
= (e lnA + j    / 180) 1 / ( x + jy )
= (e ( lnA + j    / 180 ) / ( x + jy )) ( x - jy / x - jy )
= (e{( xlnA + j x    / 180 )-( jy lnA+ j2 y  /180)}/{ x2- j2y2 })
= (e(xlnA - y    / 180)/(x2 + y2) e j (- ylnA + x    /180)/(x2+y2))
= S  e j
S = e { (xlnA + y    / 180) / (x2 + y2) }
 = {(- ylnA + x    / 180)/(x2+y2)}  180/

LOGARITHM AND NATURAL LOGARITHM OF COMPLEX NUMBERS

Log ( A   )
= Log ( A  e j    / 180 )
= Log A + Log e j    / 180
= Log A + j    / 180  Log e
= Log A + j    / 180  0.4343

Ln ( A   )
= Ln ( A  e j    / 180 )
= Ln A + Ln e j    / 180
= Ln A + j    / 180  Ln e
= Ln A + j    / 180  1

Log ( - N )
= Log ( N  180 )
= Log N + j 180   / 180  Log e
= Log N + j   0.4343

Ln ( - N )
= Ln ( N  180 )
= Ln N + j 180   / 180  Ln e
= Ln N + j   1

MATLAB Syntax Examples:

complex number
>>sqrt(-1)

Symbolic Equation Solution


x^2 + 1 = 0
>> syms x
>> f = x^2 +1
>> solve (f)

Polynomial Roots
x^2 + 1 = 0
>> p = [1 0 1]
>> roots (p)

Declaring Complex Numbers in MATLAB

3 + 4i
>> c = 3 + 4*i
or
>> c = 3 + 4*j
or
>> c = complex(3,4)

Extracting the real part, imaginary part, absolute value


>> [real(c), imag(c), abs(c)]

Converting cartesian form to polar form using cart2pol

[TH,R] = cart2pol(X,Y) transforms corresponding elements of data


stored in Cartesian coordinates X,Y to polar coordinates (angle TH
and radius R). The arrays X and Y must be the same size (or
either can be scalar). TH is returned in radians.

[TH,R,Z] = cart2pol(X,Y,Z) transforms corresponding elements of


data stored in Cartesian coordinates X,Y,Z to cylindrical
coordinates (angle TH, radius R, and height Z). The arrays X,Y,
and Z must be the same size (or any of them can be scalar). TH is
returned in radians.
>> [TH,R] = cart2pol(3,4)

Converting polar form to cartesian form using pol2cart


[X,Y] = pol2cart(TH,R) transforms corresponding elements of data
stored in polar coordinates (angle TH, radius R) to Cartesian
coordinates X,Y. The arrays TH and R must the same size (or
either can be scalar). TH must be in radians.

[X,Y,Z] = pol2cart(TH,R,Z) transforms corresponding elements of


data stored in cylindrical coordinates (angle TH, radius R, height
Z) to Cartesian coordinates X,Y,Z. The arrays TH, R, and Z must be
the same size (or any of them can be scalar). TH must be in radians.

>> [X,Y] = pol2cart(0.9273,5)

Trigonometric form of a complex number


z = 11(cos(0.7) + isin(0.7)) ; Theta = 0.7 rad
>> z = 11*(cos(0.7) + isin(0.7))
>> [abs(z), angle(z)]

Example: Basic Mathematical Operations


>> c1 = 3 + 4*i
>> c2 = 2 + 4*j
>> c1 + c2
>> c1 - c2
>> c1*c2
>> c1/c2

Plotting Polar Coordinates in MATLAB

MATLAB provide useful plotting functions for general Polar Coordinates


Note: This is not exclusively for Complex Numbers
The MATLAB function polar() achieves this:

Polar coordinate plot.


polar(THETA, RHO) makes a plot using polar coordinates of
the angle THETA, in radians, versus the radius RHO.
polar(THETA, RHO, S) uses the linestyle specified in string S.
See PLOT for a description of legal linestyles.

polar(AX, ...) plots into AX instead of GCA.

H = polar(...) returns a handle to the plotted object in H.

Plotting Polar Representation of a Complex Number


Example
>> z=11*(cos(0.7)+sin(0.7)*i)
>> polar([0 angle(z)],[0 abs(z)],'-r')

Compass plot.
compass(U,V) draws a graph that displays the vectors with
components (U,V) as arrows emanating from the origin.

compass(Z) is equivalent to compass(REAL(Z),IMAG(Z)).

compass(U,V,LINESPEC) and compass(Z,LINESPEC) uses the line


specification LINESPEC (see PLOT for possibilities).

compass(AX,...) plots into AX instead of GCA.

H = compass(...) returns handles to line objects in H.

Example
>> c = complex(3,4)
>> compass (c)

Live Script
MATLAB live scripts and live functions are interactive documents that combine
MATLAB code with embedded output, formatted text, equations, and images in a single
environment called the Live Editor.

Show that Im[jz] = Re[z] and Re[-jz] = Im[z]. Run the following MATLAB program in
order to compute and plot the complex number e^(j*theta) for theta = i*2*pi/360, i = 1,
2,...,360:

j=sqrt(-1)
n=360
for i=1:n,circle(i)=exp(j*2*pi*i/n);end;
axis('square')
plot(circle)

Replace the explicit for loop of line 3 by the implicit loop

circle=exp(j*2*pi*[1:n]);

to speed up the calculation. You can see from the figure below that the complex number
e^(j*theta), evaluated at angles theta = 2*pi/360, 2(2*pi/360),..., turns out complex
numbers that lie at angle theta and radius 1. We say that e^(j*theta) is a complex
number that lies on the unit circle.
The Complex Numbers e^(j*theta) for 0<theta<2*

m-file
Create and run the following script file (name it ComplexNum)

function complexnumbers
j=sqrt(-1);
z1=(1+(j*.5));z2=(2+(j*1.5));
z3=z1+z2;z4=(z1*z2);
z5=conj(z1);z6=(j*z2);
axis([-4 4 -4 4]),axis('square'),plot(z1,'o')
hold on
grid on
plot(z2,'o'),plot(z3,'+'),plot(z4,'*'),
plot(z5,'x'),plot(z6,'x')

Complex Numbers

Exercises:

1. Solve the following equations:


(4+𝑗5)2 [3𝑐𝑗𝑠40+3∠30+7𝑒 𝑗0.363 ]
a. (4+𝑗8)(5𝑐𝑗𝑠25)+(3∠30)2
Answer:_______________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

Syntax:________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
b. (arccot(-jπ/6))/(sinh(0.5+j0.75)
Answer:_______________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

Syntax:________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
√−1
c. ln6 + log(-7) – ln(7+j5)(2+j3) +√−1 + loge(8+j3)
Answer:_______________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

Syntax:________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
(4+𝑗3)+7∠40 6𝑐𝑗𝑠30+9∠−40
d. √ +√ − √(6 + 𝑗3)(4∠40)(7 − 𝑗3)
(3−𝑗8)2 6∠30+𝑗9
Answer:_______________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

Syntax:________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
e. the fourth roots of [(2+Ln(i))^(1/i) + ( i^(sin(1+i))((1+i)^i)]/[ i^(Ln(1+i))]
Answer:_______________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

Syntax:________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
f. the real part and imaginary part of (3 + i2)^(cos(3-j5)) - (1+i*sqrt(5))^(2-j)
Answer:_______________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

Syntax:________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
2. Create an m-file that will perform the basic math operations (addition, subtraction,
multiplication and division), square roots, logarithm, trigonometric and inverse
trigonometric functions of a complex numbers. (at least two rectangular form of complex
numbers will be the input for all of the given operations).
Answer:_______________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

Syntax:________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
If n > 0 is an integer and the four possible values of in are in+1 = i, in+2 = -1, in+3 = -i, in+4 =
1. Show that i1996 = in+4. Use the preceding result in creating an M-file.
Answer:_______________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

Syntax:________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________

You might also like