1 / 44

Bruce Mayer, PE Registered Electrical & Mechanical Engineer BMayer@ChabotCollege.edu

Engr/Math/Physics 25. Chp3 MATLAB Functions: Part1. Bruce Mayer, PE Registered Electrical & Mechanical Engineer BMayer@ChabotCollege.edu. Learning Goals. Understand the difference between Built-In and User-Defined Functions Write User Defined Functions

sylvie
Download Presentation

Bruce Mayer, PE Registered Electrical & Mechanical Engineer BMayer@ChabotCollege.edu

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Engr/Math/Physics 25 Chp3 MATLABFunctions: Part1 Bruce Mayer, PE Registered Electrical & Mechanical EngineerBMayer@ChabotCollege.edu

  2. 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

  3. Functions • MATLAB Has Two Types of Functions • Built-In Functions Provided by the Softeware • e.g.; sqrt, exp, cos, sinh, etc. • User-Defined Functions are .m-files that can accept InPut Arguments and Return OutPut Values

  4. 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): Getting Help for Functions >> 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.

  5. Built-In Exponential Functions • Note the use of log for NATURAL Logarithms and log10 for “normal” Logarithms • This a historical Artifact from theFORTRAN Language – FORTRAN designers were concerned with confusing ln with “one-n”

  6. Built-In Complex-No. Functions • Useful for Analyzing Periodic Systems • e.g., Sinusoidal Steady-State Electrical Ckts

  7. Built-In Rounding Functions Graph

  8. Engr/MTH/Phys 25 Complex Numbers Bruce Mayer, PE Licensed Electrical & Mechanical EngineerBMayer@ChabotCollege.edu

  9. Complex Numbers – Math • What do We Do with? • Factoring • Let’s Make-Up or IMAGINE

  10. Discriminant D a x2+ bx +c = 0 ± b b2– 4ac x = 2a ± j |b2– 4ac| b x = 2a Complex No.s – Basic Concept • World of REAL numbers Solution(s) of a quadratic equation existonlyfornon-negativevalues of D! • World of COMPLEX numbers Solution(s) of a quadratic equation existalsofornegative values of D! In Engineering√(-1) = j in Math √(-1) = i

  11. Complex Number, z, Defined z = x + jy Imaginary part y = Im(z) Real part x = Re(z) Im(z) Real numbers Real numbers Im(z) = 0 Complex numbers Complex numbers Im(z)  0 Re(z)

  12. j2 = –1 j3 = –j j4 = +1 j –1 = –j z1 = x1 + j y1 z2 = x2 + j y2 z1 = z2,x1 = x2 ANDy1 = y2 z1 + z2,= (x1 + x2) +j ( y1 + y2) Complex No.s – Basic Rules • Powers of j j4n = +1; j4n+1 = +j ; j4n+2 = –1; j4n+3 = –j for n = 0, ±1, ±2, … • Equality • Addition

  13. z1 z2,= (x1 x2– y1 y2) +j (x1y2 + x2 y1) z2 = x2 + j y2 z1 = x1 + j y1 z = x + j y z* = x– j y (z + z*) = xRe(z) x1 x2+y1 y2 y1 x2–x1y2 z1 z1z2* 1 1 (z – z*) = j y j Im(z) + j = = z z* = x2 + y2 z2 2 2 z2 z2* (x22+y22) (x22+y22) Complex No.s – Basic Rules cont • Multiplication • The complex conjugate • Division

  14. Im(z) z = x + iy y r x2+ y2 r = mod z = |z| =  Re(z) arctan , if x > 0 x  = arg z = arctan + p, if x < 0 y y x x z = r (cos  + jsin ) x =rcos y=rsin Complex No.s – Graphically The Argand diagram Modulus (magnitude) of z Argument (angle) of z Polar form of a complex number z

  15. Im(z) z1 = r1(cos 1 + j sin 1) z2 = r2(cos 2 + j sin 2) z = x + jy y r z1 z2=r1r2(cos (1 + 2)+ j sin(1 + 2))  Re(z) x |z1z2| =|z1| |z2| ; arg(z1z2) = arg(z1) + arg(z2) =(cos (1–2)+ j sin(1–2)) |z1| z1 z1 r1 z1 = ; arg( ) = arg(z1) – arg(z2) |z2| z2 r2 z2 z2 Complex No.s – Polar Form • Multiplication • Division

  16. Consider: Polar Multiplication Proof • Then • But Then factoring out j, & Grouping • Recall Trig IDs

  17. Using Trig ID in the Loooong Expression Polar Multiplication Proof cont • So Finally Q.E.D.

  18. z1 z2=r1r2(cos (1 + 2)+ j sin(1 + 2)) z1 z2…zn=r1r2 …rn[cos (1 + 2+…+ n)+ j sin(1 + 2+…+ n)] zn=rn(cos (n)+ j sin(n)) z1 = z2=…= zn r = 1 De Moivre’s Formula (cos+ j sin )n=cos (n)+ j sin(n) • French Mathematician Abraham de Moivre (1667-1754)

  19. f(x) = g(x) + jh(x) f*(x) = g(x)–jh(x) f(x) f*(x) = g2(x)+h2(x) f(z) = z2 + 2z + 1; z = x + j y g(x,y) = (x2–y2 + 2x + 1) f(z) = g(x,y) + jh(x,y) h(x,y) = 2y (x + 1) Complex Functions • A complex function Real function Real function • A complex conjugate function • Example:

  20. Im(z) 1 ei  1 –1 –  Re(z) e–i –1 Euler’s Formula A power series for an exponential cos(θ) sin(θ) A complex conjugate is also inverse

  21. Complex Numbers – Engineering

  22. Consider a General Complex Number Im(z) z = x + jy y r  Re(z) x Complex Number Calcs • This Can Be thought of as a VECTOR in the Complex Plane • This Vector Can be Expressed in Polar (exponential) Form Thru the Euler Identity • Where • Then from the Vector Plot

  23. Consider Two Complex Numbers Complex Number Calcs cont • The PRODUCT n•m • The SUM, Σ, and DIFFERENCE, , for these numbers • Complex DIVISION is Painfully Tedious • See Next Slide

  24. For the Quotient n/m in Rectangular Form Complex Number Division • Use the Complex CONJUGATE to Clear the Complex Denominator • The Generally accepted Form of a Complex Quotient Does NOT contain Complex or Imaginary DENOMINATORS • The Exponential Form is Cleaner • See Next Slide

  25. For the Quotient n/m in Exponential Form Complex Number Division cont. Look for lotsof this inENGR43 • However Must Still Calculate the Magnitudes and Angles

  26. How to Find? Root of A Complex Number • Use Euler • Note that θ is in the 2nd Quadrant • Thus • In This Case

  27. Now use Properites of Exponents Root of A Complex Number • Use Euler in Reverse • In this Case • By MATLAB (-7+19j)^(1/3) ans = 2.1841 + 1.6305i

  28. What is ln of a NEGATIVE Number (1) Im(z) r z=(-19,0)  = π –r Re(z) • State −19 as a complex no. –r • Find Euler Reln Quantities r, & θ

  29. Note that θ is 180º, NOT Zero Thus the Polar form of −19 ln of a NEGATIVE Number (2) Im(z) r z=(-19,0)  = π –r Re(z) –r • Taking the ln

  30. Recall complex forms for −19 Log of a NEGATIVE Number Im(z) r z=(-19,0)  = π –r Re(z) –r • Taking the common (Base-10) log

  31. MATLAB 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 = -5.0000 + 4.0000i >> ac = a*c ac = -7.0000 -22.0000i

  32. Complex Ops >> b_d = b/d b_d = 5.0000 + 4.0000i >> c_b = c/b c_b = 0 + 1.0000i >> c_a = c/a c_a = -1.7692 - 0.1538i >> Re_d = real(d) Re_d = 0 >> Im_b = imag(b) Im_b = 5

  33. Complex Ops >> b_sq = b^2 b_sq = -9.0000 -40.0000i >> b_cu = b^3 b_cu = 2.3600e+002 +1.1500e+002i >> cos_a = cos(a) cos_a = -3.7245 - 0.5118i >> exp_c = exp(c) exp_c = -0.0044 + 0.0051i >> log_b = log10(b) log_b = 0.8064 + 0.9752i

  34. Complex Ops >> 180*angle(z)/pi ans = 32.7273 >> x = -23; y = 19; >> z2 = complex(x,y) z2 = -23.0000 +19.0000i >> r = 73; >> theta = 2*pi/11; >> theta_deg = 180*theta/pi theta_deg = 32.7273 >> z = r*exp(j*theta) z = 61.4115 +39.4668i >> abs(z) ans = 73

  35. MATLAB Accepts Caveat • But NOT >> z2 = 3+7j; >> z3 = 5 + i*11; >> z4 = 7 + 13*j; >> z2 z2 = 3.0000 + 7.0000i >> z3 z3 = 5.0000 +11.0000i >> z4 z4 = 7.0000 +13.0000i >> z5 = 7 + j5; ??? Undefined function or variable 'j5'.

  36. All Done for Today LeonhardEuler(1707-1783)

  37. Engr/Math/Physics 25 Appendix Time For Live Demo Bruce Mayer, PE Licensed Electrical & Mechanical EngineerBMayer@ChabotCollege.edu

  38. I = I = Re I = Re Complex Integration Example Us EULER to Faciltitate (Nasty) AntiDerivation

  39. Illuminate Previous Slide • By EULER • Using Term-by-Term Integration • As “i” is just a CONSTANT • Taking the REAL Part of the above

  40. Im(z) r z'(x',y') z = r (cos  + j sin ) = z(x,y) a  –r Re(z) –r x'= r cos( +a) =r(cos cosa– sin sina) The function ejacan 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') . y'= r sin( +a) = r(sin cosa+ cos sina) x'= xcosa– ysina y'= xsina+ ycosa Rotation Operator Polar form of a complex number

  41. z = z' = z' = z' The function ejoccurs in the natural sciences whenever periodic motion is described or when a system has periodic structure. Periodicity

  42. Im(z) z1 z0= ej0 ;z1= ej 2p/3; z2= ej 4p/3 z0 2 1 Re(z) zk= ej 2pk/3,where k = 0, ±1 zk= ej 2pk/3,where k = 0,1,2 z2 zk3= (ej 2pk/3)3 = ej 2pk= 1  1 = zk z0= ej0 = 1 z1= ej 2p/3= - + j z2= ej 4p/3= - – j 1 1 2 2 2 2 Periodicity on a Circle or nnth roots of 1 3 roots of third degree of 1

  43. Im(z) z1 z2 z0= ej0 = 1 z±1= e±j p/3 = ± j z±2= e ±j 2p/3 = - ± j z0 z3 Re(z) z-2 z-1 1 1 0, ±1, ±2, ... , ±(n –1)/2 if n is odd 2 2 zk= ej 2pk/nfor k = 2 2 0, ±1, ±2, ... , ±(n/2 –1), n/2 if n is even Such functions are important for the description of systems with circular periodicity. Periodicity on a Circle cont or nnth roots of 1 6 sixth roots of 1 Used for description of the properties of the benzene molecule. nnth roots of 1

  44. f(x) = f(x,y,z) = Such functions are important for the description of periodic systems such as crystals. Periodicity on a Line a a a a a ... Periodic function f(x) = f(x + a) Generalization for three-dimensional periodic systems

More Related