Module # ONE



Module # TWO

Complex Numbers

using

MatLab

By Professor Mohamad H. Hassoun

Department of Electrical & Computer Engineering

Wayne Satate University

Detroit, MI 48202

October 22, 1996

Contents:

I. What Are Complex Numbers and Why Study Them?

II. Complex Algebra

III. Polar Form

IV. Exponential Form

V. Trigonometric & Hyperbolic Functions & Logarithms

clear % Just to make sure that no MatLab variables are present from a previous session.

NOTE on executing commands (green colored text) in this document: place the cursor on the command/MatLab expression you wish to execute and then type Ctrl-Enter. Make sure that variables/array definitions commands are executed before executing any following commands which depend on such definitions. Definitions in bold blue font execute automatically when you open this document; i.e., you nedd not re-execute them over.

You can get full explanation (help) of any MatLab command in this document by highlighting that command and clicking on the '?' in the bar menu above (or type Ctrl-F1).

I. What Are Complex Numbers and Why Study Them?

Definition

A complex number z is an ordered pair (x, y) of real numbers x and y written as z = x + i*y [or as (0, 1)] where by definition i = (-1)1/2 (or i2 = -1) is the imaginary unit i = 0 + i*1.0). x is called the real part of z and y is called the imaginary part of z. In circuit theory, j is used to replace i in order not to confuse the imaginary unit with the symbol for electric current. i (and j) are already defined for you in MatLab:

i

ans =

0 + 1.0000i

j

ans =

0 + 1.0000i

sqrt(-1)

ans =

0 + 1.0000i

i^2

ans =

-1.0000 + 0.0000i

The real and imaginary parts of a complex number are evaluated as follows:

z = -2.5 + 3i

z =

-2.5000 + 3.0000i

real(z)

ans =

-2.5000

imag(z)

ans =

3

Where do Complex Numbers Come From

Complex numbers arise from solving for the roots of polynomial equations (polynomials appear in the solution of linear differential equations and in solving for the eigenvalues of a matrix). First to use complex numbers was the Italian mathemetician Girolamo Cardano (1501-1576). The term "complex number" was introduced by the German mathematician Carl F. Gauss.

Examples #1: Solve for the roots of the equation x2 -10x + 40 =0:

solve('x^2-10*x+40=0')

ans =

[5+i*15^(1/2)]

[5-i*15^(1/2)]

numeric(ans) % give numerical answer

ans =

5.0000 + 3.8730i

5.0000 - 3.8730i

Example # 2: Find the eigenvalues of matrix A, where A is given by

A = [.5,.5,1,-1;1,-1,-1,-1;-1,-.25,1,1;1,-1,-8,1]

A =

0.5000 0.5000 1.0000 -1.0000

1.0000 -1.0000 -1.0000 -1.0000

-1.0000 -0.2500 1.0000 1.0000

1.0000 -1.0000 -8.0000 1.0000

The eigenvalues are

eig(A)

ans =

1.4307 + 3.0894i

1.4307 - 3.0894i

-1.3205

-0.0408

of which two are complex numbers.

NOTE: In fact these eigenvalues are the roots of the fourth degree characteristic polynomial of A, namely |xI - A| = 0, as seen below:

B = sym('[x,0,0,0;0,x,0,0;0,0,x,0;0,0,0,x]')

B =

[x,0,0,0]

[0,x,0,0]

[0,0,x,0]

[0,0,0,x]

p = determ(symsub(B,sym(A)))

p =

x^4-3/2*x^3+31/4*x^2+125/8*x+5/8

pretty

4 3 2

x - 3/2 x + 31/4 x + 125/8 x + 5/8

Verification (solving for the roots of p = 0):

numeric(solve(p, 'x'))

ans =

1.4307 + 3.0894i

1.4307 - 3.0894i

-0.0408

-1.3205

It is an interesting fact that if a polynomial with real valued coefficients has a complex root z1 = a + ib, then it must also have z2 = a - ib as its root. z2 is called the complex conjugate of z1. The conj comman computes the conjugate of a complex number

z=1-5i

z =

1.0000 - 5.0000i

conj(z)

ans =

1.0000 + 5.0000i

II. Complex Algebra

The following are examples of addition, subtraction, multiplication and division of complex numbers. We illustrate these operations with the two complex numbers 4 -5i and 2 + 3i.

z1=4-5i, z2=2+i*3

z1 =

4.0000 - 5.0000i

z2 =

2.0000 + 3.0000i

3*z2 % multiplication by a real number c: c*(a1 + ib1) = (c*a1) + i(c*b1)

ans =

6.0000 + 9.0000i

z1+z2 % addition: (a1 + ib1) + (a2 + ib2) = (a1+a2) + i(b1+b2)

ans =

6.0000 - 2.0000i

z1-z2 % addition: (a1 + ib1) - (a2 + ib2) = (a1-a2) + i(b1-b2)

ans =

2.0000 - 8.0000i

3*z1-6*z2

ans =

0 -33.0000i

z1*z2 % multiplication: (a1 + ib1)(a2 + ib2) = (a1a2 - b1b2) + i(a1b2 + b1a2)

ans =

23.0000 + 2.0000i

z1*conj(z1) % multiplication by the conjugate: (a1 + ib1)(a1 - ib1) = (a1a1 + b1b1)

ans =

41

z1/z2 % division: (a1 + ib1)/(a2 + ib2) = [(a1a2 + b1b2) +i(a1b2 + b1a2)]/(a2a2 + b2b2)

ans =

-0.5385 - 1.6923i

z1 + conj(z1)

ans =

8

z1^2

ans =

-9.0000 -40.0000i

sqrt(z1)

ans =

2.2807 - 1.0962i

i^2

ans =

-1.0000 + 0.0000i

i^3

ans =

0.0000 - 1.0000i

i^4

ans =

1.0000 - 0.0000i

i^5

ans =

0.0000 + 1.0000i

III. Polar Form

The manipulation of complex algebriac expressions may be made easier by employing polar representation of complex numbers. The polar form of a complex number is obtained by viewing a complex number z as a vector (with magnitude r and angle q) in the complex plane: a plane where the x-axis represents the real part of z and the y axis represents the imaginary part of z. Then, one may use the polar-to-rectangular transformation: x = r cos q and y = r sin q. Hence, we may now write z = x + iy = r(cos q + i sin q). The inverse transformation from rectangular to polar form is given by: r = (x2 + y2)-1/2 and q =arc tan(y/x), where q is measured in radians and positive in the counterclockwise sense. MatLab has two convenient commants for computing the magnitude (abs) and angle (angle) of a complex number.

z1

z1 =

4.0000 - 5.0000i

abs(z1), angle(z1)

ans =

6.4031

ans =

-0.8961

This is the explicit way of computing the angle of z1

atan(-5/4)

ans =

-0.8961

which we can express in degrees as

ans*180/pi

ans =

-51.3402

Therefore, z1 = 4 - i5 may be represented in the complex plane as a vector originating at the origion and extending 6.4031 units in a dirstion making an angle of 51.3402 degrees w.r.t. the x-axis in the clockwise direction (because of the negative sign!).

IV. Exponential Form

The exponential form of a complex number is a convenient way of expressing a complex number which renders it amenable to analytic manipulation. In the following, we utilize MatLab's symbolic manipulation features to show that a complex number z with magnitude r and angle q may be expressed as the product of r and the exponential term eiq; i.e., z = reiq

The idea here is to show that z = r(cos q + i sin q) = reiq, or eiq = cos q + i sin q. This last expression is known as Euler's (pronounced Oiler's) formula. Let us express eiq as a power series using Taylor's series expansion at zero:

taylor('exp(i*x)') % we use x in place of q

ans =

1+i*x-1/2*x^2+(-1/6*i)*x^3+1/24*x^4+(1/120*i)*x^5+O(x^6)

pretty

2 3 4 5 6

1 + i x - 1/2 x - 1/6 i x + 1/24 x + 1/120 i x + O(x )

The above expansion may be rearranged as: [1 -1/2 x2 + 1/24 x4 + O(x6)] + i [x - 1/6 x3 + 1/120 x5 + O(x7)] which is equal to cos(x) + i sin(x) since the power series representations for cos(x) and sin(x) are, respectively,

pretty(taylor('cos(x)'))

2 4 6

1 - 1/2 x + 1/24 x + O(x )

and

pretty(taylor('sin(x)'))

3 5 6

x - 1/6 x + 1/120 x + O(x )

This completes the proof that eiq = cos q + i sin q, and therefore r(cos q + i sin q) = reiq.

Multiplication & Division in Polar/Exponential Form

The exponential form allows us to derive simple expressions for computing the magnitude and angle of the product or ratio of two complex numbers given in polar form. Given z1 = r1eiq1 and z2 = r2eiq2, then z1z2 = r1r2 r1ei(q1 + q2) = r1r2[cos (q1 + q2) + i sin (q1+ q2)] (and z1/z2 = (r1/r2) ei(q1 - q2) = (r1/r2)[cos (q1 - q2) + i sin (q1- q2)]. One can also easily show that zn = (reiq)n = rn ei n = rn [cos nq + i sin nq]. Here are some examples:

exp(i*pi) % should give us cos(p) + i sin(p) = -1

ans =

-1.0000 + 0.0000i

exp(i*2*pi)

ans =

1.0000 - 0.0000i

exp(i*pi/2)

ans =

0.0000 + 1.0000i

z1=2*exp(i*pi/4)

z1 =

1.4142 + 1.4142i

compare to

2*(cos(pi/4) + i*sin(pi/4))

ans =

1.4142 + 1.4142i

We can retain the symbolic (exponential) representation of z1 by using the command

z1='2*exp(i*pi/4)'

z1 =

2*exp(i*pi/4)

z2='-exp(i*pi/3)'

z2 =

-exp(i*pi/3)

z1z2 = symmul(z1,z2);

numeric(z1z2) % symbolic multiplication

ans =

0.5176 - 1.9319i

abs(z1z2)

ans =

2.0000

angle(z1z2)

ans =

-1.3090

Verification: z1*z2 = (2)*(-1)*exp[i(p/4-p/3)] = -2*exp(i7p/12) = 2*exp(ip)*exp(i7p/12) = 2*exp(i19p/12) = 2*exp[i(2p - 5p/12)] = 2*exp(i2p)*exp[i(-5p/12)] = 2*exp[i(-1.3090p), which represents the complex number with magnitude 2 and angle -1.3090 radians (note that we have used the fact that exp(i2p) = 1).

Roots

The nth root (n =1, 2, 3, ... ) of a complex number z1/n = (reiq)1/n has precisely n solutions. The formula for obtaining such roots is given by r1/n {cos [(q + 2kp)/n] + i sin [(q + 2kp)/n]}, for k = 0, 1, 2, ..., n-1. Let us compute the 4th root of unity (should get 1, i, -1, -I):

r=1; % magnitude of z

a=0; % angle of z

n=4;

for k=0:n-1

r^(1/n)*(cos((a+2*k*pi)/n) + i*sin((a+2*k*pi)/n))

end

ans =

1

ans =

0.0000 + 1.0000i

ans =

-1.0000 + 0.0000i

ans =

0.0000 - 1.0000i

Roots of a complex coefficient polynomial

The solve command which solves for the roots of a symbolic polynomial also work for situations where some or all of the polynomial coefficients are complex valued. Here is an example:

z_roots = solve('z^2 - (5+i)*z + 8 + i = 0')

z_roots =

[5/2+1/2*i+1/2*2^(1/2)*(-4+3*i)^(1/2)]

[5/2+1/2*i-1/2*2^(1/2)*(-4+3*i)^(1/2)]

numeric(z_roots)

ans =

3.0000 + 2.0000i

2.0000 - 1.0000i

Answer verification:

expand('(x-(3+2*i))*(x-(2-i))')

ans =

x^2-5*x-i*x+8+i

V. Trigonometric Functions, Hyperbolic Functions

Euler's formula can be used to extend trigonometric functions for the case of complex arguments. By addition and subtraction of the two equations exp(ix) = cos x + i sin x and exp(-ix) = cos x - i sin x we obtain for the real cos and sin:

cos x = (1/2)[exp(ix) + exp(-ix)] and sin x = (1/2i)[exp(ix) - exp(-ix)]

This may be generalized to complex values z = x + iy:

cos z = (1/2)[exp(iz) + exp(-iz)] and sin z = (1/2i)[exp(iz) - exp(-iz)]

MatLab allows complex arguments for its sin & cos functions:

cos(2+3i)

ans =

-4.1896 - 9.1092i

sin(2+3i)

ans =

9.1545 - 4.1689i

sin(i)

ans =

0 + 1.1752i

MatLab also allows complex arguments for other built-in functions:

cosh(-2+3i)

ans =

-3.7245 - 0.5118i

sinh(2+i)

ans =

1.9596 + 3.1658i

log(1*exp(i*pi/2)) % ln(r*exp(iq)) = ln(r) + ln(exp(iq)) = ln(r) + iq

ans =

0 + 1.5708i

log(i)

ans =

0 + 1.5708i

log(1+i)

ans =

0.3466 + 0.7854i

log(-1)

ans =

0 + 3.1416i

YOU ARE NOW READY TO MOVE ON TO OTHER EXCITING COMPUTATIONS

WITH MATLAB !!!

(Other Modules Available:

Calculus, Linear Algebra, & Differential Equations)

who % Please go to page 1 and read the small print!!

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download