SlideShare a Scribd company logo
ECE 1010 ECE Problem Solving I




MATLAB                                                      3
Functions
Overview
In this chapter we start studying the many, many, mathematical
functions that are included in MATLAB. Some time will be spent
introducing complex variables and how MATLAB handles them.
Later we will learn how to write custom (user written) functions
which are a special form of m-file. Two dimensional plotting
functions will be introduced. We will also explore programming
constructs for flow control (if-else-elseif code blocks)
and looping (for loop etc.). Next data analysis functions will be
investigated, which includes sample statistics and histogram plot-
ting functions.




Chapter 3: Overview                                            3–1
ECE 1010 ECE Problem Solving I


Mathematical Functions
Common Math Functions
                        Table 3.1: Common math functions

    Function             Description      Function         Description
  abs(x)             x                  sqrt(x)            x
  round(x) nearest integer              fix(x)         nearest integer
  floor(x) nearest integer              ceil(x)        nearest integer
           toward – ∞                                  toward ∞
  sign(x)                               rem(x,y) the remainder
                     – 1, x < 0
                                                of x ⁄ y
                     0, x = 0
                    
                     1, x > 0
  exp(x)                x               log(x)         natural log ln x
                    e

  log10(x) log base 10
           log 10 x

Examples:
            » x = [-5.5 5.5];
            » round(x)
            ans =     -6    6
            » fix(x)
            ans =     -5    5
            » floor(x)
            ans =     -6    5
            » ceil(x)

Chapter 3: Mathematical Functions                                        3–2
ECE 1010 ECE Problem Solving I


            ans =     -5            6
            » sign(x)
            ans =     -1            1
            » rem(23,6)
            ans =      5

Trigonometric and Hyperbolic Functions
 • Unlike pocket calculators, the trigonometric functions always
   assume the input argument is in radians
 • The inverse trigonometric functions produce outputs that are
   in radians
                      Table 3.2: Trigonometric functions

    Function           Description          Function         Description
  sin(x)            sin ( x )           cos(x)             cos ( x )
  tan(x)            tan ( x )           asin(x)               –1
                                                           sin ( x )
  acos(x)               –1              atan(x)                –1
                    cos ( x )                              tan ( x )
  atan2(y,          the inverse tan-
  x)                gent of y ⁄ x
                    including the
                    correct quad-
                    rant

Examples:
                                        2           2
 • A simple verification that sin ( x ) + cos ( x ) = 1



Chapter 3: Mathematical Functions                                          3–3
ECE 1010 ECE Problem Solving I


      » x = 0:pi/10:pi;
      » [x' sin(x)' cos(x)' (sin(x).^2+cos(x).^2)']
      ans =
               0         0    1.0000    1.0000
          0.3142    0.3090    0.9511    1.0000
          0.6283    0.5878    0.8090    1.0000
          0.9425    0.8090    0.5878    1.0000
          1.2566    0.9511    0.3090    1.0000
          1.5708    1.0000    0.0000    1.0000
          1.8850    0.9511   -0.3090    1.0000
          2.1991    0.8090   -0.5878    1.0000
          2.5133    0.5878   -0.8090    1.0000
          2.8274    0.3090   -0.9511    1.0000
          3.1416    0.0000   -1.0000    1.0000
 • Parametric plotting:
    – Verify that by plotting sin θ versus cos θ for 0 ≤ θ ≤ 2π we
      obtain a circle
» theta = 0:2*pi/100:2*pi;  % Span 0 to 2pi with 100 pts
» plot(cos(theta),sin(theta)); axis('square')
» title('Parametric Plotting','fontsize',18)
» ylabel('y - axis','fontsize',14)
» xlabel('x - axis','fontsize',14)
» figure(2)
» hold
Current plot held
» plot(cos(5*theta).*cos(theta), ...
    cos(5*theta).*sin(theta)); % A five-leaved rose




Chapter 3: Mathematical Functions                              3–4
ECE 1010 ECE Problem Solving I



                                       Parametric Plotting
                1
                                                                         Circle
              0.8


              0.6


              0.4                                                 Rose
              0.2
   y - axis




                0


              -0.2


              -0.4


              -0.6


              -0.8


               -1
                -1   -0.8   -0.6   -0.4   -0.2      0       0.2    0.4   0.6    0.8   1
                                                 x - axis
 • The trig functions are what you would expect, except the fea-
   tures of atan2(y,x) may be unfamiliar
                y                              y
                                   4
                                     2 x                                 2                x
                            φ 1 = 0.4636
                                                                     4
                                                                               φ 2 = – 2.0344



Chapter 3: Mathematical Functions                                                             3–5
ECE 1010 ECE Problem Solving I


      » [atan(2/4) atan2(2,4)]
          ans =    0.4636    0.4636 % the same
      » [atan(-4/-2) atan2(-4,-2)]
          ans =    1.1071   -2.0344 % different; why?
                                                x
 • The hyperbolic functions are defined in terms of e
                            Table 3.3: Hyperbolic functions

    Function            Description            Function          Description
  sinh(x)              x         –x           cosh(x)           x         –x
                     e –e                                     e –e
                     -----------------
                                     -                        -----------------
                                                                              -
                             2                                        2
  tanh(x)               x         –x          asinh(x)                            2
                     e –e
                     ------------------                        ln ( x + x + 1 )
                        x          –x
                     e +e
  acosh(x)                                2   atanh(x)           1+x
                     ln ( x + x – 1 )                         ln -----------, x ≤ 1
                                                                           -
                                                                 1–x

 • There are no special concerns in the use of these functions
   except that atanh requires an argument that must not
   exceed an absolute value of one

Complex Number Functions
 • Before discussing these functions we first review a few facts
   about complex variable theory
 • In electrical engineering complex numbers appear frequently
 • A complex number is an ordered pair of real numbers1

   1. Tom M. Apostle, Mathematical Analysis, second edition, Addison Wesley,
      p. 15, 1974.

Chapter 3: Mathematical Functions                                                     3–6
ECE 1010 ECE Problem Solving I


    denoted ( a, b )
    – The first number, a, is called the real part, while the second
      number, b, is called the imaginary part
    – For algebraic manipulation purposes we write ( a, b )
        = a + ib = a + jb where i = j = – 1 ; electrical
      engineers typically use j since i is often used to denote cur-
      rent
    Note:        –1 × –1 = –1 ⇒ j × j = –1
 • For complex numbers z 1 = a 1 + jb 1 and z 2 = a 2 + jb 2
   we define/calculate
                  z1 + z2 = ( a1 + a2 ) + j ( b1 + b2 )                              (sum)
             z 1 – z 2 = ( a 1 – a 2 ) + j ( b 1 – b 2 ) (difference)
         z 1 z 2 = ( a 1 a 2 – b 1 b 2 ) + j ( a 1 b 2 + b 1 a 2 ) (product)
          z1     ( a1 a2 + b1 b2 ) – j ( a1 b2 – b1 a2 )
          ---- = --------------------------------------------------------------------------- (quotient)
                                                                                           -
          z2                                     2            2
                                              a +b
                                              2         2

                                               2        2
                             z1 =           a 1 + b 1 (magnitude)
                                                  –1
                           ∠z 1 = tan ( b 1 ⁄ a 1 ) (angle)

                     z 1∗ = a 1 – jb 1 (complex conjugate)
 • MATLAB is consistent with all of the above, starting with the
   fact that i and j are predefined to be – 1



Chapter 3: Mathematical Functions                                                                         3–7
ECE 1010 ECE Problem Solving I


 • The rectangular form of a complex number is as defined
   above,
                             z = ( a, b ) = a + jb
 • The corresponding polar form is
                                        z = r ∠θ
                         2     2                   –1
    where r =          a + b and θ = tan ( b ⁄ a )
                        Imaginary Axis
  Complex Plane                     b
                                             r
                                                   θ       Real
                                                       a   Axis



 • MATLAB has five basic complex functions, but in reality
   most all of MATLAB’s functions accept complex arguments
   and deal with them correctly
                      Table 3.4: Basic complex functions

       Function                              Description
    conj(x)            Computes the conjugate of z = a + jb
                       which is z∗ = a – jb
    real(x)            Extracts the real part of z = a + jb
                       which is real ( z ) = a
    imag(x)            Extracts the imaginary part of
                        z = a + jb which is imag ( z ) = b

Chapter 3: Mathematical Functions                                 3–8
ECE 1010 ECE Problem Solving I


                      Table 3.4: Basic complex functions

       Function                                 Description
    angle(x)           computes the angle of z = a + jb using
                       atan2 which is
                       atan2(imag(z),real(z))
Euler’s Formula: A special mathematical result of, special
importance to electrical engineers, is the fact that
                             jb
                         e        = cos b + j sin b             (3.1)
 • Turning (3.1) around yields
                                          jθ       – jθ
                                   e –e
                           sin θ = ---------------------
                                                       -        (3.2)
                                            2j
                                          jθ        – jθ
                                  e +e
                          cos θ = ---------------------
                                                      -         (3.3)
                                            2
 • It also follows that
                                                      jθ
                          z = a + jb = re                       (3.4)
    where
                  2   2         –1 b
         r=      a + b , θ = tan --, a = r cos θ, b = r sin θ
                                   -
                                   a




Chapter 3: Mathematical Functions                                 3–9
ECE 1010 ECE Problem Solving I


 • Some examples:
      » z1 = 2+j*4; z2 = -5+j*7;
      » [z1 z2]
      ans =
         2.0000 + 4.0000i -5.0000 + 7.0000i
      » [real(z1) imag(z1) abs(z1) angle(z1)]
      ans =
         2.0000    4.0000    4.4721    1.1071
      » [conj(z1) conj(z2)]
      ans =
         2.0000 - 4.0000i -5.0000 - 7.0000i
      » [z1+z2 z1-z2 z1*z2 z1/z2]
      ans =
        -3.0000 +11.0000i   7.0000 - 3.0000i
       -38.0000 - 6.0000i   0.2432 - 0.4595i

Polar Plots: When dealing with complex numbers we often deal
with the polar form. The plot command which directly plots vec-
tors of magnitude and angle is polar(theta,r)
 • This function is also useful for general plotting
 • As an example the equation of a cardioid in polar form, with
   parameter a, is
                       r = a ( 1 + cos θ ), 0 ≤ θ ≤ 2π
» theta = 0:2*pi/100:2*pi;             % Span 0 to 2pi with 100 pts
» r = 1+cos(theta);
» polar(theta,r)




Chapter 3: Mathematical Functions                              3–10
ECE 1010 ECE Problem Solving I



                                    90
    Polar Plot                                  2
                       120                           60

                                               1.5



            150                            1               30



                                          0.5




      180                                                        0




            210                                            330




                       240                           300

                                    270




Chapter 3: Mathematical Functions                                    3–11

More Related Content

What's hot

Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabkrishna_093
 
Lesson 21: Curve Sketching (slides)
Lesson 21: Curve Sketching (slides)Lesson 21: Curve Sketching (slides)
Lesson 21: Curve Sketching (slides)
Matthew Leingang
 
01 derivadas
01   derivadas01   derivadas
01 derivadasklorofila
 
Identidades
IdentidadesIdentidades
Identidades
mchamorro2
 
Actividad 4 calculo diferencial
Actividad 4 calculo diferencialActividad 4 calculo diferencial
Actividad 4 calculo diferencialSIGIFREDO12222
 
Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)asghar123456
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
aabdel96
 
Fuzzy calculation
Fuzzy calculationFuzzy calculation
Fuzzy calculation
Amir Rafati
 
Numerical Methods 3
Numerical Methods 3Numerical Methods 3
Numerical Methods 3
Dr. Nirav Vyas
 
Partial Differential Equation - Notes
Partial Differential Equation - NotesPartial Differential Equation - Notes
Partial Differential Equation - Notes
Dr. Nirav Vyas
 
Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)asghar123456
 
11 X1 T02 07 sketching graphs (2010)
11 X1 T02 07 sketching graphs (2010)11 X1 T02 07 sketching graphs (2010)
11 X1 T02 07 sketching graphs (2010)Nigel Simmons
 

What's hot (16)

Chapter 3 (maths 3)
Chapter 3 (maths 3)Chapter 3 (maths 3)
Chapter 3 (maths 3)
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Lesson 21: Curve Sketching (slides)
Lesson 21: Curve Sketching (slides)Lesson 21: Curve Sketching (slides)
Lesson 21: Curve Sketching (slides)
 
01 derivadas
01   derivadas01   derivadas
01 derivadas
 
Identidades
IdentidadesIdentidades
Identidades
 
Actividad 4 calculo diferencial
Actividad 4 calculo diferencialActividad 4 calculo diferencial
Actividad 4 calculo diferencial
 
Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Fuzzy calculation
Fuzzy calculationFuzzy calculation
Fuzzy calculation
 
mathematics formulas
mathematics formulasmathematics formulas
mathematics formulas
 
Numerical Methods 3
Numerical Methods 3Numerical Methods 3
Numerical Methods 3
 
Chapter 4 (maths 3)
Chapter 4 (maths 3)Chapter 4 (maths 3)
Chapter 4 (maths 3)
 
Partial Differential Equation - Notes
Partial Differential Equation - NotesPartial Differential Equation - Notes
Partial Differential Equation - Notes
 
Hw2 s
Hw2 sHw2 s
Hw2 s
 
Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)Amth250 octave matlab some solutions (2)
Amth250 octave matlab some solutions (2)
 
11 X1 T02 07 sketching graphs (2010)
11 X1 T02 07 sketching graphs (2010)11 X1 T02 07 sketching graphs (2010)
11 X1 T02 07 sketching graphs (2010)
 

Similar to 1010n3a

Seismic data processing lecture 3
Seismic data processing lecture 3Seismic data processing lecture 3
Seismic data processing lecture 3
Amin khalil
 
Jacob's and Vlad's D.E.V. Project - 2012
Jacob's and Vlad's D.E.V. Project - 2012Jacob's and Vlad's D.E.V. Project - 2012
Jacob's and Vlad's D.E.V. Project - 2012
Jacob_Evenson
 
Module II Partition and Generating Function (2).ppt
Module II Partition and Generating Function (2).pptModule II Partition and Generating Function (2).ppt
Module II Partition and Generating Function (2).ppt
ssuser26e219
 
ISI MSQE Entrance Question Paper (2008)
ISI MSQE Entrance Question Paper (2008)ISI MSQE Entrance Question Paper (2008)
ISI MSQE Entrance Question Paper (2008)
CrackDSE
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavVyacheslav Arbuzov
 
Chapter 1 (math 1)
Chapter 1 (math 1)Chapter 1 (math 1)
Chapter 1 (math 1)
Amr Mohamed
 
1531 fourier series- integrals and trans
1531 fourier series- integrals and trans1531 fourier series- integrals and trans
1531 fourier series- integrals and trans
Dr Fereidoun Dejahang
 
7.curves Further Mathematics Zimbabwe Zimsec Cambridge
7.curves   Further Mathematics Zimbabwe Zimsec Cambridge7.curves   Further Mathematics Zimbabwe Zimsec Cambridge
7.curves Further Mathematics Zimbabwe Zimsec Cambridge
alproelearning
 
Interpolation functions
Interpolation functionsInterpolation functions
Interpolation functions
Tarun Gehlot
 
Statistical Physics Assignment Help
Statistical Physics Assignment HelpStatistical Physics Assignment Help
Statistical Physics Assignment Help
Statistics Assignment Help
 
Rational Functions
Rational FunctionsRational Functions
Rational Functions
Jazz0614
 
Unit 4 Review
Unit 4 ReviewUnit 4 Review
Unit 4 Review
rfrettig
 
03 truncation errors
03 truncation errors03 truncation errors
03 truncation errorsmaheej
 
NIPS2010: optimization algorithms in machine learning
NIPS2010: optimization algorithms in machine learningNIPS2010: optimization algorithms in machine learning
NIPS2010: optimization algorithms in machine learningzukun
 
chapter3.ppt
chapter3.pptchapter3.ppt
chapter3.ppt
JudieLeeTandog1
 

Similar to 1010n3a (20)

Seismic data processing lecture 3
Seismic data processing lecture 3Seismic data processing lecture 3
Seismic data processing lecture 3
 
Jacob's and Vlad's D.E.V. Project - 2012
Jacob's and Vlad's D.E.V. Project - 2012Jacob's and Vlad's D.E.V. Project - 2012
Jacob's and Vlad's D.E.V. Project - 2012
 
Taylor problem
Taylor problemTaylor problem
Taylor problem
 
Quadratic
QuadraticQuadratic
Quadratic
 
Module II Partition and Generating Function (2).ppt
Module II Partition and Generating Function (2).pptModule II Partition and Generating Function (2).ppt
Module II Partition and Generating Function (2).ppt
 
ISI MSQE Entrance Question Paper (2008)
ISI MSQE Entrance Question Paper (2008)ISI MSQE Entrance Question Paper (2008)
ISI MSQE Entrance Question Paper (2008)
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
 
Chapter 1 (math 1)
Chapter 1 (math 1)Chapter 1 (math 1)
Chapter 1 (math 1)
 
1531 fourier series- integrals and trans
1531 fourier series- integrals and trans1531 fourier series- integrals and trans
1531 fourier series- integrals and trans
 
7.curves Further Mathematics Zimbabwe Zimsec Cambridge
7.curves   Further Mathematics Zimbabwe Zimsec Cambridge7.curves   Further Mathematics Zimbabwe Zimsec Cambridge
7.curves Further Mathematics Zimbabwe Zimsec Cambridge
 
Interpolation functions
Interpolation functionsInterpolation functions
Interpolation functions
 
Lec3
Lec3Lec3
Lec3
 
Statistical Physics Assignment Help
Statistical Physics Assignment HelpStatistical Physics Assignment Help
Statistical Physics Assignment Help
 
Assignment6
Assignment6Assignment6
Assignment6
 
Rational Functions
Rational FunctionsRational Functions
Rational Functions
 
Unit 4 Review
Unit 4 ReviewUnit 4 Review
Unit 4 Review
 
0708 ch 7 day 8
0708 ch 7 day 80708 ch 7 day 8
0708 ch 7 day 8
 
03 truncation errors
03 truncation errors03 truncation errors
03 truncation errors
 
NIPS2010: optimization algorithms in machine learning
NIPS2010: optimization algorithms in machine learningNIPS2010: optimization algorithms in machine learning
NIPS2010: optimization algorithms in machine learning
 
chapter3.ppt
chapter3.pptchapter3.ppt
chapter3.ppt
 

More from Faiza Saher

Lecture 1 wireless
Lecture 1 wirelessLecture 1 wireless
Lecture 1 wirelessFaiza Saher
 
Modern digital and analog communications systems by b p-lathi-solutions-manual
Modern digital and analog communications systems by b p-lathi-solutions-manualModern digital and analog communications systems by b p-lathi-solutions-manual
Modern digital and analog communications systems by b p-lathi-solutions-manualFaiza Saher
 
Fourier series 1
Fourier series 1Fourier series 1
Fourier series 1
Faiza Saher
 
Fourier series
Fourier seriesFourier series
Fourier series
Faiza Saher
 

More from Faiza Saher (7)

Lecture 05
Lecture 05Lecture 05
Lecture 05
 
Chapter3
Chapter3Chapter3
Chapter3
 
Ch04
Ch04Ch04
Ch04
 
Lecture 1 wireless
Lecture 1 wirelessLecture 1 wireless
Lecture 1 wireless
 
Modern digital and analog communications systems by b p-lathi-solutions-manual
Modern digital and analog communications systems by b p-lathi-solutions-manualModern digital and analog communications systems by b p-lathi-solutions-manual
Modern digital and analog communications systems by b p-lathi-solutions-manual
 
Fourier series 1
Fourier series 1Fourier series 1
Fourier series 1
 
Fourier series
Fourier seriesFourier series
Fourier series
 

Recently uploaded

STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 

Recently uploaded (20)

STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 

1010n3a

  • 1. ECE 1010 ECE Problem Solving I MATLAB 3 Functions Overview In this chapter we start studying the many, many, mathematical functions that are included in MATLAB. Some time will be spent introducing complex variables and how MATLAB handles them. Later we will learn how to write custom (user written) functions which are a special form of m-file. Two dimensional plotting functions will be introduced. We will also explore programming constructs for flow control (if-else-elseif code blocks) and looping (for loop etc.). Next data analysis functions will be investigated, which includes sample statistics and histogram plot- ting functions. Chapter 3: Overview 3–1
  • 2. ECE 1010 ECE Problem Solving I Mathematical Functions Common Math Functions Table 3.1: Common math functions Function Description Function Description abs(x) x sqrt(x) x round(x) nearest integer fix(x) nearest integer floor(x) nearest integer ceil(x) nearest integer toward – ∞ toward ∞ sign(x) rem(x,y) the remainder  – 1, x < 0  of x ⁄ y  0, x = 0   1, x > 0 exp(x) x log(x) natural log ln x e log10(x) log base 10 log 10 x Examples: » x = [-5.5 5.5]; » round(x) ans = -6 6 » fix(x) ans = -5 5 » floor(x) ans = -6 5 » ceil(x) Chapter 3: Mathematical Functions 3–2
  • 3. ECE 1010 ECE Problem Solving I ans = -5 6 » sign(x) ans = -1 1 » rem(23,6) ans = 5 Trigonometric and Hyperbolic Functions • Unlike pocket calculators, the trigonometric functions always assume the input argument is in radians • The inverse trigonometric functions produce outputs that are in radians Table 3.2: Trigonometric functions Function Description Function Description sin(x) sin ( x ) cos(x) cos ( x ) tan(x) tan ( x ) asin(x) –1 sin ( x ) acos(x) –1 atan(x) –1 cos ( x ) tan ( x ) atan2(y, the inverse tan- x) gent of y ⁄ x including the correct quad- rant Examples: 2 2 • A simple verification that sin ( x ) + cos ( x ) = 1 Chapter 3: Mathematical Functions 3–3
  • 4. ECE 1010 ECE Problem Solving I » x = 0:pi/10:pi; » [x' sin(x)' cos(x)' (sin(x).^2+cos(x).^2)'] ans = 0 0 1.0000 1.0000 0.3142 0.3090 0.9511 1.0000 0.6283 0.5878 0.8090 1.0000 0.9425 0.8090 0.5878 1.0000 1.2566 0.9511 0.3090 1.0000 1.5708 1.0000 0.0000 1.0000 1.8850 0.9511 -0.3090 1.0000 2.1991 0.8090 -0.5878 1.0000 2.5133 0.5878 -0.8090 1.0000 2.8274 0.3090 -0.9511 1.0000 3.1416 0.0000 -1.0000 1.0000 • Parametric plotting: – Verify that by plotting sin θ versus cos θ for 0 ≤ θ ≤ 2π we obtain a circle » theta = 0:2*pi/100:2*pi; % Span 0 to 2pi with 100 pts » plot(cos(theta),sin(theta)); axis('square') » title('Parametric Plotting','fontsize',18) » ylabel('y - axis','fontsize',14) » xlabel('x - axis','fontsize',14) » figure(2) » hold Current plot held » plot(cos(5*theta).*cos(theta), ... cos(5*theta).*sin(theta)); % A five-leaved rose Chapter 3: Mathematical Functions 3–4
  • 5. ECE 1010 ECE Problem Solving I Parametric Plotting 1 Circle 0.8 0.6 0.4 Rose 0.2 y - axis 0 -0.2 -0.4 -0.6 -0.8 -1 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 x - axis • The trig functions are what you would expect, except the fea- tures of atan2(y,x) may be unfamiliar y y 4 2 x 2 x φ 1 = 0.4636 4 φ 2 = – 2.0344 Chapter 3: Mathematical Functions 3–5
  • 6. ECE 1010 ECE Problem Solving I » [atan(2/4) atan2(2,4)] ans = 0.4636 0.4636 % the same » [atan(-4/-2) atan2(-4,-2)] ans = 1.1071 -2.0344 % different; why? x • The hyperbolic functions are defined in terms of e Table 3.3: Hyperbolic functions Function Description Function Description sinh(x) x –x cosh(x) x –x e –e e –e ----------------- - ----------------- - 2 2 tanh(x) x –x asinh(x) 2 e –e ------------------ ln ( x + x + 1 ) x –x e +e acosh(x) 2 atanh(x) 1+x ln ( x + x – 1 ) ln -----------, x ≤ 1 - 1–x • There are no special concerns in the use of these functions except that atanh requires an argument that must not exceed an absolute value of one Complex Number Functions • Before discussing these functions we first review a few facts about complex variable theory • In electrical engineering complex numbers appear frequently • A complex number is an ordered pair of real numbers1 1. Tom M. Apostle, Mathematical Analysis, second edition, Addison Wesley, p. 15, 1974. Chapter 3: Mathematical Functions 3–6
  • 7. ECE 1010 ECE Problem Solving I denoted ( a, b ) – The first number, a, is called the real part, while the second number, b, is called the imaginary part – For algebraic manipulation purposes we write ( a, b ) = a + ib = a + jb where i = j = – 1 ; electrical engineers typically use j since i is often used to denote cur- rent Note: –1 × –1 = –1 ⇒ j × j = –1 • For complex numbers z 1 = a 1 + jb 1 and z 2 = a 2 + jb 2 we define/calculate z1 + z2 = ( a1 + a2 ) + j ( b1 + b2 ) (sum) z 1 – z 2 = ( a 1 – a 2 ) + j ( b 1 – b 2 ) (difference) z 1 z 2 = ( a 1 a 2 – b 1 b 2 ) + j ( a 1 b 2 + b 1 a 2 ) (product) z1 ( a1 a2 + b1 b2 ) – j ( a1 b2 – b1 a2 ) ---- = --------------------------------------------------------------------------- (quotient) - z2 2 2 a +b 2 2 2 2 z1 = a 1 + b 1 (magnitude) –1 ∠z 1 = tan ( b 1 ⁄ a 1 ) (angle) z 1∗ = a 1 – jb 1 (complex conjugate) • MATLAB is consistent with all of the above, starting with the fact that i and j are predefined to be – 1 Chapter 3: Mathematical Functions 3–7
  • 8. ECE 1010 ECE Problem Solving I • The rectangular form of a complex number is as defined above, z = ( a, b ) = a + jb • The corresponding polar form is z = r ∠θ 2 2 –1 where r = a + b and θ = tan ( b ⁄ a ) Imaginary Axis Complex Plane b r θ Real a Axis • MATLAB has five basic complex functions, but in reality most all of MATLAB’s functions accept complex arguments and deal with them correctly Table 3.4: Basic complex functions Function Description conj(x) Computes the conjugate of z = a + jb which is z∗ = a – jb real(x) Extracts the real part of z = a + jb which is real ( z ) = a imag(x) Extracts the imaginary part of z = a + jb which is imag ( z ) = b Chapter 3: Mathematical Functions 3–8
  • 9. ECE 1010 ECE Problem Solving I Table 3.4: Basic complex functions Function Description angle(x) computes the angle of z = a + jb using atan2 which is atan2(imag(z),real(z)) Euler’s Formula: A special mathematical result of, special importance to electrical engineers, is the fact that jb e = cos b + j sin b (3.1) • Turning (3.1) around yields jθ – jθ e –e sin θ = --------------------- - (3.2) 2j jθ – jθ e +e cos θ = --------------------- - (3.3) 2 • It also follows that jθ z = a + jb = re (3.4) where 2 2 –1 b r= a + b , θ = tan --, a = r cos θ, b = r sin θ - a Chapter 3: Mathematical Functions 3–9
  • 10. ECE 1010 ECE Problem Solving I • Some examples: » z1 = 2+j*4; z2 = -5+j*7; » [z1 z2] ans = 2.0000 + 4.0000i -5.0000 + 7.0000i » [real(z1) imag(z1) abs(z1) angle(z1)] ans = 2.0000 4.0000 4.4721 1.1071 » [conj(z1) conj(z2)] ans = 2.0000 - 4.0000i -5.0000 - 7.0000i » [z1+z2 z1-z2 z1*z2 z1/z2] ans = -3.0000 +11.0000i 7.0000 - 3.0000i -38.0000 - 6.0000i 0.2432 - 0.4595i Polar Plots: When dealing with complex numbers we often deal with the polar form. The plot command which directly plots vec- tors of magnitude and angle is polar(theta,r) • This function is also useful for general plotting • As an example the equation of a cardioid in polar form, with parameter a, is r = a ( 1 + cos θ ), 0 ≤ θ ≤ 2π » theta = 0:2*pi/100:2*pi; % Span 0 to 2pi with 100 pts » r = 1+cos(theta); » polar(theta,r) Chapter 3: Mathematical Functions 3–10
  • 11. ECE 1010 ECE Problem Solving I 90 Polar Plot 2 120 60 1.5 150 1 30 0.5 180 0 210 330 240 300 270 Chapter 3: Mathematical Functions 3–11