2Learning GoalsUnderstand the difference between Built-In and User-Defined FunctionsWrite User Defined FunctionsDescribe Global and Local VariablesWhen to use SUBfunctions as opposed to NESTED-FunctionsImport Data from an External Data-FileAs generated, for example, by an Electronic Data-Acquisition System
3Functions MATLAB Has Two Types of Functions Built-In Functions Provided by the Softewaree.g.; sqrt, exp, cos, sinh, etc.User-Defined Functions are .m-files that can accept InPut Arguments and Return OutPut Values
4Getting Help for Functions Use the lookfor command to find functions that are relevant to your applicationFor example typing lookfor complex returns a list of functions that operate on complex numbers (more to come):>> lookfor complexctranspose.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.
5Built-In Exponential Functions CommandConventional Math Functionexp(x)Exponential; exsqrt(x)Square root; xlog(x)Natural logarithm; lnxlog10(x)Common (base 10) logarithm; logx = log10xNote the use of log for NATURAL Logarithms and log10 for “normal” LogarithmsThis a historical Artifact from the FORTRAN Language – FORTRAN designers were concerned with confusing ln with “one-n”
6Built-In Complex-No. Functions CommandConventional Math Functionabs(x)Absolute value (Magnitude or Modulus)angle(x)Angle of a complex number (Argument)conj(x)Complex Conjugateimag(x)Imaginary part of a complex numberreal(x)Real part of a complex numberUseful for Analyzing Periodic Systemse.g., Sinusoidal Steady-State Electrical Ckts
7Built-In Rounding Functions CommandConventional Math Functionceil(x)Round to nearest integer toward +fix(x)Round to nearest integer toward zerofloor(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.Sort of like the FFT problem we did in labGraph
9Complex Numbers – Math What do We Do with? Factoring Let’s Make-Up or IMAGINE
10Complex No.s – Basic Concept Discriminant DWorld of REAL numbersx =2ab2– 4acba x2 + b x + c = 0Solution(s) of a quadratic equation exist only for non-negative values of D !World of COMPLEX numbersSolution(s) of a quadratic equation exist also for negative values of D !x =± j2a|b2– 4ac|bIn Engineering √(-1) = j in Math √(-1) = i
11Complex Number, z, Defined z = x + j yImaginary party = Im(z)Real partx = Re(z)Im(z)RealnumbersRealnumbersIm(z) = 0Complex numbersComplexnumbersIm(z) 0REAL no.s described by a (number) LINE. Complex no.s described by a PLANERe(z)
13Complex No.s – Basic Rules cont z1 = x1 + j y1z2 = x2 + j y2Multiplicationz1 z2, = (x1 x2 – y1 y2) + j (x1 y2 + x2 y1)The complex conjugatez = x + j yz* = x – j y(z + z*) = x Re(z)21(z – z*) = j y j Im(z)21z z* = x2 + y2Multiply by F.O.I.L. * For division multiply by 1, where on is the conjugate of the DIVISOR divided by itselfz2z1=(x22 + y22)z2 z2*z1z2*x1 x2 + y1 y2+ jy1 x2 – x1 y2Division
14Complex No.s – Graphically The Argand diagramModulus (magnitude) of zr = mod z = |z| =x2 + y2xyrz = x + i yIm(z)Re(z)Argument (angle) of zarctan = arg z =xy+ p, if x < 0, if x > 0x = r cos Polar form of a complex number zz = r (cos + j sin )y = r sin
17Polar Multiplication Proof cont Using Trig ID in the Loooong ExpressionSo FinallyQ.E.D.
18De Moivre’s Formula z1 z2 = r1r2 (cos (1 + 2) + j sin(1 + 2)) z1 z2…zn = r1r2 …rn [cos (1 + 2 + …+ n) + j sin(1 + 2 + …+ n)]z1 = z2=…= znzn = rn (cos (n) + j sin(n))Named after French Mathematician Abraham de Moivre ( )r = 1(cos + j sin )n = cos (n) + j sin(n)French Mathematician Abraham de Moivre ( )
19Complex Functions A complex function A complex conjugate function Real functionf(x) = g(x) + j h(x)Real functionA complex conjugate functionf*(x) = g(x) – j h(x)f(x) f*(x) = g2(x) + h2(x)f(z) = z2 + 2z + 1; z = x + j yExample:g(x,y) = (x2 – y2 + 2x + 1)h(x,y) = 2y (x + 1)f(z) = g(x,y) + j h(x,y)
20Verify by MuPadFrom the last Line (collect comand) collect real and imaginary parts
21Euler’s Formula ei e–i cos(θ) sin(θ) Im(z) Re(z) 1 –1 – A power series for an exponentialcos(θ)sin(θ)e^j(-x) = cos(-x) + jsin(-x) => use trig IDs: cos(-y) = cosy & sin(-y) = -sinyA complex conjugate is also inverse
23Complex Number Calcs Im(z) Consider a General Complex Number yrz = x + j yIm(z)Re(z)Consider a General Complex NumberThis Can Be thought of as a VECTOR in the Complex PlaneThis Vector Can be Expressed in Polar (exponential) Form Thru the Euler IdentityWhereThen from the Vector PlotNeed to be careful abaout the values of θ when z is in the LEFT-half of the Argand Plane => must Add 180 degrees
24Complex Number Calcs cont Consider Two Complex NumbersThe PRODUCT n•mThe SUM, Σ, and DIFFERENCE, , for these numbersComplex DIVISION is Painfully TediousSee Next Slide
25Complex Number Division For the Quotient n/m in Rectangular FormUse the Complex CONJUGATE to Clear the Complex DenominatorThe Generally accepted Form of a Complex Quotient Does NOT contain Complex or Imaginary DENOMINATORSThe Exponential Form is CleanerSee Next Slide
26Complex Number Division cont. For the Quotient n/m in Exponential FormLook for lots of this in ENGR43However Must Still Calculate the Magnitudes and Angles
27Root of a Complex Number How to Find?Use EulerNote that θ is in the 2nd QuadrantThusIn This Case
28Root of A Complex Number Now use Properites of ExponentsUse Euler in ReverseIn this CaseBy MATLAB(-7+19j)^(1/3)ans =i
29ln of a NEGATIVE Number (1) Im(z)What isrz=(-19,0) = π–rRe(z)State −19 as a complex no.–rFind Euler Reln Quantities r, & θ
30ln of a NEGATIVE Number (2) Im(z)Note that θ is 180º, NOT ZeroThus the Polar form of −19rz=(-19,0) = π–rRe(z)–rTaking the ln
31Log of a NEGATIVE Number Im(z)Recall complex forms for −19rz=(-19,0) = π–rRe(z)–rTaking the common (Base-10) log
32sin or cos of Complex number Recall from Euler DevelopmentBy Sum & Difference Formulas
33sin or cos of Complex number ThusFrom Previous SlideSo Finally
34MATLAB Complex Operations >> a = 3+2j;>> b = -4+5i;>> c = -5-j*4;>> d = i;>> Mag_b = abs(b)Mag_b =6.4031>> c_star = conj(c)c_star =i>> ac = a*cac =i
37Complex Ops >> 180*angle(z)/pi >> r = 73; ans = >> x = -23; y = 19;>> z2 = complex(x,y)z2 =i>> r = 73;>> theta = 2*pi/11;>> theta_deg = 180*theta/pitheta_deg =>> z = r*exp(j*theta)z =i>> abs(z)ans =73
38Caveat MATLAB Accepts But NOT >> z2 = 3+7j; >> z3 = 5 + i*11;>> z4 = *j;>> z2z2 =i>> z3z3 =i>> z4z4 =i>> z5 = 7 + j5;??? Undefined function or variable 'j5'.
39Leonhard Euler (1707-1783) All Done for Today ".. indeed, far and away the most prolific writer in the history of the subject" writes Howard Eves in An Introduction to the History of Mathematics. Euler's contribution to mathematics is represented here by a few of the notations conventionalized by him or in his honor. Around the world, these are read, written, and spoken thousands of times every day:e for the base of the natural logarithm (a.k.a. "the calculus number") a, b, c for the sidelengths of a triangle ABC f(x) for functional value R and r for the circumradius and inradius of a triangle sin x and cos x for values of the sine and cosine functions i for the imaginary unit, the "square root of -1" capital sigma for summation. capital delta for finite difference.Euler grew up near Basel, Switzerland, and studied at an early age under Johann Bernoulli. He finished studies at the University of Basel when only 15 years old. From 1727 to 1741, Euler worked in St. Perersburg, Russia, and then moved to the Akademie in Berlin. In 1766 he returned to St. Petersburg, where he remained.
42Complex Integration Example Us EULER to Faciltitate (Nasty) AntiDerivationI =I = ReI = Re
43Illuminate Previous Slide By EULERUsing Term-by-Term IntegrationAs “i” is just a CONSTANTTaking the REAL Part of the above
44Rotation Operator Im(z) r z'(x',y') z = r (cos + j sin ) = z(x,y) a Re(z)r–raz'(x',y')Polar form of a complex numberz = r (cos + j sin ) =x'= r cos( + a) = r(cos cosa – sin sina)y'= r sin( + a) = r(sin cosa + cos sina)x'= x cosa – y sinay'= x sina + y cosaThe function eja can be regarded as a representation of the rotation operator R(x,y) which transforms the coordinates (x,y) of a point z into coordinates (x',y') of the rotated point z' : R(x,y) = (x',y') .
45Periodicityz =z' =z' =z'The function ej occurs in the natural sciences whenever periodic motion is described or when a system has periodic structure.
46Periodicity on a Circle or n nth roots of 1z0Im(z)Re(z)1z1z22z0 = ej0 ; z1 = ej 2p/3 ; z2 = ej 4p/3zk = ej 2pk/3, where k = 0,1,2zk3 = (ej 2pk/3)3 = ej 2pk = 1 = zkz0 = ej0 = 1z1 = ej 2p/3 = jz2 = ej 4p/3 = – j213 roots of third degree of 1zk = ej 2pk/3, where k = 0, ±1
47Periodicity on a Circle cont or n nth roots of 1z0Im(z)Re(z)z1z2z3z-2z-16 sixth roots of 1Used for description of the properties of the benzene molecule.z0 = ej0 = 1z±1 = e±j p/3 = ± jz±2 = e ±j 2p/3 = ± j21n nth roots of 1zk = ej 2pk/n for k =0, ±1, ±2, ... , ±(n –1)/ if n is odd0, ±1, ±2, ... , ±(n/2 –1), n/2 if n is evenSuch functions are important for the description of systems with circular periodicity.
48Periodicity on a Line f(x) = f(x + a) f(x) = f(x,y,z) = a a a a a ... Periodic functionf(x) =f(x) = f(x + a)Generalization for three-dimensional periodic systemsf(x,y,z) =Such functions are important for the description of periodic systems such as crystals.