Docsity

Understanding MATLAB Complex Numbers and Functions: Built-In and User-Defined Functions, O, Slides of Calculus for Engineers

Partial preview of the text

Download Understanding MATLAB Complex Numbers and Functions: Built-In and User-Defined Functions, O and more Slides Calculus for Engineers in PDF only on Docsity!

Engr/Math/Physics 25

Chp3 MATLAB

Functions: Part

Learning Goals

  • Understand the difference between Built-In

and User-Defined Functions

  • Write User Defined Functions
  • Describe Global and Local Variables
  • When to use SUBfunctions as opposed to

NESTED-Functions

  • Import Data from an External Data-File
    • As generated, for example, by an Electronic

Data-Acquisition System

Getting Help for Functions

  • Use the lookfor command to find functions that

are relevant to your application

  • For example typing lookfor complex returns

a list of functions that operate on complex

numbers (more to come):

>> lookfor complex

ctranspose.m: %' Complex conjugate transpose.

COMPLEX Construct complex result from real and

imaginary parts.

CONJ Complex conjugate.

CPLXPAIR Sort numbers into complex conjugate pairs.

IMAG Complex imaginary part.

REAL Complex real part.

CPLXMAP Plot a function of a complex variable.

Built-In Exponential Functions

Command Conventional Math Function

exp(x) (^) Exponential; e x

sqrt(x) (^) Square root;  x

log(x) (^) Natural logarithm; ln x

log10(x) (^) Common (base 10) logarithm; log x = log 10

x

 Note the use of log for

NATURAL Logarithms and

log10 for “normal” Logarithms

  • This a historical Artifact from the

FORTRAN Language – FORTRAN designers were

concerned with confusing ln with “one-n”

Built-In Rounding Functions

Command Conventional Math Function

ceil(x) (^) Round to nearest integer toward +

fix(x) (^) Round to nearest integer toward zero

floor(x) (^) Round to nearest integer toward −

round(x) (^) Round toward nearest integer.

sign(x)

Signum function:

+1 if x > 0; 0 if x = 0; −1 if x < 0.

Graph

Complex Numbers – Math

  • What do We Do

with?

i  - 1

x   7

 Factoring

x   1  7   1 7

 Let’s Make-Up or

IMAGINE

1 (Engr Def.)

1 (Math Def.)

j

i

 

 

x  2. 646 j

Complex Number, z , Defined

i  j   1

z = x + j y

Real part

x = Re( z )

Imaginary part

y = Im( z )

Complex

numbers

Im(z)  0

Real

numbers

Im( z ) = 0

Re( z )

Im( z )

Complex numbers

Real

numbers

Complex No.s – Basic Rules

 Powers of j j

2 = – 1 j

3 = – j j

4 = + 1 j

- 1 = – j

j

4 n = + 1; j

4 n+ 1 = +j ; j

4 n+ 2 = – 1; j

4 n+ 3 = – j for n = 0 , ± 1 , ± 2 , …

 Equality z

1

= x 1

+ j y 1

z 2

= x 2

+ j y 2

z 1

= z 2,

 x

1

= x 2

AND y 1

= y 2

 Addition

z 1

+ z 2,

= ( x

1

+ x 2

) + j ( y 1

+ y 2

)

i  j   1

Complex No.s – Graphically

x

y

r

z = x + i y

Im( z )

Re( z )

The Argand diagram Modulus (magnitude) of z

arctan

 = arg z =

x

y

  • p, if x < 0

arctan x

y , if x > 0

r = mod z = |z| = x

2 + y

2

x = r cos 

y = r sin 

Argument (angle) of z

Polar form of a complex number z

z = r (cos  + j sin 

i  j   1

Complex No.s – Polar Form

z 1

= r 1

(cos  1

  • j sin  1

z 2

= r 2

(cos  2

  • j sin  2

x

y

r

z = x + j y

Im( z )

Re( z )

|z 1

z 2

| = |z

1

| |z 2

| ; arg( z 1

z 2

) = arg( z 1

) + arg( z 2

)

z 1

z 2

= r

1

r 2

(cos ( 1

  •  2

) + j sin( 1

  •  2

))

= (cos (

1

-  2

) + j sin( 1

-  2

)) z 2

z 1

r 2

r 1

= ; arg( ) = arg( z

1

) – arg( z 2

) |z 2 |

|z 1 |

z 2

z 1

z 2

z 1

 Multiplication

 Division

i  j   1

Polar Multiplication Proof cont

  • Using Trig ID in the Loooong Expression

 So Finally

    

w wd d cos    j sin   

  1 2

cos  

    1 2 1 2 1 2 1 2 1 2 1 2

ww  d d cos cos sin sin  j sin cos cos sin 

  1 2

sin   
i  j   1

De Moivre’s Formula

z 1

z 2

= r

1

r 2

(cos ( 1

  •  2

) + j sin( 1

  •  2

))

z 1 z 2 … z n

= r

1 r 2 … r n [cos ( 1

  •  2  …+n ) + j sin( 1
  •  2  …+n )]

z

n

= r

n z (cos ( n ) + j sin( n )) 1

= z 2

=…= z n

r = 1 (cos  + j sin )

n

= cos ( n ) + j sin( n )

 French Mathematician Abraham de Moivre (1667-1754)

i  j   1

Verify by MuPad

  • From the last Line

(collect comand)

collect real and

imaginary parts

 

 

 (^) ,  2  1 

2 2

h x y y x

h x y xy y

g x y x y x

Euler’s Formula

A complex conjugate is also inverse

A power series for an exponential

    

!

u

!

u e u

u

2 3

1

2 3

     

    

     

 

2! 4! 3! 5!

1

3!

(j )

2!

( ) 1

2 4 3 5

2 3

θ θ θ

θ θ

jθ θ e jθ

jθ

j

z e θ sinθ

jθ  cos  j

u  jθ

e

i

Im( z )

Re( z )

1

1

- 1 - 1

-

e

- i

 

 

jθ -jθ

jθ - jθ

e e

j

θ

θ e e

 

 

2

1 sin

2

1 cos

_z z e θ sinθ_*

-jθ    cos  j

i  j   1

cos(θ) sin(θ)