**Using MATLAB® and Excel®
**

Third Edition

Steven T. Karris

Orchard Publications www.orchardpublications.com

Numerical Analysis

Using MATLAB® and Excel® Third Edition

Students and working professionals will find Numerical Analysis Using MATLAB® and Excel®, Third Edition, to be a concise and easy-to-learn text. It provides complete, clear, and detailed explanations of the principal numerical analysis methods and well known functions used in science and engineering. These are illustrated with many real-world examples.

This text includes the following chapters and appendices: • Introduction to MATLAB • Root Approximations • Sinusoids and Complex Numbers • Matrices and Determinants • Review of Differential Equations • Fourier, Taylor, and Maclaurin Series • Finite Differences and Interpolation • Linear and Parabolic Regression • Solution of Differential Equations by Numerical Methods • Integration by Numerical Methods • Difference Equations • Partial Fraction Expansion • The Gamma and Beta Functions • Orthogonal Functions and Matrix Factorizations • Bessel, Legendre, and Chebyshev Polynomials • Optimization Methods • Difference Equations in Discrete-Time Systems • Introduction to Simulink • Ill-Conditioned Matrices Each chapter contains numerous practical applications supplemented with detailed instructions for using MATLAB and/or Excel to obtain quick solutions. Steven T. Karris is the president and founder of Orchard Publications, has undergraduate and graduate degrees in electrical engineering, and is a registered professional engineer in California and Florida. He has more than 35 years of professional engineering experience and more than 30 years of teaching experience as an adjunct professor, most recently at UC Berkeley, California.

Orchard Publications Visit us on the Internet www.orchardpublications.com or email us: info@orchardpublications.com

19 0 1 ISBN-13: 978-1-934404-04-1 9 0 7 ISBN-10: 1-934404-04-7

$60.00 USA

Numerical Analysis

Using MATLAB® and Excel®

Third Edition

Steven T. Karris

Orchard Publications www.orchardpublications.com

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright ” 2007 Orchard Publications. All rights reserved. Printed in the United States of America. No part of this publication may be reproduced or distributed in any form or by any means, or stored in a data base or retrieval system, without the prior written permission of the publisher. Direct all inquiries to Orchard Publications, info@orchardpublications.com Product and corporate names are trademarks or registered trademarks of the Microsoft™ Corporation and The MathWorks™, Inc. They are used only for identification and explanation, without intent to infringe.

**Library of Congress Cataloging-in-Publication Data
**

Library of Congress Control Number: 2007922100 Copyright TX 5-589-152

ISBN-13: 978-1-934404-04-1 ISBN-10: 1-934404-04-7

Disclaimer

The author has made every effort to make this text as complete and accurate as possible, but no warranty is implied. The author and publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this text.

Preface

Numerical analysis is the branch of mathematics that is used to find approximations to difficult problems such as finding the roots of non−linear equations, integration involving complex expressions and solving differential equations for which analytical solutions do not exist. It is applied to a wide variety of disciplines such as business, all fields of engineering, computer science, education, geology, meteorology, and others. Years ago, high−speed computers did not exist, and if they did, the largest corporations could only afford them; consequently, the manual computation required lots of time and hard work. But now that computers have become indispensable for research work in science, engineering and other fields, numerical analysis has become a much easier and more pleasant task. This book is written primarily for students/readers who have a good background of high−school algebra, geometry, trigonometry, and the fundamentals of differential and integral calculus.* A prior knowledge of differential equations is desirable but not necessary; this topic is reviewed in Chapter 5. One can use Fortran, Pascal, C, or Visual Basic or even a spreadsheet to solve a difficult problem. It is the opinion of this author that the best applications programs for solving engineering problems are 1) MATLAB which is capable of performing advanced mathematical and engineering computations, and 2) the Microsoft Excel spreadsheet since the versatility offered by spreadsheets have revolutionized the personal computer industry. We will assume that the reader has no prior knowledge of MATLAB and limited familiarity with Excel. We intend to teach the student/reader how to use MATLAB via practical examples and for detailed explanations he/she will be referred to an Excel reference book or the MATLAB User’s Guide. The MATLAB commands, functions, and statements used in this text can be executed with either MATLAB Student Version 12 or later. Our discussions are based on a PC with Windows XP platforms but if you have another platform such as Macintosh, please refer to the appropriate sections of the MATLAB’s User Guide that also contains instructions for installation. MATLAB is an acronym for MATrix LABoratory and it is a very large computer application which is divided to several special application fields referred to as toolboxes. In this book we will be using the toolboxes furnished with the Student Edition of MATLAB. As of this writing, the latest release is MATLAB Student Version Release 14 and includes SIMULINK which is a

* These topics are discussed in Mathematics for Business, Science, and Technology, Third Edition, ISBN 0−9709511− 0−8. This text includes probability and other advanced topics which are supplemented by many practical applications using Microsoft Excel and MATLAB.

software package used for modeling, simulating, and analyzing dynamic systems. SIMULINK is not discussed in this text; the interested reader may refer to Introduction to Simulink with Engineering Applications, ISBN 0−9744239−7−1. Additional information including purchasing the software may be obtained from The MathWorks, Inc., 3 Apple Hill Drive, Natick, MA 01760−2098. Phone: 508 647−7000, Fax: 508 647−7001, e−mail: info@mathwork.com and web site http://www.mathworks.com. The author makes no claim to originality of content or of treatment, but has taken care to present definitions, statements of physical laws, theorems, and problems. Chapter 1 is an introduction to MATLAB. The discussion is based on MATLAB Student Version 5 and it is also applicable to Version 6. Chapter 2 discusses root approximations by numerical methods. Chapter 3 is a review of sinusoids and complex numbers. Chapter 4 is an introduction to matrices and methods of solving simultaneous algebraic equations using Excel and MATLAB. Chapter 5 is an abbreviated, yet practical introduction to differential equations, state variables, state equations, eigenvalues and eigenvectors. Chapter 6 discusses the Taylor and Maclaurin series. Chapter 7 begins with finite differences and interpolation methods. It concludes with applications using MATLAB. Chapter 8 is an introduction to linear and parabolic regression. Chapters 9 and 10 discuss numerical methods for differentiation and integration respectively. Chapter 11 is a brief introduction to difference equations with a few practical applications. Chapters 12 is devoted to partial fraction expansion. Chapters 13, 14, and 15 discuss certain interesting functions that find wide application in science, engineering, and probability. This text concludes with Chapter 16 which discusses three popular optimization methods. New to the Third Edition This is an extensive revision of the first edition. The most notable changes are the inclusion of Fourier series, orthogonal functions and factorization methods, and the solutions to all end−of− chapter exercises. It is in response to many readers who expressed a desire to obtain the solutions in order to check their solutions to those of the author and thereby enhancing their knowledge. Another reason is that this text is written also for self−study by practicing engineers who need a review before taking more advanced courses such as digital image processing. The author has prepared more exercises and they are available with their solutions to those instructors who adopt this text for their class. Another change is the addition of a rather comprehensive summary at the end of each chapter. Hopefully, this will be a valuable aid to instructors for preparation of view foils for presenting the material to their class. The last major change is the improvement of the plots generated by the latest revisions of the MATLAB® Student Version, Release 14. Orchard Publications Fremont, California www.orchardpublications.com info@orchardpublications.com

**Table of Contents 1 Introduction to MATLAB
**

1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12 1.13

1−1

Command Window.................................................................................................1−1 Roots of Polynomials...............................................................................................1−3 Polynomial Construction from Known Roots ........................................................1−4 Evaluation of a Polynomial at Specified Values .....................................................1−5 Rational Polynomials ..............................................................................................1−8 Using MATLAB to Make Plots..............................................................................1−9 Subplots.................................................................................................................1−18 Multiplication, Division and Exponentiation.......................................................1−19 Script and Function Files......................................................................................1−26 Display Formats ....................................................................................................1−31 Summary ...............................................................................................................1−33 Exercises................................................................................................................1−37 Solutions to End−of−Chapter Exercises ...............................................................1−38

MATLAB Computations: Entire chapter

2

Root Approximations 2.1 2.2 2.3 2.4 2.5 2.6

2−1

Newton’s Method for Root Approximation...........................................................2−1 Approximations with Spreadsheets........................................................................2−7 The Bisection Method for Root Approximation .................................................2−19 Summary...............................................................................................................2−27 Exercises ...............................................................................................................2−28 Solutions to End−of−Chapter Exercises ...............................................................2−29

MATLAB Computations: Pages 2−2 through 2−7, 2−14, 2−21 through 2−23, 2−29 through 2−34 Excel Computations: Pages 2−8 through 2−19, 2−24 through 2−26

3

Sinusoids and Phasors 3.1 3.2 3.3 3.4 3.5 3.6 3.7

3−1

Alternating Voltages and Currents ........................................................................ 3−1 Characteristics of Sinusoids.................................................................................... 3−2 Inverse Trigonometric Functions ......................................................................... 3−10 Phasors.................................................................................................................. 3−10 Addition and Subtraction of Phasors ................................................................... 3−11 Multiplication of Phasors...................................................................................... 3−12 Division of Phasors ............................................................................................... 3−13

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

i

3.8 3.9 3.10 3.11

Exponential and Polar Forms of Phasors ..............................................................3−13 Summary ...............................................................................................................3−24 Exercises................................................................................................................3−27 Solutions to End−of−Chapter Exercises................................................................3−28

MATLAB Computations: Pages 3−15 through 3−23, 3−28 through 3−31 Simulink Modeling: Pages 3−16 through 3−23

4

Matrices and Determinants 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10 4.11 4.12 4.13 4.14

4−1

Matrix Definition.....................................................................................................4−1 Matrix Operations ...................................................................................................4−2 Special Forms of Matrices........................................................................................4−5 Determinants ...........................................................................................................4−9 Minors and Cofactors ............................................................................................4−13 Cramer’s Rule ........................................................................................................4−18 Gaussian Elimination Method...............................................................................4−20 The Adjoint of a Matrix ........................................................................................4−22 Singular and Non−Singular Matrices ....................................................................4−22 The Inverse of a Matrix.........................................................................................4−23 Solution of Simultaneous Equations with Matrices ..............................................4−25 Summary ................................................................................................................4−32 Exercises ................................................................................................................4−36 Solutions to End−of−Chapter Exercises ................................................................4−38

MATLAB Computations: Pages 4−3, 4−5 through 4−8, 4−10, 4−12, 4−3, 4−5, 4−19 through 4−20, 4−24, 4−26, 4−28, 4−30, 4−38, 4−41, 4−43 Excel Computations: Pages 4−28 through 4−29, 4−42 through 4−43

5

Differential Equations, State Variables, and State Equations 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.10 5.11 5.12

5−1

Simple Differential Equations..................................................................................5−1 Classification............................................................................................................5−2 Solutions of Ordinary Differential Equations (ODE) .............................................5−6 Solution of the Homogeneous ODE ...................................................................... 5−8 Using the Method of Undetermined Coefficients for the Forced Response ........ 5−10 Using the Method of Variation of Parameters for the Forced Response ............. 5−20 Expressing Differential Equations in State Equation Form.................................. 5−24 Solution of Single State Equations ....................................................................... 5−27 The State Transition Matrix ................................................................................ 5−28 Computation of the State Transition Matrix ...................................................... 5−30 Eigenvectors.......................................................................................................... 5−38 Summary .............................................................................................................. 5−42

ii

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

5.13 Exercises ............................................................................................................... 5−47 5.14 Solutions to End−of−Chapter Exercises............................................................... 5−49 MATLAB Computations: Pages 5−11, 5−13 through 5−14, 5−16 through 5−17, 5−19, 5−23, 5−33 through 5−35, 5−37, 5−49 through 5−53, 5−55 Fourier, Taylor, and Maclaurin Series 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 6.10 6.11 6.12 6.13 6−1 Wave Analysis ........................................................................................................6−1 Evaluation of the Coefficients ...............................................................................6−2 Symmetry ...............................................................................................................6−7 Waveforms in Trigonometric Form of Fourier Series .........................................6−12 Alternate Forms of the Trigonometric Fourier Series .........................................6−25 The Exponential Form of the Fourier Series .......................................................6−29 Line Spectra .........................................................................................................6−33 Numerical Evaluation of Fourier Coefficients .....................................................6−36 Power Series Expansion of Functions ..................................................................6−40 Taylor and Maclaurin Series ................................................................................6−41 Summary ..............................................................................................................6−48 Exercises ..............................................................................................................6−51 Solutions to End−of−Chapter Exercises ..............................................................6−53

6

MATLAB Computations: Pages 6−35, 6−45, 6−58 through 6−61 Excel Computations: Pages 6−37 through 6−39

7

Finite Differences and Interpolation 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 7.10 7.11

7−1

Divided Differences ............................................................................................... 7−1 Factorial Polynomials ............................................................................................. 7−6 Antidifferences ................................................................................................... 7−12 Newton’s Divided Difference Interpolation Method ......................................... 7−15 Lagrange’s Interpolation Method ........................................................................ 7−17 Gregory−Newton Forward Interpolation Method .............................................. 7−19 Gregory−Newton Backward Interpolation Method ........................................... 7−21 Interpolation with MATLAB ............................................................................. 7−24 Summary ............................................................................................................. 7−39 Exercises ............................................................................................................. 7−44 Solutions to End−of−Chapter Exercises ............................................................. 7−45

MATLAB Computations: Pages 7−8 through 7−9, 7−13 through 7−15, 7−26 through 7−38, 7−45 through 7−46, 7−48, 7−50, 7−52 Excel Computations: Pages 7−17 through 7−19, 7−22 through 7−25, 7−49, 7−52

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

iii

8

Linear and Parabolic Regression 8.1 8.2 8.3 8.4 8.5 8.6 8.7

8−1

Curve Fitting ..........................................................................................................8−1 Linear Regression ...................................................................................................8−2 Parabolic Regression ..............................................................................................8−7 Regression with Power Series Approximations ....................................................8−14 Summary ..............................................................................................................8−24 Exercises ...............................................................................................................8−26 Solutions to End−of−Chapter Exercises ...............................................................8−28

MATLAB Computations: Pages 8−11 through 8−14, 8−17 through 8−23, 8−30 through 8−34 Excel Computations: Pages 8−5 through 8−10, 8−15 through 8−19, 8−28 through 8−32

9

Solution of Differential Equations by Numerical Methods 9.1 9.2 9.3 9.4 9.5 9.6 9.7

9−1

Taylor Series Method ............................................................................................ 9−1 Runge−Kutta Method ............................................................................................ 9−5 Adams’ Method ................................................................................................... 9−13 Milne’s Method .................................................................................................... 9−15 Summary .............................................................................................................. 9−17 Exercises .............................................................................................................. 9−20 Solutions to End−of−Chapter Exercises .............................................................. 9−21

MATLAB Computations: Pages 9−5, 9−9 through 9−12, 9−21 through 9−23 Excel Computations: Page 9−2, 9−14, 9−22 through 9−26

10

Integration by Numerical Methods 10.1 10.2 10.3 10.4 10.5

10−1

The Trapezoidal Rule .......................................................................................... 10−1 Simpson’s Rule ..................................................................................................... 10−6 Summary ............................................................................................................ 10−14 Exercises ............................................................................................................ 10−15 Solution to End−of−Chapter Exercises .............................................................. 10−16

MATLAB Computations: Pages 10−3 through 10−6, 10−9 through 10−13, 10−16, 10−18 through 10−21 Excel Computations: Pages 10−10, 10−19 through 10−21

11

Difference Equations

11−1

11.1 Introduction ......................................................................................................... 11−1 11.2 Definition, Solutions, and Applications .............................................................. 11−1 11.3 Fibonacci Numbers .............................................................................................. 11−7

iv

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

11.4 Summary .............................................................................................................11−11 11.5 Exercises ............................................................................................................. 11−13 11.6 Solutions to End−of−Chapter Exercises .............................................................11−14

12

Partial Fraction Expansion 12.1 12.2 12.3 12.4 12.5

12−1

Partial Fraction Expansion ..................................................................................12−1 Alternate Method of Partial Fraction Expansion ..............................................12−13 Summary ............................................................................................................12−19 Exercises ............................................................................................................12−22 Solutions to End−of−Chapter Exercises ............................................................12−23

MATLAB Computations: Pages 12−3 through 12−5, 12−9 through 12−12, 12−16 through 12-18, 12−23 through 12−28

13

The Gamma and Beta Functions and Distributions 13.1 13.2 13.3 13.4 13.5 13.6 13.7

13−1

The Gamma Function .........................................................................................13−1 The Gamma Distribution ..................................................................................13−16 The Beta Function .............................................................................................13−17 The Beta Distribution ........................................................................................13−20 Summary ............................................................................................................13−22 Exercises ............................................................................................................13−24 Solutions to End−of−Chapter Exercises ............................................................13−25

MATLAB Computations: Pages 13−3, 13−5, 13−10, 13−19, 13−25 Excel Computations: Pages 13−5, 13−10, 13−16 through 13−17, 13−19, 13−21

14

Orthogonal Functions and Matrix Factorizations 14.1 14.2 14.3 14.4 14.5 14.6 14.7 14.8 14.9 14.10 14.11

14−1

Orthogonal Functions ......................................................................................14−1 Orthogonal Trajectories ...................................................................................14−2 Orthogonal Vectors ..........................................................................................14−4 The Gram−Schmidt Orthogonalization Procedure ..........................................14−7 The LU Factorization .......................................................................................14−9 The Cholesky Factorization ............................................................................14−23 The QR Factorization .....................................................................................14−25 Singular Value Decomposition .......................................................................14−28 Summary .........................................................................................................14−30 Exercises .........................................................................................................14−32 Solutions to End−of−Chapter Exercises .........................................................14−34

MATLAB Computations: Pages 14−8 through 14−9, 14−11 through 14−29, 14−36, 14−38 through 14−39

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

v

15

Bessel, Legendre, and Chebyshev Functions 15.1 15.2 15.3 15.4 15.5 15.6 15.7

15−1

The Bessel Function ............................................................................................15−1 Legendre Functions ...........................................................................................15−10 Laguerre Polynomials .........................................................................................15−21 Chebyshev Polynomials .....................................................................................15−22 Summary ............................................................................................................15−27 Exercises .............................................................................................................15−32 Solutions to End−of−Chapter Exercises ............................................................15−33

MATLAB Computations: Pages 15−3 through 15−4, 15−6, 15−9, 14−19 through 15−22, 15−25, 15−33, 15−35 through 15−37 Excel Computations: Pages 15−5, 15−9

16

Optimization Methods 16.1 16.2 16.3 16.4 16.5 16.6

16−1

Linear Programming ........................................................................................... 16−1 Dynamic Programming ........................................................................................16−4 Network Analysis ...............................................................................................16−14 Summary ............................................................................................................16−19 Exercises .............................................................................................................15−20 Solutions to End−of−Chapter Exercises ............................................................15−22

MATLAB Computations: Pages 16−3 Excel Computations: Pages 16−4, 16−23, 16−25 through 16−27

A B C

Difference Equations in Discrete−Time Systems

A−1

A.1 Recursive Method for Solving Difference Equations........................................... A−1 A.2 Method of Undetermined Coefficients ................................................................A−1 MATLAB Computations: Pages A−4, A−7, A−9 Introduction to Simulink® B.1 B.2 B−1

Simulink and its Relation to MATLAB ............................................................... B−1 Simulink Demos .................................................................................................. B−20

MATLAB Computations and Simulink Modeling: Entire Appendix B Ill-Conditioned Matrices C−1

C.1 The Norm of a Matrix ...........................................................................................C−1 C.2 Condition Number of a Matrix .............................................................................C−2 C.3 Hilbert Matrices ....................................................................................................C−3

vi

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

MATLAB Computations: Pages C−1. C−4 through C−5 References Index R−1 IN−1 Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications vii .

and making plots. the right justified bar will be omitted. access to MATLAB’s Editor/ Debugger. important terms and MATLAB functions. MATLAB now waits for a new command from the user.1 Command Window To distinguish the screen displays from the user commands. for example. To use the Editor/Debugger: 1. We can use the Editor/Debugger to write our program.m. 1. it distinguishes between upper− and lower−case letters. These bars will not be shown whenever an example begins at the top of a page or at the bottom of a page. finding the roots of a polynomial. Throughout this text. This takes us to the Editor Window where we can type our script (list of statements) for a new file. we choose New and click on M−File. comment lines. It is a good * EDU>> is the MATLAB prompt in the Student Version. that is. and a right justified horizontal bar will denote the end of the example. and return to the command screen to execute the program as explained below. we see the toolbar on top of the command screen and the prompt EDU>>. a left justified horizontal bar will denote the beginning of an example. procedures for naming and saving the user generated files. we will use the following conventions: Click: Click the left button of the mouse Courier Font: Screen displays Helvetica Font: User inputs at MATLAB’s command window prompt EDU>>* Helvetica Bold: MATLAB functions Bold Italic: Important terms and facts. Several examples are provided with detailed explanations. save it. t and T are two different characters in MATLAB language. We must save our program with a file name which starts with a letter. From the File menu on the toolbar. when one example follows immediately after a previous example. Third Edition Copyright © Orchard Publications 1−1 . Important! MATLAB is case sensitive. The files that we create are saved with the file name we use and the extension . Also.Chapter 1 Introduction to MATLAB T his chapter is an introduction of the basic MATLAB commands and functions. This prompt is displayed also after execution of a command. Thus. notes. or open a previously saved file. and file names When we first start MATLAB.m. myfile01. Numerical Analysis Using MATLAB® and Excel®.

To appreciate MATLAB’s capabilities. and MATLAB returns to the command window. We should also use a separate disk to backup our files. The command help matlab iofun will display input/output information. if we want MATLAB to retain all previously entered commands. we should use the clear command. The clc command clears the screen but MATLAB still remembers all values. All text after the % (percent) symbol is interpreted by MATLAB as a comment line and thus it is ignored during the execution of a program. If we have saved our file in drive a or any other drive. the statements conv(p. to get information on graphics. such as 3 – 4i or 3 – 4j .q) % performs multiplication of polynomials p and q % The next statement performs partial fraction expansion of p(x) / q(x) are both correct. We can also get help from the Help pull− down menu. This command erases everything. we can use the clc command. For example.Chapter 1 Introduction to MATLAB practice to save the script in a file name that is descriptive of our script content. For instance. but leave only the EDU>> prompt on the upper left of the screen. When we are done and want to leave MATLAB. 3. Whenever we want to return to the command window. variables and equations which we have already used. it is like exiting MATLAB and starting it again. we click on the Close button. For instance. we press <enter> and observe the execution and the values obtained from it. we may exit the Editor/Debugger window by clicking on Exit Editor/Debugger of the File menu. Henceforth. we type help matlab graphics. One of the most powerful features of MATLAB is the ability to do computations involving complex numbers. we can type help followed by any topic from the displayed menu. we type demo and we see the MATLAB Demos menu. In other words. then. A comment can be typed on the same line as the function or command or as a separate line. Once the script is written and saved as an m−file. we ought to name and save that file as matrices01.m or any other similar name. For example. The MATLAB User’s Guide contains numerous help topics. To execute a program. we type the file name without the . we type quit or exit. or j to denote the imaginary part of a complex number. if the script performs some matrix operations. To get help with other MATLAB topics. But if we want to clear all previous values. we must make sure that it is added it to the desired directory in MATLAB’s search path. The MATLAB User’s Guide provides more information on this topic. it will be understood that each input command is typed after the EDU>> prompt and followed by the <enter> key. Third Edition Copyright © Orchard Publications . variables. We can do this periodically to become familiar with them. 2.m extension at the EDU>> prompt. We can use either i . the statement z=3−4j 1−2 Numerical Analysis Using MATLAB® and Excel®. and equations without exiting.

and the roots as a column vector. We have denoted the polynomial as p1.0000 3. that is.2 Roots of Polynomials In MATLAB. a polynomial is expressed as a row vector of the form [ a n a n – 1 a 2 a 1 a 0 ] .0000 2. p1=[1 −10 35 −50 24] % Specify the coefficients of p1(x) p1 = 1 -10 35 -50 24 roots_ p1=roots(p1) % Find the roots of p1(x) roots_p1 = 4.0000i In the example above.1 Find the roots of the polynomial p 1 ( x ) = x – 10x + 35x – 50x + 24 4 3 2 (1.0000 We observe that MATLAB displays the polynomial coefficients as a row vector.1) Solution: The roots are found with the following two statements. The elements a i of this vector are the coefficients of the polynomial in descending order. we must use the multiplication sign. We must include terms whose coefficients are zero. and the roots as roots_ p1.4. Numerical Analysis Using MATLAB® and Excel®. if the imaginary part is a function or variable such as cos ( x ) . Example 1. 1. a multiplication (*) sign between 4 and j was not necessary because the complex number consists of numerical constants. We can find the roots of any polynomial with the roots(p) function where p is a row vector containing the polynomial coefficients in descending order. However.0000 1. Third Edition Copyright © Orchard Publications 1−3 .0000 .Roots of Polynomials displays z = 3. we must type cos(x)*j or j*cos(x).

2) Solution: There is no cube term. 3. * By definition.5014 2. with the given roots as elements of this vector.2 Find the roots of the polynomial p 2 ( x ) = x – 7x + 16x + 25x + 52 5 4 2 (1. Of course. Solution: We first define a row vector.3 Polynomial Construction from Known Roots We can compute the coefficients of a polynomial from a given set of roots with the poly(r) function where r is a row vector containing the roots. complex roots always occur in complex conjugate* pairs.3202i -0.7428 -1. say r3 .3366 . Example 1. Third Edition Copyright © Orchard Publications . and 4 . we find the coefficients with the poly(r) function as shown below.3 It is known that the roots of a polynomial are 1. and the roots of this polynomial as roots_ p2. then.5711 -0.1. therefore.3366 + 1. 1. Compute the coefficients of this polynomial. we must enter zero as its coefficient.Chapter 1 Introduction to MATLAB Example 1. the conjugate of a complex number A = a + jb is A∗ = a – jb 1−4 Numerical Analysis Using MATLAB® and Excel®. 2. and two complex roots. The roots are found with the statements below where we have defined the polynomial as p2.3202i The result indicates that this polynomial has three real roots. p2=[1 −7 0 16 25 52] p2 = 1 -7 0 16 25 52 roots_ p2=roots(p2) roots_ p2 = 6.

Third Edition Copyright © Orchard Publications 1−5 .5. – 3. with the given roots. say r4 . Find the coefficients of this polynomial. Example 1.x) function evaluates a polynomial p ( x ) at some specified value of the independent variable x . Solution: We form a row vector. Numerical Analysis Using MATLAB® and Excel®.1. 4 + j5. the polynomial is p 4 ( x ) = x + 14x + 100x + 340x + 499x + 246 (1.3) 1.4 It is known that the roots of a polynomial are – 1. and we find the polynomial coefficients with the poly(r) function as shown below.0000 + 5.0000 -3. and 4 – j5 .0000 Column 5 -4.0000i poly_r4 = 1 14 100 340 5 4 499 3 246 2 Therefore. r4=[ −1 −2 −3 4+5j 4−5j ] r4 = Columns 1 through 4 -1.0000 .0000i poly_r4=poly(r4) -4.4 Evaluation of a Polynomial at Specified Values The polyval(p. – 2.0000 -2.Evaluation of a Polynomial at Specified Values r3=[1 2 3 4] % Specify the roots of the polynomial r3 = 1 2 3 4 poly_r3=poly(r3) % Find the polynomial coefficients poly_r3 = 1 -10 35 -50 24 We observe that these are the coefficients of the polynomial p 1 ( x ) of Example 1.

4) val_minus3 = 1280 Other MATLAB functions used with polynomials are the following: conv(a. Solution: p1=[1 −3 0 5 7 9]. -8 34 18 -24 -74 -88 78 166 174 108 1−6 Numerical Analysis Using MATLAB® and Excel®.p2) p1p2 = 2 -6 Therefore.5 Evaluate the polynomial at x = – 3 . % These are the coefficients % The semicolon (. p2=[2 0 −8 0 4 10 12].b) − multiplies two polynomials a and b [q. −3)% Evaluate p5 at x=−3. % val_minus3=polyval(p5. Example 1.5) Compute the product p 1 ⋅ p 2 with the conv(a.r]=deconv(c.d) −divides polynomial c by polynomial d and displays the quotient q and remainder r.b) function. Solution: p5=[1 −3 0 5 −4 3 2].) after the right bracket suppresses the display of the row vector % that contains the coefficients of p5. No semicolon is used here % because we want the answer to be displayed p 5 ( x ) = x – 3x + 5x – 4x + 3x + 2 6 5 3 2 (1. p1p2=conv(p1. polyder(p) − produces the coefficients of the derivative of a polynomial p.6 Let p 1 = x – 3x + 5x + 7x + 9 p 2 = 2x – 8x + 4x + 10x + 12 6 4 2 5 4 2 (1.Chapter 1 Introduction to MATLAB Example 1. Third Edition Copyright © Orchard Publications .

the quotient q ( x ) and remainder r ( x ) are q ( x ) = 0. der_p5=polyder(p5) 6 4 2 r ( x ) = 4x – 3x + 3x + 2x + 3 5 4 2 (1. Solution: p3=[1 0 −3 0 5 7 9].Evaluation of a Polynomial at Specified Values p 1 Þ p 2 = 2x 11 – 6x 5 10 – 8x + 34x + 18x – 24x 4 3 2 9 8 7 6 – 74x – 88x + 78x + 166x + 174x + 108 We can write MATLAB statements in one line if we separate them by commas or semicolons. [q.r]=deconv(p3.7 Let p 3 = x – 3x + 5x + 7x + 9 p 4 = 2x – 8x + 4x + 10x + 12 Compute the quotient p 3 ⁄ p 4 using the deconv(p. Solution: p5=[2 0 −8 0 4 10 12].5 Example 1.8 Let p 5 = 2x – 8x + 4x + 10x + 12 Compute the derivative dp 5 ⁄ dx using the polyder(p) function. Third Edition Copyright © Orchard Publications 1−7 .p4) 6 5 2 7 5 3 (1. Commas will display the results whereas semicolons will suppress the display. 0 -32 0 8 10 Numerical Analysis Using MATLAB® and Excel®.5000 r = 0 4 -3 0 3 2 3 Therefore. Example 1. p4=[2 −8 0 0 4 10 12].q) function.6) q = 0.7) der_p5 = 12 Therefore.

1.0712 ) ⋅ ( x + 1.1633 ) ⋅ ( x + 0.9961i 1.6760 .4922 ) ⋅ ( x + 1.% Do not display num and den coefficients roots_num=roots(num).4186 – j1.5 Rational Polynomials Rational Polynomials are those which can be expressed in ratio form.9870 ) ⋅ ( x + 0.6760 + 0.Chapter 1 Introduction to MATLAB dp 5 ⁄ dx = 12x – 32x + 4x + 8x + 10 5 3 2 1.0. using the roots(p) function.= ---------------------------------------------------------------------6 4 2 p den 2x – 8x + 4x + 10x + 12 (1.0000 ) 1−8 Numerical Analysis Using MATLAB® and Excel®.4186 + j1.2108 – j 0. that is. For the numerator.9304 ) ⋅ ( x + 0. the complex roots occur in complex conjugate pairs.9870 ) ⋅ ( x + 1. we have p den = ( x – 1.2108 + 0.9870i 2.3370 – j0.6760 + j0. as bn x + bn – 1 x + bn – 2 x + … + b1 x + b0 ) R ( x ) = Num ( x .= ------------------------------------------------------------------------------------------------------------------------------------------m m–1 m–2 Den ( x ) am x + am – 1 x + am – 2 x + … + a1 x + a0 n n–1 n–2 (1.0.3370 . We can find the roots of the numerator and denominator with the roots(p) function as before.9 Let 5 4 2 p num x – 3x + 5x + 7x + 9 R ( x ) = ----------.2108 .4186 + 1. Example 1.3370 + 0.9) Express the numerator and denominator in factored form.0712i -0.9961i roots_den = 1.2108 + j0.0712i -0. den=[2 0 −8 0 4 10 12]. Third Edition Copyright © Orchard Publications .8) where some of the terms in the numerator and/or denominator may be zero.0000 As expected.3370 + j0.0.4186 .4922 ) ⋅ ( x – 1.0712 ) ⋅ ( x – 2.4922i -0.9304 -1.1633 -1.4922i -0. we have the factored form p num = ( x – 2.9961 ) and for the denominator. roots_den=roots(den) % Display num and den roots roots_num = 2.9961 ) ⋅ ( x + 0. Solution: num=[1 −3 0 5 7 9].6760 – j0.9870i -1.

1.2108+0. the negative sum of the roots is equal to the coefficient b of the x term. while the amplitude was held constant.9870i) ans = 1. Here. we want to plot a set of ordered pairs.10 Consider the electric circuit of Figure 1. while the product of the roots is equal to the constant term c .6760+0.3370−0.3370+0. (2. that is. Numerical Analysis Using MATLAB® and Excel®. We recall that in a quadratic equation of the form x 2 + bx + c = 0 whose roots are x 1 and x 2 .9971 (−0. This is a very easy task with the MATLAB plot(x.9961i) % Form the product of the 2nd set of complex conjugates ans = 1. Accordingly. Solution: We cannot type ω (omega) in the MATLAB command window.1.2108−0. that is. x 1 ⋅ x 2 = c .9870i)*(−0.6760−0.4186 −1.0712i)*(2. x is the horizontal axis (abscissa) and y is the vertical axis (ordinate).Using MATLAB to Make Plots We can also express the numerator and denominator of this rational function as a combination of linear and quadratic factors. The ammeter readings were then recorded for each frequency.0712i) % Form the product of the 1st set of complex conjugates ans = 6.0512 (−0. then we multiply the complex conjugate roots to obtain the constant term c using MATLAB as indicated below. The magnitude of the impedance Z was computed as Z = V ⁄ A and the data were tabulated in Table 1.9961i)*(−0. so we will use the English letter w instead.4186+1. – ( x 1 + x 2 ) = b . Plot the magnitude of the impedance. where the radian frequency ω (radians/second) of the applied voltage was varied from 300 to 3000 in steps of 100 radians/second. Example 1.4922i) ans = 3. Third Edition Copyright © Orchard Publications 1−9 . Z versus radian frequency ω .1058 (1.y) command which plots y versus x .0186 1.4922i)*(1.6 Using MATLAB to Make Plots Quite often. that is. we form the coefficient b by addition of the complex conjugate roots and this is done by inspection.

or a row vector is too long to fit in one line.122 42. we use the semicolon (.353 103.184 97.83 266.339 52.588 67..182 40.) to suppress the display of numbers which we do not care to see on the screen. The data are entered as follows: w=[300 400 500 600 700 800 900 1000 1100 1200 1300 1400. Electric circuit for Example 1.611 51. it can be continued to the next line by typing three or more periods.589 71.10 ω (rads/s) 300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 Z Ohms 39.717 46.428 48.240 54.481 58.1 Table for Example 1.10 TABLE 1.111 ω (rads/s) 1700 1800 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900 3000 Z Ohms 90.032 187.751 120. This is illustrated below for the data of w and z.437 222.845 If a statement. 1−10 Numerical Analysis Using MATLAB® and Excel®..513 62. and continue to enter data.286 44.938 469.056 1014. % Use 4 periods to continue 1500 1600 1700 1800 1900 2000 2100 2200 2300 2400 2500. Also.182 436. then pressing <enter> to start a new line.088 73.665 140. Third Edition Copyright © Orchard Publications .. as mentioned before..603 81.052 145.1.432 38..Chapter 1 Introduction to MATLAB A R1 R2 C V L Figure 1..

611 51.437 222.. 90. Numerical Analysis Using MATLAB® and Excel®.468.240 54. or any plot.104 97. To see the graph again. we click on the Window pull−down menu. we use the plot(x. 1014. % Use semicolon to suppress display of these numbers % z=[39. The grid off command removes the grid.Using MATLAB to Make Plots 2600 2700 2800 2900 3000]. and we select Figure.y) command. Plot of impedance z versus frequency ω for Example 1. we simply type w or z.088 73. We can make the above. we press any key. 1200 1000 800 600 400 200 0 0 500 1000 1500 2000 2500 3000 Figure 1.717 46.481 58.830 266.032 187.286 44. * Default is a particular value for a variable or condition that is assigned automatically by an operating system.513 62. To return to the command window.. we select MATLAB Command Window. that is.2. The default* is off..432 38.. This plot is shown in Figure 1. and remains in effect unless canceled or overridden by the operator.845]. and we press <enter>. When this command is executed.588 67. For this example. if we want to see the values of w or z or both... we use plot(w. more presentable with the following commands: grid on: This command adds grid lines to the plot. MATLAB displays the plot on MATLAB’s graph screen.056.z).339 52.10 This plot is referred to as the amplitude frequency response of the circuit.751 120. changes from off to on or vice versa.182 436.789 71. Third Edition Copyright © Orchard Publications 1−11 ..052 145. To plot z ( y – axis ) versus w ( x – axis ). or from the Window pull−down menu. 48.665 140.2...111. The command grid toggles them.353 103.182 40. Of course.122 42.603 81.938 469.

and box on restores the box.2.z). The amplitude frequency response is usually represented with the x −axis in a logarithmic scale. whereas the common logarithm is expressed as log10(x). except that the x −axis is represented as a log scale. except that the y −axis is represented as a log scale. voltage. Likewise. and ln is the natural (base e) logarithm. Throughout this text. We must remember. or current. A review of the decibel unit follows.y) command. grid. ylabel('|Z| in Ohms') After execution of these commands. the semilogy(x. the x −axis of the frequency response is more often shown in a logarithmic scale. Modified frequency response plot of Figure 1.y) command uses logarithmic scales for both axes. 1−12 Numerical Analysis Using MATLAB® and Excel®. The default is on. by adding the following statements: semilogx(w. the function log(x) in MATLAB is the natural logarithm. and the y −axis as a linear scale. % Replaces the plot(w. it will be understood that log is the common (base 10) logarithm.3. our plot is as shown in Figure 1. and the x −axis as a linear scale.y) command. Third Edition Copyright © Orchard Publications . however. title(‘string’): This command adds a line of the text string (label) at the top of the plot.3. Radian Frequency 10 w in rads/sec 3 10 4 Figure 1.z) command title('Magnitude of Impedance vs. We can use the semilogx(x. If the y −axis represents power. The command box toggles them.y) command is similar to the plot(x. The loglog(x. xlabel('w in rads/sec'). the logarithm to the base 2 is expressed as log2(x). and the y −axis in dB (decibels) scale.Chapter 1 Introduction to MATLAB box off: This command removes the box (the solid lines which enclose the plot). 1200 1000 800 |Z| in Ohms 600 400 200 0 2 10 Magnitude of Impedance vs. xlabel(‘string’) and ylabel(‘string’) are used to label the x − and y −axis respectively. Likewise. Let us now redraw the plot with the above options. Radian Frequency').y) command that is similar to the plot(x.

10 dB represents a power ratio of 10 10n dB represents a power ratio of 10 It is very useful to remember that: 20 dB represents a power ratio of 100 30 dB represents a power ratio of 1. 27 dB = 20 dB + 7 dB and this is equivalent to a power ratio of approximately 100 × 5 = 500 Using the relations y = log x = 2 log x and 2 P = V. For instance.25 ) = ratio of 2.10) Therefore. we can estimate other values.= I Z -----Z 2 2 n if we let Z = 1 . Third Edition Copyright © Orchard Publications 1−13 . If the gain (or loss) is 0 dB the output is equal to the input.5 Likewise. P out dB = 10 log --------P in (1. or current) can be expressed in decibels (dB). By definition.Using MATLAB to Make Plots The ratio of any two values of the same quantity (power. 000 60 dB represents a power ratio of 1. Thus. voltage.25 then.25 3 dB represents a power ratio of approximately 2 7 dB represents a power ratio of approximately 5 From these. the dB values for voltage and current ratios become Numerical Analysis Using MATLAB® and Excel®. 4 dB ≅ ratio of ( 2 × 1. 000. we say that an amplifier has 10 dB power gain. 4 dB = 3 dB + 1 dB and since 3 dB ≅ power ratio of 2 and 1 dB ≅ power ratio of 1. 1 dB represents a power ratio of approximately 1. 000 Also. or a transmission line has a power loss of 7 dB (or gain – 7 dB ).

and colors. and we press <enter>.= 20 log ------I in I in To display the voltage v in a dB scale on the y – axis .95. v=sin(x+4*pi/3). We will illustrate its use with the following example which plots a 3−phase sinusoidal waveform.02: 2)*pi instead.2.x.y. where s is a character string containing one or more characters shown on the three columns of Table 1. These. and displays a cross−hair which can be moved around with the mouse. The command text(x. % we could have used x=0:0. we add the relation dB=20*log10(v).x.2 for each additional line in the plot.85.’string’) is similar to gtext(‘string’). Also.65.s) command. text(4. last_value. However. The command gtext(‘string’) switches to the current Figure Window. MATLAB has no default color. The first line of the script below has the form linspace(first_value. 2*pi. For instance. In our previous examples.4. An alternate command uses the colon notation and has the format x=first: increment: last This format specifies the increments between points but not the number of data points. % The x−axis must be specified for each function grid on. It places a label on a plot in some specific location specified by x and y. box on. no markers are 1−14 Numerical Analysis Using MATLAB® and Excel®. we can use the command gtext(‘Impedance |Z| versus Frequency’). and we replace the semilogx(w.75. we can move the cross−hair to the position where we want our label to begin. 0. 0. u=sin(x+2*pi/3). text(2. y=sin(x). MATLAB allows us to specify various line types.11) (1. % pi is a built−in function in MATLAB. and string is the label which we want to place at that location. using the mouse. Third Edition Copyright © Orchard Publications .dB). we did not specify line styles. and this will place a cross−hair in the Figure window. markers.y. 0. number_of_values) This command specifies the number of data points but not the increments between data points. The script for the 3−phase plot is as follows: x=linspace(0.65.v). plot symbols. plot(x. 'sin(x+4*pi/3)') These three waveforms are shown on the same plot of Figure 1.z) command with semilogx(w.Chapter 1 Introduction to MATLAB V out dB v = 10 log --------V in 2 and V out = 20 log --------V in (1.u. there is no default marker.12) I out 2 I out dB i = 10 log ------. and colors for our plots. Then. it starts with blue and cycles through the first seven colors listed in Table 1. or a combination of these. can be added with the plot(x.y. 60).65. 'sin(x+2*pi/3)'). 'sin(x)'). % turn grid and axes box on text(0.02*pi:2*pi or x = (0: 0.

5 sin(x+2*pi/3) sin(x+4*pi/3) 0 -0. we must type plot(x.y. and markets used in MATLAB Symbol b g r c m y k w Color blue green red cyan magenta yellow black white Symbol Marker point circle x−mark plus star square diamond triangle down triangle up triangle left triangle right pentagram hexagram Symbol Line Style solid line dotted line dash−dot line dashed line . 1 sin(x) 0.5 -1 0 1 2 3 4 5 6 7 Figure 1.4.'m*:') plots a magenta dotted line with a star at each data point. Three−phase waveforms TABLE 1. Third Edition Copyright © Orchard Publications 1−15 . −− ⁄ Ÿ < > p h For example.y.'rs') plots a red square at each data point. If we want to connect the data points with a solid line.y. colors. Numerical Analysis Using MATLAB® and Excel®.Using MATLAB to Make Plots drawn unless they are selected. the command plot(x. o x + * s d − : −. and plot(x.'rs−').2 Styles. The default line is the solid line. For additional information we can type help plot in MATLAB’s command screen. but does not draw any line because no line was selected.

Third Edition Copyright © Orchard Publications .^3+x+3. and z are three vectors of the same length. The general format is plot3(x1. or line style.s2.y2.5.*y.11 Plot the function z = – 2x + x + 3y – 1 Solution: We arbitrarily choose the interval (length) shown with the script below.s3.s1.z). MATLAB has also a three−dimensional (three−axes) capability and this is discussed next.z1.Chapter 1 Introduction to MATLAB The plots which we have discussed thus far are two−dimensional.) where xn.^2−1.5.11 * This statement uses the so called dot multiplication.x3. dot division. and dot exponentiation where these operations are preceded by a dot (period). Example 1.. and zn are vectors or matrices.y. where x .y1.y3. z= −2.y.5: 10.. y= x. x= −10: 0.z2. y . These strings are the same as those of the two−dimensional plots. grid % Length of vector x % Length of vector y must be same as x % Vector z is function of both x and y* 3 2 (1. Three dimensional plot for Example 1. 1−16 Numerical Analysis Using MATLAB® and Excel®.z) plots a line in 3−space through the points whose coordinates are the elements of x . 3000 2000 1000 0 -1000 -2000 10 5 0 -5 -10 -10 -5 0 5 10 Figure 1. y . and sn are strings specifying color. that is.x2..8.z3. and z . marker symbol. The command plot3(x.13) The three−dimensional plot is shown in Figure 1.*x. yn. Page 1−19. plot3(x. These operations will be explained in Section 1. they are drawn on two axes.

z. n ] = size ( Z ) . the vertices of the mesh lines are the triples { x ( j ).'bd−') will display the plot in blue diamonds.y) function which creates the matrix X whose rows are copies of the vector x.y. Example 1. grid on and box off are the default states. we can set the limits of the x − and y − axes with the axis([xmin xmax ymin ymax]) command.y) or plot3(x. Third Edition Copyright © Orchard Publications 1−17 . Z ( i.Using MATLAB to Make Plots The command plot3(x.’string’) command will place string beginning at the co−ordinate ( x. that is. and the matrix Y whose columns are copies of the vector y. or on the same line without first executing the plot command. as in the previous example. draws contour lines for n levels.z) commands.y. y ( i ). Likewise.z.y.z) command displays a three−dimensional plot. connected with a solid line. In a two−dimensional plot.14) Plot the volume of the cone as r and h vary on the intervals 0 ≤ r ≤ 4 and 0 ≤ h ≤ 6 meters. y. this topic will be explained in Section 1. z ) on the plot. In a three−dimensional plot. The three−dimensional text(x. This must be done for each plot. We observe that x corresponds to the columns of Z . in a three−dimensional plot we can set the limits of all three axes with the axis([xmin xmax ymin ymax zmin zmax]) command.Y]=meshgrid(x. It must be placed after the plot(x. and y corresponds to the rows of Z . Another command.z) command with two vector argum e n t s . We can generate the matrices X and Y with the [X.n). h ) The three−dimensional plot is created with the following MATLAB script where. in the second line we have used the dot multiplication. Page 1−19.y. To produce a mesh plot of a function of two variables. T h e s e m u s t b e d e f i n e d a s length ( x ) = n a n d length ( y ) = m w h e r e [ m. division.8. and exponentiation. j ) } . Numerical Analysis Using MATLAB® and Excel®. For three−dimensional plots. The mesh(x. In this case.12 The volume V of a right circular cone of radius r and height h is given by 2 V = 1 πr h -3 (1. contour(Z. We can also use the mesh(x. As mentioned in the footnote of the previous page. V = f ( r. say z = f ( x. we can use the zlabel(‘string’) command in addition to the xlabel(‘string’) and ylabel(‘string’).y. Solution: The volume of the cone is a function of both the radius r and the height h . we must first generate the X and Y matrices which consist of repeated rows and columns over the range of the variables x and y . y ) .

volume (cubic meters) 150 100 50 0 6 4 2 0 0 1 2 3 4 y-axis. The MATLAB User’s manual contains more examples. This command divides the window into an m × n matrix of plotting areas and chooses the pth area to be active. Volume of Right Circular Cone z-axis. MATLAB can generate very sophisticated and impressive three−dimensional plots. and the plot of Figure 1. and p . 1. altitude h (meters) x-axis.* H) .7 Subplots MATLAB can display up to four windows of different plots on the Figure window using the command subplot(m. title('Volume of Right Circular Cone').H]=meshgrid(0: 4.6.6. H. Volume of a right circular cone. % Creates R and H matrices from vectors r and h V=(pi .p).^ 2 . radius r (meters)'). The possible combinations are shown in Figure 1. ylabel('y−axis. are rudimentary. V) xlabel('x−axis. We will illustrate the use of the subplot(m.7. shows how the volume of the cone increases as the radius and height are increased. No spaces or commas are required between the three integers m .5.n./ 3. 1−18 Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications . division and exponentiation that follows. box on The three−dimensional plot of Figure 1. volume (cubic meters)').* R . zlabel('z−axis. mesh(R.p) command following the discussion on multiplication. 0: 6). radius r (meters) Figure 1. This.n.Chapter 1 Introduction to MATLAB [R. altitude h (meters)'). n .

7. These are the matrix multiplication.8 Multiplication. Division and Exponentiation MATLAB recognizes two types of multiplication. 11] b = -1 3 6 11 b=[−1 3 6 11]' b = -1 3 Numerical Analysis Using MATLAB® and Excel®. To distinguish between row and column vectors. We recall that the elements of a row vector are separated by spaces. and thus are called row vectors. 6. Third Edition Copyright © Orchard Publications 1−19 . a column vector can be written either as b=[−1. consisted of one row and multiple columns. 11] or as b=[−1 3 6 11]' MATLAB produces the same display with either format as shown below.2. They are explained in the following paragraphs. MATLAB uses the single quotation character (¢) to transpose a vector. Thus. and the element−by−element multiplication. and exponentiation. the elements of a column vector must be separated by semicolons. 3. b=[−1. and then transpose it into a column vector. it is called a column vector. Division and Exponentiation 111 Full Screen 211 212 221 222 212 221 223 211 223 224 222 224 221 223 122 Default 121 122 222 224 121 Figure 1. division. If an array has one column and multiple rows. is to write it first as a row vector.Multiplication. Possible subpot arrangements in MATLAB 1. the arrays [ a b c … ] . 6. such a those that contained the coefficients of polynomials. division. and exponentiation. In Section 1. division. An easier way to construct a column vector. and exponentiation. 3.

We observe that A is defined as a row vector whereas B is defined as a column vector. Then. B=[−2 6 −3 8 7]. 1. is performed with the matrix multiplication operator (*). A=[1 2 3 4 5]. as indicated by the transpose operator (′). let us suppose that both A and B are row vectors. MATLAB displays the following message: ??? Error using ==> * Inner matrix dimensions must agree. and we attempt to perform a row−by− row multiplication with the following MATLAB statements. B=[ −2 6 −3 8 7]'. Matrix Multiplication (multiplication of row by column vectors) Let A = [ a1 a2 a3 … an ] and B = [ b 1 b 2 b 3 … b n ]' be two vectors. multiplication of the row vector A by the column vector B . Third Edition Copyright © Orchard Publications . A*B % Observe transpose operator (‘) in B (B. that is. MATLAB expects 1−20 Numerical Analysis Using MATLAB® and Excel®. A∗ B = 1 × ( – 2 ) + 2 × 6 + 3 × ( – 3 ) + 4 × 8 + 5 × 7 = 68 and this is verified with the MATLAB script A=[1 2 3 4 5]. A*B = [ a 1 b 1 + a 2 b 2 + a 3 b 3 + … + a n b n ] = sin gle value For example.15) ans = 68 Now. Here. because we have used the matrix multiplication operator (*) in A*B. Here. if and A = [1 2 3 4 5] B = [ – 2 6 – 3 8 7 ]' the matrix multiplication A*B produces the single value 68.Chapter 1 Introduction to MATLAB 6 11 We will now define Matrix Multiplication and Element−by−Element multiplication. A*B % No transpose operator (‘) here When these statements are executed.

^) are used for element− by−element division and exponentiation. 2.Multiplication. the division (/) and exponentiation (^) operators. D=[−2 6 −3 8 7].) is never required with the plus (+) and minus (−) operators. whereas dot division (. as illustrated with the examples above. as the elements of C and D . Division and Exponentiation vector B to be a column vector. not a row vector. Here.16) This product is another row vector with the same number of elements. and warns us that we cannot perform this multiplication using the matrix multiplication operator (*). It recognizes that B is a row vector.∗ D = [ c 1 d 1 c2 d2 c3 d3 … cn dn ] (B. Third Edition Copyright © Orchard Publications 1−21 . and exponentiation (^) operators. Thus. There is no space between the dot and the multiplication symbol.*D % Vectors C and D must have % same number of elements % We observe that this is a dot multiplication ans = -2 12 -9 32 35 Similarly. As an example.) and the multiplication (*). This operator is defined below. are used for matrix division and exponentiation. we must perform this type of multiplication with a different operator. Note: A dot (. We must remember that no space is allowed between the dot (. multiplication of the row vector C by the row vector D is performed with the dot multiplication operator (. division ( /). Element−by−Element Multiplication (multiplication of a row vector by another row vector) Let C = [ c1 c2 c3 … cn ] and D = [ d1 d2 d3 … dn ] be two row vectors. Numerical Analysis Using MATLAB® and Excel®. C./) and dot exponentiation (.∗ D = 1 × ( – 2 ) 2 × 6 3 × ( – 3 ) 4 × 8 5 × 7 = – 2 12 – 9 32 35 Check with MATLAB: C=[1 2 3 4 5].*). let and C = [1 2 3 4 5] D = [ –2 6 –3 8 7 ] Dot multiplication of these two row vectors produce the following result. C. Accordingly. C.

the eps number.2 × 10 – 16 . ymin and ymax.13') Figure 1.8. The command axis([xmin xmax ymin ymax]) scales the current plot to the values specified by the arguments xmin.* cos(5 . say as – 3 ≤ t ≤ 3 . % Define t−axis in 0.* exp(−4 .01: 5.13 Write the MATLAB script that produces a simple plot for the waveform defined as y = f ( t ) = 3e –4 t 2 cos 5t – 2e –3 t t sin 2t + -----------t+1 (1.8 shows the plot for this example.y).* t)−2 . plot(t.Chapter 1 Introduction to MATLAB Example 1. This command must be placed after the plot command and must be repeated for each plot.* t) + t .13 Had we. title('Plot for Example 1. There are no commas between these four arguments. which is a number approximately equal to 2. The following example illustrates the use of the dot multiplication. Third Edition Copyright © Orchard Publications . and also MATLAB’s capability of 1−22 Numerical Analysis Using MATLAB® and Excel®. the axis([xmin xmax ymin ymax]) command.* t) . This is because the last term (the rational fraction) of the given expression.* sin(2 .13 0 1 2 t 3 4 5 Figure 1. in the example above. xlabel('t').^2 . ylabel('y=f(t)')./ (t+1). division. defined the time interval starting with a negative value equal to or less than – 1 . grid.* exp(−3 .17) in the 0 ≤ t ≤ 5 seconds interval. xmax. 6 4 y=f(t) 2 0 -2 Plot for Example 1. MATLAB would have displayed the following message: Warning: Divide by zero.01 increments y=3 . we use the special MATLAB function eps. is divided by zero when t = – 1 . Plot for Example 1. and exponentiation.* t) . Solution: The MATLAB script for this example is as follows: t=0: 0. It will be used with the next example. To avoid division by zero.

% Interval with 100 data points % add eps to avoid division by zero % upper left of four subplots % upper right of four subplots % lower left of four subplots % lower right of four subplots These subplots are shown in Figure 1. subplot(221).^ 2).3]). title('v=(sinx)^2/(cosx)^2').9.y). subplot(224).^ 2). v=y . z = cos 2x. w=y . 1 y=(sinx)2 1 z=(cosx)2 0.18) in the interval 0 ≤ x ≤ 2π using 100 data points. Third Edition Copyright © Orchard Publications 1−23 .2 400 v=(sinx)2/(cosx)2 200 0.14 Plot the functions y = sin 2x. 2*pi.1 0 0 2 4 6 0 0 2 4 6 Figure 1.v). subplot(223). z=(cos(x) .14 Numerical Analysis Using MATLAB® and Excel®. plot(x. plot(x. plot(x. title('z=(cosx)^2'). axis([0 2*pi 0 0. plot(x. axis([0 2*pi 0 1]).* z.w). Solution: The MATLAB script to produce the four subplots is as follows: x=linspace(0.z).9. w = sin 2x ⋅ cos 2x./ (z+eps). axis([0 2*pi 0 400]). Subplots for the functions of Example 1. v = sin 2x ⁄ cos 2x (1.5 0 0 2 2 4 2 6 0 0 2 4 6 w=(sinx) *(cosx) 0. Use the subplot command to display these functions on four windows on the same graph. Example 1. axis([0 2*pi 0 1]). title('w=(sinx)^2*(cosx)^2').5 0. y=(sin(x) .Multiplication. Division and Exponentiation displaying up to four windows of different plots. title('y=(sinx)^2'). subplot(222).100).

19) 1−24 Numerical Analysis Using MATLAB® and Excel®.15 b With the given values of resistance. Plot the impedance Z versus frequency ω in polar coordinates. the abs(z). Example 1.Chapter 1 Introduction to MATLAB The next example illustrates MATLAB’s capabilities with imaginary numbers. We will introduce the real(z) and imag(z) functions which display the real and imaginary parts of the complex quantity z = x + iy. b.10. where r is the magnitude. the impedance Z ab as a function of the radian frequency ω can be computed from the following expression. Plot Re { Z } (the real part of the impedance Z ) versus frequency ω . Solution: The MATLAB script below computes the real and imaginary parts of Z ab that is. % Define interval with one radian interval z=(10+(10 . 4 6 (1.1 H Z ab Figure 1.^5. and the angle(z) functions that compute the absolute value (magnitude) and phase angle of the complex quantity z = x + iy = r –θ . a 10 Ω 10 Ω 10 μF 0./ (w+eps)) . We will also use the polar(theta.^ 4 −j ./ (w+eps)))). theta is the angle in radians. and capacitance. c. inductance. and the round(n) function that rounds a number to its nearest integer.10.* 10 .* (0.* w −10. Plot Im { Z } (the imaginary part of the impedance Z ) versus frequency ω .1 . denoted as z . It also produces a polar plot (part c).^ 6 ./ (10 + j .1 w – 10 ⁄ w ) a.15 Consider the electric circuit of Figure 1. and plots these as two separate graphs (parts a & b). Third Edition Copyright © Orchard Publications . 10 – j ( 10 ⁄ w ) Z ab = Z = 10 + ------------------------------------------------------5 10 + j ( 0. w=0: 1: 2000.r) function that produces a plot in polar coordinates. Electric circuit for Example 1. for simplicity.

13 respectively. ylabel('Polar Plot of Z'). Third Edition Copyright © Orchard Publications 1−25 . grid. grid. and polar plots are shown in Figures 1.Multiplication. plot(w. The real.12. Plot for the real part of Z in Example 1.% Computes |Z| rndz=round(abs(z)). imaginary. Division and Exponentiation % % The first five statements (next two lines) compute and plot Re{z} real_part=real(z).% Angle is the first argument grid. xlabel('radian frequency w').rndz). 1200 1000 800 Real part of Z 600 400 200 0 0 200 400 600 800 1000 1200 radian frequency w 1400 1600 1800 2000 Figure 1.real_part). % The last six statements (next six lines) below produce the polar plot of z mag=abs(z). and 1. 1.11.% Rounds |Z| to read polar plot easier theta=angle(z). plot(w.11.imag_part). ylabel('Real part of Z'). ylabel('Imaginary part of Z'). xlabel('radian frequency w'). % % The next five statements (next two lines) compute and plot Im{z} imag_part=imag(z).% Computes the phase angle of impedance Z polar(theta.15 Numerical Analysis Using MATLAB® and Excel®.

1.9 Script and Function Files MATLAB recognizes two types of files: script files and function files.Chapter 1 Introduction to MATLAB 600 400 Imaginary part of Z 200 0 -200 -400 -600 0 200 400 600 800 1000 1200 radian frequency w 1400 1600 1800 2000 Figure 1.12. Generally.15 clearly illustrates how powerful.m extension. and flexible MATLAB is. Plot for the imaginary part of Z in Example 1.15 Example 1.15 90 120 150 Polar Plot of Z 1500 1000 60 30 500 180 0 210 240 270 300 330 Figure 1.13. Both types are referred to as m−files since both require the . Thus. Third Edition Copyright © Orchard Publications . make up a script file. Polar plot of Z in Example 1. a script file is one which was generated and saved as an m−file with an editor such as the MATLAB’s 1−26 Numerical Analysis Using MATLAB® and Excel®. fast. A script file consists of two or more built−in functions such as those we have discussed thus far. the script for each of the examples we discussed earlier. accurate.

5 Solution: We first plot this function to observe the approximate zeros. To save it. NaN (Not−a−Number) is not a function. maxima.x) tries to find a zero of a function of one variable.– 10 2 2 ( x – 0.m. We will use the following MATLAB functions with the next example. fplot(fcn. We use function files for repetitive tasks.01 ( x – 1. we choose New and click on M−File.04 in the interval – 1. Important: We must remember that we use roots(p) to find the roots of polynomials only.16 Find the zeros. The function name and file name must be the same. The string fcn must be the name of an m−file function or a string with variable x . from the File menu of the command window. The function fzero(f.^ 3 + cos(3 . such as those in Examples 1. A function file is a user−defined function using MATLAB. which we mentioned earlier. where f is a string containing the name of a real−valued function of a single real variable. followed by the output argument. ∞ ⁄ ∞ . or inability to produce a result as described on the next paragraph. it is MATLAB’s response to an undefined expression such as 0 ⁄ 0 . or returns NaN if the search fails. Using lims = [xmin xmax ymin ymax] also controls the y−axis limits. and returns that value. The first line of a function file must contain the word function. MATLAB searches for a value near a point where the function f changes sign.lims) − plots the function specified by the string fcn between the x−axis limits specified by lims = [xmin xmax].1 ) + 0. but the file name must have the extension .Script and Function Files Editor/Debugger. Example 1. maxima and minima of the function 1 1 f ( x ) = ----------------------------------------.+ ----------------------------------------.1 and 1. For example.m.2 ) + 0.* x) is a function file and must be saved. Third Edition Copyright © Orchard Publications 1−27 . and the input argument enclosed in parentheses. the function file consisting of the two lines below function y = myfunction(x) y=x . the equal sign ( = ).5 ≤ x ≤ 1.2. and minima using the following script: (1. This takes us to the Editor Window where we type these two lines and we save it as myfunction.20) Numerical Analysis Using MATLAB® and Excel®. We can avoid division by zero using the eps number.

1).5 1.14.5: 0.1)^2+0./ ((x−0.5])./ ((x−1. [−1.y) command as shown in Figure 1.16 using the plot command The roots (zeros) of this function appear to be in the neighborhood of x = – 0.01)−1/((x−1.15. and when the Editor Window appears.14. we define and save f(x) as the funczero01. Now. grid The plot is shown in Figure 1.5 0 0. To save this file.14. y min = – 34 . we choose New. Third Edition Copyright © Orchard Publications . we can use the fplot(fcn.^ 2 + 0.5 -1 -0.5 1 1.^ 2 + 0. approximately.m function m−file with the following script: function y=funczero01(x) % Finding the zeros of the function shown below y=1/((x−0. plot(x. from the File drop menu on the Command Window. 100 80 60 40 20 0 -20 -40 -1.1 where.lims) command to plot f ( x ) as follows: fplot('funczero01'.01: 1.y). Plot for Example 1. MATLAB appends the extension .14 which was obtained with the plot(x.5 Figure 1.Chapter 1 Introduction to MATLAB x=−1. this plot is identical to the plot of Figure 1.2).5. y=1. Next. The maximum occurs at approximately x = 0.2)^2+0.04) −10. approximately.2 where. As expected. y max = 90 .2 and x = 0.04)−10.3 . we type the script above and we save it as funczero01. grid This plot is shown in Figure 1. 1−28 Numerical Analysis Using MATLAB® and Excel®.01) −1.m to it. and the minimum occurs at approximately x = 1.

x) function to compute the roots of f ( x ) in Equation (1.. x1). −0. x2= fzero('funczero01'.16 using the fplot command We will use the fzero(f. The MATLAB script below will accomplish this.5 0 0. Plot for Example 1.x1. 0.3). we recall that the maxima or minima of a function y = f ( x ) can be found by setting the first derivative of a function equal to zero and solving for the independent variable x .5 Figure 1.04)−10.1)^2+0. x1= fzero('funczero01'.2).x2) and with this function we could compute both a minimum of some function f ( x ) or a maximum of f ( x ) since a maximum of f ( x ) is equal to a minimum of – f ( x ) . Thus.15.2)^2+0.4f \n'. fprintf('The roots (zeros) of this function are r1= %3.Script and Function Files 100 80 60 40 20 0 -20 -40 -1. zmin=diff(ymin) zmin = -1/((x-1/10)^2+1/100)^2*(2*x-1/5)+1/((x-6/5)^2+1/25)^2*(2*x-12/5) When the command Numerical Analysis Using MATLAB® and Excel®.4f'. This can be visualized by flipping the plot of a function f ( x ) upside−down.5 1 1. x2) MATLAB displays the following: The roots (zeros) of this function are r1= -0.20) more precisely. From elementary calculus. Third Edition Copyright © Orchard Publications 1−29 .5 -1 -0.. For this example we use the diff(x) function which produces the approximate derivative of a function. ymin=1/((x−0.3788 The earlier MATLAB versions included the function fmin(f. we use the following MATLAB script: syms x ymin zmin..01)−1/((x−1. This function is no longer used in MATLAB and thus we will compute the maxima and minima from the derivative of the given function. fprintf(' and r2= %3.1919 and r2= 0.

MATLAB displays a very long expression which when copied at the command prompt and executed.Chapter 1 Introduction to MATLAB solve(zmin) is executed.1). This is accomplished with the MATLAB script below.^2+0.2012. ymax=−(1/((x−0.01)−1/((x−1.04) −10 ymin = -34. ymin=1 / ((x−0. grid and the plot is shown in Figure 1. we substitute it into f ( x ) .0. Third Edition Copyright © Orchard Publications .2) ^ 2 + 0.2012 above is the value of x at which the function y has its minimum value as we observe also in the plot of Figure 1.6585 + 0.5.16.1) ^ 2 + 0. that is./((x−0.1812 We can find the maximum value from – f ( x ) whose plot is produced with the script x=−1. plot(x./((x−1.2)^2+0. To find the value of y corresponding to this value of x.01:1. x=1. 40 20 0 -20 -40 -60 -80 -100 -1.04)−10).2).3437i ans = 0.2012 The real value 1.1)^2+0.01)+1.5 0 0. produces the following: ans = 0.5 Figure 1.16 Next we compute the first derivative of – f ( x ) and we solve for x to find the value where the maximum of ymax occurs. Plot of – f ( x ) for Example 1.15.5 -1 -0. ymax=−1. zmax=diff(ymax) 1−30 Numerical Analysis Using MATLAB® and Excel®.5:0.5 1 1.6585 .^2+0.3437i ans = 1.01) −1 / ((x−1.ymax).16.04)+10. syms x ymax zmax.

1) ^ 2 + 0.10 Display Formats MATLAB displays the results on the screen in integer format without decimals if the result is an integer number. or in short floating point format with four decimals if it a fractional number.Display Formats zmax = 1/((x-1/10)^2+1/100)^2*(2*x-1/5)-1/((x-6/5)^2+1/25)^2*(2*x-12/5) solve(zmax) When the command solve(zmax) is executed.16.2000 1. x=0. All computations in MATLAB are done in double precision. Accordingly.2012 ans = 0. FORMAT may be used to switch between different output display formats as follows: Numerical Analysis Using MATLAB® and Excel®.0.3437i ans = 1.0999 From the values above we choose x = 0.15 and 1.3437i ans = 0.04) −10 ymax = 89.0999. The output format can changed with the format command. Third Edition Copyright © Orchard Publications 1−31 .2) ^ 2 + 0. % Using this value find the corresponding value of ymax ymax=1 / ((x−0.6585 .6585 + 0. we execute the following script to obtain the value of ymin . The available formats can be displayed with the help format command as follows: help format FORMAT Set output format. MATLAB performs all computations with accuracy up to 16 decimal places.01) −1 / ((x−1. produces the following: ans = 0.0999 which is consistent with the plots of Figures 1. The format displayed has nothing to do with the accuracy in the computations. MATLAB displays a very long expression which when copied at the command prompt and executed.

SHORT G Best of fixed or floating point format with 5 digits. FORMAT LONG G Best of fixed or floating point format with 15 digits. negative and zero elements. Spacing: FORMAT COMPACT Suppress extra line-feeds. Imaginary parts are ignored.33333333333334 16 digits format short e 3. FORMAT HEX Hexadecimal format. LONG Scaled fixed point format with 15 digits. format short 33.and blank are printed for positive. SHORT Scaled fixed point format with 5 digits.3335 Four decimal digits (default) format long 33. Some examples with different format displays age given below.3333e+01 Four decimal digits plus exponent format short g 33. FORMAT RAT Approximation by ratio of small integers. FORMAT BANK Fixed format for dollars and cents. FORMAT + The symbols +.333 Better of format short or format short e format bank 33. FORMAT LOOSE Puts the extra line-feeds back in. Same as SHORT.Chapter 1 Introduction to MATLAB FORMAT FORMAT FORMAT FORMAT FORMAT FORMAT Default. Third Edition Copyright © Orchard Publications . SHORT E Floating point format with 5 digits.33 two decimal digits format + only + or − or zero are printed format rat 100/3 rational approximation 1−32 Numerical Analysis Using MATLAB® and Excel®. . LONG E Floating point format with 15 digits.

• For computations involving complex numbers we can use either i . the command help matlab\iofun will display input/output information. The elements a i of this vector are the coefficients of the polynomial in descending order. a polynomial is expressed as a row vector of the form [ a n a n – 1 a 2 a 1 a 0 ] . • The polyval(p. • We type quit or exit when we are done and want to leave MATLAB.Summary 1. Third Edition Copyright © Orchard Publications 1−33 . • The conv(a. variables. • We find the roots of any polynomial with the roots(p) function where p is a row vector containing the polynomial coefficients in descending order. • We use the clear command if we want to clear all previous values.r]=deconv(c. • In MATLAB. • The clc command clears the screen but MATLAB still remembers all values. we click on the Close button. • The polyder(p) function produces the coefficients of the derivative of a polynomial p. • We can compute the coefficients of a polynomial from a given set of roots with the poly(r) function where r is a row vector containing the roots.x) function evaluates a polynomial p ( x ) at some specified value of the independent variable x . and help matlab graphics will display help on graphics. A comment can be typed on the same line as the function or command or as a separate line. Numerical Analysis Using MATLAB® and Excel®. and equations without exiting. variables and equations which we have already used. • We can write MATLAB statements in one line if we separate them by commas or semicolons. or j to denote the imaginary part of the complex number. we type demo and we see the different topics. • The [q.d) function divides polynomial c by polynomial d and displays the quotient q and remainder r. • All text after the % (percent) symbol is interpreted by MATLAB as a comment line and thus it is ignored during the execution of a program. To access it. • The MATLAB Demos menu displays MATLAB’s capabilities. Whenever we want to return to the command window. For example. We must include terms whose coefficients are zero.b) function multiplies the polynomials a and b. Commas will display the results whereas semicolons will suppress the display.11 Summary • We can get help with MATLAB topics by typing help followed by any topic available.

whereas the common logarithm is expressed as log10(x). Normally.y) to make two−dimensional plots. Likewise. then pressing <enter> to start a new line. Third Edition Copyright © Orchard Publications . the semilogy(x. and y is the vertical axis (ordinate).= ------------------------------------------------------------------------------------------------------------------------------------------m m–1 m–2 Den ( x ) am x + am – 1 x + am – 2 x + … + a1 x + a0 where some of the terms in the numerator and/or denominator may be zero. The command text(x. last_value. xlabel(‘string’). we express the numerator and denominator of a rational function as a combination of linear and quadratic factors. except that the y −axis is represented as a log scale. An alternate command uses the colon notation and has the format x=first: increment: last. box. This format specifies the increments between points but not the number of data points. title(‘string’).y) command is similar to the plot(x. • The ratio of any two values of the same quantity. number_of_values) specifies the number of data points but not the increments between data points. • We can make a two−dimensional plot more presentable with the commands grid. it can be continued to the next line by typing three or more periods. typically power. • The semilogx(x. we can also use the zlabel(‘string’) command.y) command. • The function log(x) in MATLAB is the natural logarithm.y) command. and the x −axis as a linear scale. the logarithm to the base 2 is expressed as log2(x). that is. The loglog(x.’string’) is similar to gtext(‘string’). P out dB = 10 log --------P in • The command gtext(‘string’) switches to the current Figure Window. as bn x + bn – 1 x + bn – 2 x + … + b1 x + b0 ) R ( x ) = Num ( x . or a row vector is too long to fit in one line. • We use the MATLAB command plot(x. and ylabel(‘string’). • The command linspace(first_value. and the y −axis as a linear scale.y. it places a label on a plot in some specific location specified by x and y. n n–1 n–2 1−34 Numerical Analysis Using MATLAB® and Excel®.Chapter 1 Introduction to MATLAB • Rational Polynomials are those which can be expressed in ratio form. and displays a cross−hair which can be moved around with the mouse. is normally expressed in decibels (dB) and by definition.y) command is similar to the plot(x. Likewise. This command plots y versus x where x is the horizontal axis (abscissa). For a three−dimensional plot. • If a statement. except that the x −axis is represented as a log scale.y) command uses logarithmic scales for both axes. and string is the label which we want to place at that location. and continue to enter data.

y.z) commands. We can also use the mesh(x. y ) . we must first generate the X and Y matrices which consist of repeated rows and columns over the range of the variables x and y . Also.2 × 10 – 16 . the division (/) and exponentiation (^) operators.^) are used for element−by−element division and exponentiation. y . • In a two−dimensional plot. There are no commas between these four arguments. in a three−dimensional plot we can set the limits of all three axes with the axis([xmin xmax ymin ymax zmin zmax]) command. there is no default marker. and z are three vectors of the same length.p). say z = f ( x. are used for matrix division and exponentiation.n).y.y. This command must be placed after the plot command and must be repeated for each plot. y ( i ). It must be placed after the plot(x. and z . and y corresponds to the rows of Z . or on the same line without first executing the plot command. where x. xmax. • MATLAB can display up to four windows of different plots on the Figure window using the command subplot(m. whereas dot division (. Numerical Analysis Using MATLAB® and Excel®. We observe that x corresponds to the columns of Z . Another command. • With MATLAB. contour(Z. These must be defined as length ( x ) = n and length ( y ) = m where [ m. n ] = size ( Z ) . y.z.Y]=meshgrid(x.y) or plot3(x. we can set the limits of the x − and y −axes with the axis([xmin xmax ymin ymax]) command. Third Edition Copyright © Orchard Publications 1−35 . Similarly.y.n. • To avoid division by zero. Z ( i. we use the special MATLAB function eps. whereas element−by−element multiplication is performed with the dot multiplication operator (. j ) } .y) function which creates the matrix X whose rows are copies of the vector x. no markers are drawn unless they are selected. and the matrix Y whose columns are copies of the vector y. This must be done for each plot. • The command axis([xmin xmax ymin ymax]) scales the current plot to the values specified by the arguments xmin. We can generate the matrices X and Y with the [X. • The mesh(x. ymin and ymax.z) command displays a three−dimensional plot. In this case.z) command plots a line in 3−space through the points whose coordinates are the elements of x . The default line is the solid line. • The plot3(x. draws contour lines for n levels. Likewise. the vertices of the mesh lines are the triples { x ( j ).y.Summary • MATLAB has no default color.’string’) command will place string beginning at the co−ordinate ( x.*). z ) on the plot. it starts with blue and cycles through seven colors. y.z) command with two vector arguments. which is a number approximately equal to 2. matrix multiplication (multiplication of row by column vectors) is performed with the matrix multiplication operator (*). The three − dimensional text(x./) and dot exponentiation (. To produce a mesh plot of a function of two variables. This command divides the window into an m × n matrix of plotting areas and chooses the pth area to be active.

the values will be displayed and printed in scientific notation format. A script file consists of two or more built−in functions. and if %e is used. a script file is one which was generated and saved as an m−file with an editor such as the MATLAB’s Editor/ Debugger. The format displayed has nothing to do with the accuracy in the computations.Chapter 1 Introduction to MATLAB • The real(z) and imag(z) functions display the real and imaginary parts of the complex quantity z = x + iy. The first line of a function file must contain the word function. It uses specifiers to indicate where and in which format the values would be displayed and printed. Using lims = [xmin xmax ymin ymax] also controls the y −axis limits. and theta is the angle in radians. • MATLAB recognizes two types of files: script files and function files. MATLAB performs all computations with accuracy up to 16 decimal places. the values will be displayed and printed in fixed decimal format. or in short floating point format with four decimals if it a fractional number. if %f is used. and the input argument enclosed in parentheses. • The MATLAB fprintf(format. The string fcn must be the name of an m−file function or a string with variable x . 1−36 Numerical Analysis Using MATLAB® and Excel®. but the file name must have the extension . • The MATLAB fmin(f. With these commands only the real part of each parameter is processed.lims) command plots the function specified by the string fcn between the x −axis limits specified by lims = [xmin xmax]. followed by the output argument. Generally. Both types are referred to as m−files.x2) function minimizes a function of one variable.array) command used above displays and prints both text and arrays. The string f contains the name of the function to be minimized. Thus.m. • MATLAB displays the results on the screen in integer format without decimals if the result is an integer number. Third Edition Copyright © Orchard Publications . The polar(theta. • The MATLAB fplot(fcn. and the angle(z) functions compute the absolute value (magnitude) and phase angle of the complex quantity z = x + iy = r –θ . The function name and file name must be the same. A function file is a user−defined function using MATLAB. the equal sign ( = ).x1.r) function produces a plot in polar coordinates. where r is the magnitude. It attempts to return a value of x where f ( x ) is minimum in the interval x 1 < x < x 2 . and the abs(z). We use function files for repetitive tasks.

3132 – 0.5 1200 102.8 1600 94.9 Plot V C (in dB scale) versus ω (in common log scale) and label the axes appropriately. Use MATLAB to evaluate the polynomials below at the specified values.4 700 103. Use MATLAB to derive the polynomials having the following roots: a. p ( y ) = y + 7y + 19y + 25y + 16y + 4 2.7 800 104. In the electric circuit below.3 1500 96.000 and three roots at x = – 3.9 1100 103. Third Edition Copyright © Orchard Publications 1−37 .3132 5 4 3 2 3 2 b. Numerical Analysis Using MATLAB® and Excel®. the applied voltage V S was kept constant and the voltage V C across the capacitor was measured and recorded at several frequencies as shown on the table below. p ( x ) = x + 8x + 10x + 4 at x = 1. a.8 600 98.75 4.Exercises 1. p ( y ) = y + 7y + 19y + 25y + 16y + 4 at y = – 3.5 1000 104.9 900 105.7146 – j 0.9 1400 98.5708 – 0. R1 R2 VS C L VC 5 4 3 2 3 2 Capacitor voltage versus radian frequency ω VC ω VC 500 88. Two roots at x = – 2.25 b. p ( x ) = x + 8x + 10x + 4 b.7146 + j0.0 1300 100. – 6.000 3. Use MATLAB to compute the roots of the following polynomials: a.12 Exercises 1.

review this chapter and try again. You must. Third Edition Copyright © Orchard Publications . 1−38 Numerical Analysis Using MATLAB® and Excel®. You should follow this practice with the rest of the exercises of this book. Refer to the solutions as a last resort and rework those exercises at a later date. For the exercises that you are uncertain.13 Solutions to End−of−Chapter Exercises Dear Reader: The remaining pages on this chapter contain the solutions to the exercises. make an honest effort to find the solutions to the exercises without first looking at the solutions that follow.Chapter 1 Introduction to MATLAB 1. It is recommended that first you go through and work out those you feel that you know. for your benefit.

value=polyval(Pw.25) value = 30. roots(Py) ans = -2. a. poly_r1=poly(r1) poly_r1 = 3 1.7146+0.0000 2 8.0000 . −3.0000 -1. Px=[1 8 10 4]. r2=[−2 −2 −3 −3 −3]. value=polyval(Pv. Pw=[1 7 19 25 16 4].0000 -2. r1=[−6.0000 + 0.7146 + 0.9997 4. ans = -6.0000 p ( x ) = x + 8x + 10x + 4 b.0000i 2.0000 -1.3132i -0. Pv=[1 8 10 4].6904 Numerical Analysis Using MATLAB® and Excel®.0.3132j].0. a. Third Edition Copyright © Orchard Publications 1−39 .75) value = -63.3132j −0.7146 .9531 b.5708 −0.7146−0. roots(Px) b.5708 -0.0000i -1. poly_r2=poly(r2) poly_r2 = 1 5 13 4 67 3 171 2 216 108 p ( z ) = z + 13z + 67z + 171z + 216z + 108 3.3132i Py=[1 7 19 25 16 4]. 1. a.Solutions to End−of−Chapter Exercises 1.0000 9.

5 2 10 Magnitude of Vc vs.9].4 100.3 104.. dB=20*log10(Vc). title('Magnitude of Vc vs.9 98.5 40 |Vc| in volts 39.8 102. Third Edition Copyright © Orchard Publications .5 39 38.9 105.5 103 104. grid. xlabel('w in rads/sec').5 94.Chapter 1 Introduction to MATLAB 4.8 103.. semilogx(w. w=[5 6 7 8 9 10 11 12 13 14 15 16]*100.7 98.. w 10 w in rads/sec 3 10 4 1−40 Numerical Analysis Using MATLAB® and Excel®. ylabel('|Vc| in volts') 40.9 96.dB). w'). Vc=[88.

Newton’s method for approximating real roots of a function We assume that the slope is neither zero nor infinite. f ( x 2 ) ] = ( x 2.Chapter 2 Root Approximations T his chapter is an introduction to Newton’s and bisection methods for approximating roots of linear and non−linear equations.2) and in general. Since this point [ x 2. f ( x 1 ) } x ( x 2.1 Newton’s Method for Root Approximation Newton’s (or Newton−Raphson) method can be used to approximate the roots of any linear or non−linear equation of any degree.1.1) The slope crosses the x – axis at x = x 2 and y = 0 . This is an iterative (repetitive procedure) method and it is derived with the aid of Figure 2. f ( x 1 ) } { x 1. f ( xn ) x n + 1 = x n – -------------f ' ( xn ) (2. Third Edition Copyright © Orchard Publications 2−1 . 0 ) Figure 2. the slope (first derivative) at x = x 1 is y – f ( x1 ) f ' ( x 1 ) = -------------------x – x1 y – f ( x1 ) = f ' ( x1 ) ( x – x 1 ) (2. it satisfies (2. Several examples are presented to illustrate practical solutions using MATLAB and Excel spreadsheets. Then. y y = f(x ) • • Tangent line (slope) to the curve y = f ( x ) at point { x 1. 0 – f ( x1 ) = f ' ( x1 ) ( x2 – x1 ) f ( x1 ) x 2 = x 1 – -------------f ' ( x1 ) (2.3) Numerical Analysis Using MATLAB® and Excel®. By substitution.1.1). 2. 0 ) lies on the slope line.

optional subtype specifier. It formats the data in the real part of matrix A (and in any additional matrix arguments). Knowing the polynomial p and the first approximation x 0 . and formfeed characters respectively. we plot the curve of (2.\b. G.x0) We’ve used the fprintf command in Chapter 1.x) function evaluates the polynomial p at some value x. 4. We recall that the polyder(p) function displays the row vector whose values are the coefficients of the first derivative of the polynomial p. x.\r. let us review it again. optional width and precision fields. under control of the specified format string. X. The special formats \n. In all cases. x=linspace(−4. optional flags.^ 2 − 5. Use \\ to produce a backslash character and %% to produce the percent character. tab. we will use it many more times. The following two lines of script will display the graph of the given equation in the interval – 4 ≤ x ≤ 4 . carriage return. These specifications involve the character %. q=polyder(p) x1=x0−polyval(p. and waits for an input from the user. input(‘string’): It displays the text string.1 Use Newton’s method to approximate the positive root of to four decimal places. u.\t. c. and writes it to the file associated with file identifier fid and contains C language conversion specifications. we must start with a reasonable approximation of the root value. This can be done easily with a simple plot using MATLAB or a spreadsheet. The polyval(p. Solution: As a first step. See the Language Reference Guide or a C manual for complete details. we can use the following script for the next approximation x 1 . We will now introduce some new MATLAB functions and review some which are discussed in Chapter 1. Therefore. E. and conversion characters d. i.4) the text in single quotation marks. Therefore. e. y=x . o. 100). We start with MATLAB and will discuss the steps for using a spreadsheet afterwards. f. plot(x. backspace.4) to find out where it crosses the x – axis . g. To apply Newton’s method.x0)/polyval(q. this can best be done by plotting f ( x ) versus x with the familiar statements below. we can compute the next iteration for approximating a root with Newton’s method using these functions. We must enclose f ( x ) = x2 – 5 (2.\f can be used to produce linefeed. and s. grid % Specifies 100 values between -4 and 4 % The dot exponentiation is a must 2−2 Numerical Analysis Using MATLAB® and Excel®. The following description was extracted from the help fprintf function.Chapter 2 Root Approximations Example 2.y). Third Edition Copyright © Orchard Publications .

x0). q=polyder(p).25 ) f ' ( x1 ) (2. we expect this value to be a value between 2 and 3 . The plot is shown in Figure 2.5) and (2.2.6f.xxxxxx. Plot for the curve of Example 2.= 2.= 2. and then redefine the interval. where the interval may not be so obvious.= 2 – -----------------.0625 = 2. we can choose a larger interval. with 9 digits where 6 of these digits % are to the right of the decimal point such as xxx. Third Edition Copyright © Orchard Publications 2−3 .25 ) – 5 = 2. x0=input('Enter starting value: '). 15 10 5 0 -5 -4 -2 0 2 4 Figure 2. the curve shows one crossing between x = 2 and x = 3 ..Newton’s Method for Root Approximation We chose this interval because the given equation asks for the square root of 5 .25 f ' ( x0 ) 2(2) 4 (2.x0)/polyval(q.25 – 0. % Inserts a blank line % % The next function displays the value of x1 in decimal format as indicated % by the specifier %9.6).5) The second approximation yields 2 f ( x1 ) --------------------------------------x 2 = x 1 – -------------. fprintf('\n'). % Calculates the derivative of p(x) x1=x0−polyval(p. % Approximation of a root of a polynomial function p(x) % Do not forget to enclose the coefficients in brackets [ ] p=input('Enter coefficients of p(x) in descending order: ').1 As expected. and Numerical Analysis Using MATLAB® and Excel®.= 2 – ---------.2. i.2361 4. For other functions. and we compute the next value x 1 as 2 f ( x0 ) ( –1 ) (2) – 5 x 1 = x 0 – -------------.6) We will use the following MATLAB script to verify (2.25 – ( 2.5 2 ( 2.e. observe the x – axis crossings. so we take x 0 = 2 as our first approximation.

The first line of a function file must contain the word function followed by the output argument.Chapter 2 Root Approximations % \n prints a blank line before printing x1 fprintf('The next approximation is: %9. approximation \n'). the equal sign (=).* x) is a function file and must be saved as myfunction.25 The next approximation is: 2. In Chapter 1 we discussed script files and function files. whose general form is while expression commands . x1) fprintf('\n')...6f \n'... % Inserts another blank line % fprintf('Rerun the program using this value as your next.m We will use the while end loop. We will also be using the following commands: 2−4 Numerical Analysis Using MATLAB® and Excel®.^ 3 + cos(3 . the function file consisting of the two lines below function y = myfunction(x) y=x . Enter coefficients of P(x) in descending order: [1 0 −5] Enter starting value: 2 The next approximation is: 2. in the second line are executed as long as all elements in expression of the first line are true... We use function files for repetitive tasks. The function name and file name must be the same but the file name must have the extension . end where the commands .m. Third Edition Copyright © Orchard Publications .6). and the input argument enclosed in parentheses. The following lines show MATLAB’s inquiries and our responses (inputs) for the first two approximations..236111 We observe that this approximation is in close agreement with (2. We recall that a function file is a user− defined function using MATLAB. For example.250000 Rerun the program using this value as your next approximation Enter polynomial coefficients in descending order: [1 0 −5] Enter starting value: 2.

Next. we choose New and click on M−File. We generate the plot with the script below. the text is displayed. Solution: As a first step.^ 2 + 4 . and disp(‘volts’) displays volts. from the File menu of the command window. 100).3f specifies a fixed format of 4 digits where 3 of these digits are allocated to the fractional part. If x is a string. sprintf('%d'. y=x . Example 2. x=linspace(−pi.Newton’s Method for Root Approximation disp(x): Displays the array x without printing the array name. For example. if v = 12 . Third Edition Copyright © Orchard Publications 2−5 . sprintf(format.* x + 3 + sin(x) − x .* x + 3 + sin(x) − x .m.* cos(x).* cos(x).3f'. we generate the function funcnewt01 and we save it as an m−file.7) to four decimal places using Newton’s method. disp(v) displays 12.142 where the format script %4. sprintf('%4. we sketch the curve to find out where the curve crosses the x – axis . grid The plot is shown in Figure 2. This takes us to the Editor Window where we type the following three lines and we save it as funcnewt01. To save it. For example. function y=funcnewt01(x) % Approximating roots with Newton's method y=x .A): Formats the data in the real part of matrix A under control of the specified format string.2 Approximate one real root of the non−linear equation f ( x ) = x + 4x + 3 + sin x – x cos x 2 (2. pi.y).pi) ans = 3.^ 2 + 4 . plot(x. Likewise. The plot shows that one real root is approximately at x = – 1 .round(pi)) ans = 3 where the format script %d specifies an integer. Numerical Analysis Using MATLAB® and Excel®.3. so we will use this value as our first approximation.

* x + 4 + x . and to introduce the diff(s) function. x = xnext. This takes us to the Editor Window where we type these two lines and we save it as funcnewt02. x = input('Enter starting value: ').Chapter 2 Root Approximations 30 20 10 0 -10 -4 -3 -2 -1 0 1 2 3 4 Figure 2.3. xnext = x−fx/fprimex. however. The syms function is used to define one or more symbolic expressions. and we save it as m−file. but correct % answer will be displayed if they are used. we generate the function funcnewt02.m. we choose New and click on M−File. function y=funcnewt02(x) % Finding roots by Newton's method % The following is the first derivative of the function defined as funcnewt02 y=2 . To save it. Third Edition Copyright © Orchard Publications .* sin(x). This function performs differentiation of symbolic expressions. Our script for finding the next approximation with Newton’s method follows. from the File menu of the command window. 2−6 Numerical Analysis Using MATLAB® and Excel®. fprimex = funcnewt02(x). fx = funcnewt01(x). syms x y = x^2+4*x+3+sin(x)−x*cos(x).2 We also need the first derivative of y. This is y' = 2x + 4 + x sin x The computation of the derivative for this example was a simple task. just as a check. y1=diff(y) % Dot operations are not necessary with % symbolic expressions. Plot for the equation of Example 2. we can let MATLAB do the differentiation. % Find the derivative of y y1 = 2*x+4+x*sin(x) Now.

1=yes)'). Third Edition Copyright © Orchard Publications 2−7 .6f \n'. fprimex=funcnewt02(x). 2.1=yes) <enter> We can also use the fzero(f. and Quattro can also be used. x)) MATLAB produces the following result with – 1 as a starting value. all spreadsheet commands and formulas that we will be using. xnext=x−fx/fprimex.894010 Next approximation? (<enter>=no. disp(sprintf('First approximation is x = %9. fprimex = funcnewt02(x). disp(sprintf('%9. Henceforth. As we recall. we will go through several examples to illustrate the procedure of using a spreadsheet such as Excel* to approximate the real roots of linear and non−linear equations. x)) end. We recall that there is a standard procedure for finding the roots of a cubic equation. This function tries to find a zero of a function of one variable. Enter starting value: −1 First approximation is: -0.895225 Next approximation? (<enter>=no. MATLAB searches for a value near a point where the function f changes sign and returns that value. A cubic equation of the form y + py + qy + r = 0 3 2 (2.9) can be reduced to the simpler form x + ax + b = 0 3 where * We will illustrate our examples with Excel. will be those of Excel.6f \n'. The string f contains the name of a real−valued function of a single real variable.Approximations with Spreadsheets fx = funcnewt01(x). x=xnext. fx=funcnewt01(x). disp(sprintf('Next approximation is x = %9. Numerical Analysis Using MATLAB® and Excel®.6f \n'.2 Approximations with Spreadsheets In this section. x)) while input('Next approximation? (<enter>=no.8) (2. It was introduced in Chapter 1. it is included here for convenience.1=yes)1 -0. or returns NaN if the search fails.x) function. although others such as Lotus 1−2−3.

Also. unless we know that the roots are all real. However.12) (2. Example 2.10) For the solution it is convenient to let 3 A = a –b b ----. y = f ( x ) = x – 7x + 16x – 12 3 2 (2. C11.– 3 2 2 A+B A–B x 3 = – ------------.13) If the coefficients p . and r are real.> 0 one root will be real and the other two complex conjugates 4 27 a b If ---.14) 2−8 Numerical Analysis Using MATLAB® and Excel®. the values of x for which the cubic equation of (2.3 Compute the roots of the polynomial using Excel.+ ----4 27 2 2 3 a –b b B = – ----.– 3 2 2 (2. q .11) is equal to zero are x1 = A + B A+B A–B x 2 = – ------------. Then. then b.< 0 the roots will be real and unequal 4 27 a b If ---.( 2p – 9pq + 27r ) 27 (2.+ ---. Thus B3.– ------------.+ ----4 27 2 3 2 3 (2. and so on. and so on will be understood to be cell B3.+ ----. Therefore. we can use a spreadsheet to find the real root since in any cubic equation there is at least one real root.11) Then.+ ------------.( 3q – p ) 3 1 3 b = ----.a If ---. we can plot y versus x to observe the values of x that make f ( x ) = 0 . This procedure is illustrated with the examples that follow. after an entry has been made. For real roots.+ ----. Third Edition Copyright © Orchard Publications .+ ----. it will be understood that the <enter> key was pressed.= 0 there will be three real roots with at least two equal 4 27 2 3 2 3 2 3 While MATLAB handles complex numbers very well. cell C11. spreadsheets do not. Note: In our subsequent discussion we will omit the word cell and the key <enter>.+ ---.Chapter 2 Root Approximations p x = y + -3 1 2 a = -. we can use a spreadsheet to define a range of x values with small increments and compute the corresponding values of y = f ( x ) . we should not use a spreadsheet to find the roots of a cubic equation by substitution in the above formulas.

this is called the fill handle. We click on Edit. * To use this feature. Alternately. then we release the mouse button. We type 0. we choose Options and we click on the Edit tab. and we click on Copy. we select B1. all numbers that we will type in Column A will be fixed numbers with two decimal places. and the numbers in Column B will be fixed with three decimal places. we can make it visible by performing the sequential steps Tools>Options.00 Next. We select the range B3:B102 with the mouse.05 increments up to 5. and to make all values look uniform. that is. we type = A2^3-7*A2^2 + 16*A2-2 where A2 represents the first value of x = 0. With B2 still selected. Next. We observe that the entire column is now highlighted. we drag it down to A102. We will enter more values in column A. We observe that after pressing the <enter> key. To continue. we highlight cells A2 and A3. For this example. we want to copy this formula to the range B3:B102 (the colon : means B3 through B102). We observe that this number is displayed exactly as it was typed. we type the equation formula with the = sign in front of it. and we observe that this range is now highlighted. We observe that. that is. the next cell moves downwards to A2.00 in increments of 0. In B2.00 . select the Edit tab. We select a cell by moving the thick hollow white cross pointer to the desired cell and we click.05 in A3. If it does not appear on the spreadsheet. Next. this becomes the next selected cell. In an Excel worksheet. we click on Edit on the main taskbar. we click and holding the mouse left button down. as we drag the fill handle.05. that is. A2 will have a white background but A3 will have a black background. and place a check mark on the Drag and Drop setting. we release the mouse button. we can use the Copy and Paste icons of the taskbar. from the Tools drop menu of the Menu bar. We will now use the AutoFill* feature to fill−in the other values of x in Column A. We click. and we type f(x). hold down the mouse button. then on Paste and we observe that this range is now filled with the values of f ( x ) . and we release the mouse button. Third Edition Copyright © Orchard Publications 2−9 .000 .Approximations with Spreadsheets Solution: We start with a blank worksheet. We repeat these steps for Column B and we choose 3 decimal places. We observe that B2 displays the value – 12. We observe that this value is displayed just as 0. the background on the monitor has changed from white to black. Next. We observe that on the lower right corner of A3. Numerical Analysis Using MATLAB® and Excel®. there is a small black square. This is the value of f ( x ) when x = 0. a pop−up note shows the cell entry for the last value in the range. without decimals. Then. a selected cell is surrounded by a heavy border. Column A now contains 100 values of x from 0. we first select A1 and we type x.00 to 5.00. We will use values in 0. Next. we click on letter A on top of column A. we select A2. we point the mouse to the fill handle and we observe that the mouse pointer appears as a small cross. When properly done. we drag the mouse down to A3 so that both these two cells are highlighted. we type 0. We click on the Fixed Decimal check box to place a check mark and we choose 2 as the number of decimal places.00 in A2.

422 0.0 Major unit: 1. The Chart menu appears in two places. on the Format axis menu. A chart similar to the one on Figure 2. we choose the one on top of the right side (the smooth curves without connection points). 3. From the View menu. and Finish. the roots of f ( x ) . Then. Third Edition Copyright © Orchard Publications . on the main taskbar and below it in a box where next to it is another small box with the hand icon.05 -11. Then. Next.803 0.4 appears. only when the graph box is selected.55 -5.469 0. x f(x) 0.217 0. we click on Next.4. we click on Toolbars. we select Value (X) axis.30 -7. We click on the Patterns tab to select it. Note: The Chart menu appears on the main taskbar and on the box below it. and on the Chart type column we click on XY (Scatter). We click anywhere inside the graph box. when it is enclosed in black square handles. We click on OK to return to the graph.215 0. and to see more precisely the x – axis crossing(s). Next. and we delete it by pressing the Delete key. 2.625 0. This is done with the following steps: 1. that is. We click on the Font tab.50 -5.754 0. Size 9.151 f(x) 20 15 10 5 0 -5 -10 -15 0 1 2 3 4 5 6 Figure 2.45 -6.40 -6. we select Number from the Category column.15 -9. that is.0 Minor unit: 0. From the Chart menu box we select Value (Y) axis and we click on the small box next to it (the 2−10 Numerical Analysis Using MATLAB® and Excel®. and we type 0 in the Decimal places box.3. We will modify this plot to make it more presentable. We click on the Series 1 box to select it.35 -7. Regular style.00 -12.20 -9. From the displayed charts. and we click on Low on the Tick mark labels (lower right box). and we click on the small box next to it (the box with the hand icon).126 0.Chapter 2 Root Approximations To plot f ( x ) versus x .072 0. we see it enclosed in six black square handles. and we place a check mark on Chart. we click on the Scale tab and we make the following entries: Minimum: 0.656 0. we click on the Chart Wizard icon of the Standard Toolbar. Plot of the equation of Example 2.000 0. Then.5 We click on the Number tab.25 -8. From the Chart menu box (below the main taskbar).10 -10. we select any font.0 Maximum: 5.

The plot area on the chart now appears on white background. Then. we click on the Scale tab. we select Plot Area and we observe that the gray background of the plot area is surrounded by black square handles. say poly01. From the Chart menu box below the main task bar. therefore. we select Chart Area from the Chart menu. and the third root is x = 3 .5 where we have shown partial lists of x and f ( x ) .xls where. We click on Gridlines. The given polynomial has two roots at x = 2 .05 We click on the Number tab. Now. and on the Area side of the Patterns tab.Approximations with Spreadsheets box with the hand icon). We click on the Patterns tab. we will change the background of the plot area from gray to white.0 Major unit: 0. Series 1 appears on the Chart menu box. 7. Finally. we click on the Titles tab and we make the following entries: Chart title: f(x) = the given equation (or whatever we wish) Value (X) axis: x (or whatever we wish) Value (Y) axis: y=f(x) (or whatever we wish) 5. We click on the box next to it (the box with the hand icon). We click on the small box next to it. 6. Regular style.25 Minor unit: 0. Third Edition Copyright © Orchard Publications 2−11 . 4. and we select 2 in the Decimal places box. and on the Chart Options. it is highly recommended that this file is saved with any name. and we click on Outside on the Major tick mark type (upper right box). select any font. We click on the Font tab. Size 9. The plot now resembles the one shown in Figure 2. we place check marks on Major gridlines of both Value (X) axis and Value (Y) axis. To make the line of the curve f ( x ) thicker. and on the Patterns tab we place a check mark on the Round corners box. Numerical Analysis Using MATLAB® and Excel®. we select Number from the Category column.0 Maximum: 1. and we make the following entries: Minimum: −1. we click at any point near it and we observe that several black square handles appear along the curve. we click on the white square which is immediately below the gray box.xls is the default extension for file names saved in Excel. From the Weight selections we select the first of the thick lines. We will follow the same procedure for generating the graphs of the other examples which follow. We click on Chart on the main taskbar. and on the Patterns tab. On the Format axis menu. We click on OK to return to the graph. to change Chart Area square corners to round.

217 0.10 -10.121 f(x) =0 at x=2 (double root) and at x=3 Figure 2.55 -5.422 0.xls.05 -0.625 0.151 0.00 0.754 0.90 -0.072 0.215 0.704 0.009 3. Modified plot of the equation of Example 2.00 -2.xls.95 -0.803 0.Chapter 2 Root Approximations x f(x) 0.25 -0.85 -2.90 -2. that is. we choose the Save as option.469 0.4 Find a real root of the polynomial using Excel. and save it with another name such as poly02.656 0.10 0.05 0. This is done by first opening the file poly01.60 -4. the spreadsheet of the previous example still exists as poly01.011 2. we perform the following steps: 1. Third Edition Copyright © Orchard Publications . When this is done.05 -11.90 -0.10 -0.168 0.15) 2−12 Numerical Analysis Using MATLAB® and Excel®. we save it as poly02.516 0.3.00 -0.126 0.12 1.15 -9. we expect that this polynomial will have at least one real root.50 -0.000 2.25 0.002 3.xls.70 -3.45 -6.75 0.5.95 -0.260 1.00 0.75 -3. then.65 -4.045 Roots 2. For this example. and since we know that complex roots occur in conjugate pairs.887 0. Example 2.00 0.7x2 + 16x .003 2.081 1.30 -7.50 -5. and from the File drop down menu.055 2. Since we do not know where a real root is in the x−axis interval.80 -3. the highest power of the polynomial is 5 (odd number).000 f(x) = x3 .xls.25 -8. or any other name. we invoke (open) the spreadsheet of the previous example.20 -9.000 3.843 0. Solution: To save lots of unnecessary work.40 -6.95 -2.00 -12.xls (or any other file name that was assigned to it). poly01.541 0. Next.75 -1. we arbitrarily y = f ( x ) = 3x – 2x + 6x – 8 5 3 (2.283 0.50 0.35 -7.00 0 1 2 3 4 5 f(x) x x f(x) x f(x) 1.000 0.

and we click on the small box next to it (the box with the hand).00 0. The Chart menu on the main taskbar and the Chart menu box below it.000 84.4 This table shows that f ( x ) changes sign somewhere in the interval from x = 1 and x = 2 . From the Chart menu box (below the main taskbar) we select Value (X) axis. Now we select B2 where we enter the formula for the given equation. =3*A2^5−2*A2^3+6*A2−8 We copy this formula to B3:B22. are now displayed.000 -8.000 175735.Approximations with Spreadsheets choose the interval – 10 ≤ x ≤ 10 . and we press the Delete key. Columns A and B now contain values of x and f ( x ) respectively.01 Numerical Analysis Using MATLAB® and Excel®. Then. We do this by highlighting the range A23:B102.00 -9.0 Maximum: 1. Third Edition Copyright © Orchard Publications 2−13 .00 2.6. Using the AutoFill feature.6.05.00 f(x) -298068.05.1 Major unit: 0. reveal some useful information.. 2. When this is done A1 contains 1.00 1. We select the graph box by clicking inside it.000 -175751.05 and x = 1. i. we fill−in the range A4:A22.00 9. We must now delete all rows starting with 23 and downward. and we have the interval from −10 to 10 in increments of 1.02 Minor unit: 0. x -10.10 . A2 contains 1. and B (values of f ( x ) ).00.e. to get better approximations. we enter −10 and −9 in A2 and A3 respectively. Columns A (values of x). Partial table for Example 2.000 298052.000 -1. Let us then redefine our interval of the x values as 1 ≤ x ≤ 2 in increments of 0. we click on the Scale tab and make the following entries: Minimum: 1. we perform Steps 2 through 4 below. On the View menu. and we observe the square handles surrounding it. To obtain a good approximation of the real root in that interval. and thus we expect that a real root exists between x = 1. A part of the table is shown in Figure 2.00 10. we click on Toolbars and place a check mark on Chart. Next.000 Sign Change Figure 2. Our spreadsheet now shows that there is a sign change from B3 to B4. on the Format axis menu. We observe that the chart has changed shape to conform to the new data. and so on. and the plot shows that the curve crosses the x−axis somewhere between x = 1 and x = 2.

186 0. roots_p=roots(p) 2−14 Numerical Analysis Using MATLAB® and Excel®.90 1.970 41.35 1.00 1.1 4.000 f(x) = 3x 5 .209 4.60 1.50 f(x) 0. We confirm this with MATLAB as follows: p = [ 3 0 −2 0 6 −8].631 11.80 1.85 1. we click on the Scale tab and make the following entries: Minimum: −1.605 34.00 1.5 Minor unit: 0.65 1.10 x x 1.05 Real Root between 1.20 1.50 1.Chapter 2 Root Approximations 3.40 1.20 f(x) = − 0.7.15 1.031 20.000 -0.00 f(x) -1.823 55.06 1.892 3.892 3.15 1. Then.965 73.865 29.10 1.4 Since no other roots are indicated on the plot.209 Figure 2.749 6. and we click on the small box next to it.05 1. x 1.7 and we see that one real root is approximately 1.770 1.25 1.545 8. We click on the Titles tab and make the following entries: Chart title: f(x) = the given equation (or whatever we wish) Value (X) axis: x (or whatever we wish) Value (Y) axis: y=f(x) (or whatever we wish) Our spreadsheet now should look like the one in Figure 2.00 0.8 1.455 84.186 0. Graph for Example 2.000 -0.00 1.04 1. Third Edition Copyright © Orchard Publications .021 47.70 1.50 -1. we suspect that the others are complex conjugates.10 1.55 1.08 1.00 -0. From the Chart menu we select Value (Y) axis.30 1.02 1.06.00 1.770 1.047 13.447 63.06 f(x) -1.75 1.692 24.95 2.45 1. on the Format axis menu.0 Maximum: 1.832 17.007 at x = 1.0 Major unit: 0.2x 3 + 6x .

Using the AutoFill feature. i.5.20 2. one in the 1.30 and x = 2. we select B2 and we enter the formula for the given equation.xls. that is. we enter −1.30 interval and the other in the 2.00 and −0.194 Sign Change Sign Change We observe two sign changes.059 0. Since we do not know where real roots (if any) are in the x−axis interval.90 in A2 and A3 respectively.e.xls or poly02. such as poly03.8212i 0.30 2.0604 Example 2.6113 1.30 interval.16) and we copy this formula to B3:B62.041 -0.20 1. Third Edition Copyright © Orchard Publications 2−15 .Approximations with Spreadsheets roots_p = -1.20 ≤ x ≤ 1. Numerical Analysis Using MATLAB® and Excel®. Then.9476i 0. Approximate values of these roots can also be observed on the plot of Figure 2.24 . We observe that Columns A and B contain the following sign changes (only a part of the table is shown): x 1. and save it with another name.. we arbitrarily choose the interval – 1 ≤ x ≤ 6 .8212i 0.9476i (2. we fill−in the range A4:A72 and thus we have the interval from −1 to 6 in increments of 0. we will find that the other two roots are approximately x = 1.1415 -1.20 ≤ x ≤ 2. we expect two more real roots.1415 0. this is found by substitution of zero into the given equation.10.xls. Solution: We invoke (open) the spreadsheet of one of the last two examples. There is a root at x = 0 .8 where the curve crosses the x – axis .30 f(x) 0.138 -0. =COS(2*A2)+SIN(2*A2)+A2−1 y = f ( x ) = cos 2x + sin 2x + x – 1 + + - 0.5 Compute the real roots of the trigonometric function using Excel.6113 0. If we redefine the x – axis range as 1 to 2. poly01. Next. Therefore.

70 0.5 We can obtain more accurate approximations using Excel’s Goal Seek feature.421 -1.325 -3.894 0.40 0. Thus.770 0.20 1. From the Tools drop menu.60 -0.20 -0.855 0.647 f(x) = cos2x + sin2x + x .882 0. In the last three examples our goal was to find the values of x for which y = f ( x ) = 0 .30 f(x) 0.041 -0.138 -0.30 0. We increase the accuracy of Columns J and K to 5 decimal places by clicking on Format.30 and −0.138 (or 1. we will use it to find better approximations for the non−zero roots of Example 2.80 -0.319 0.20 0.10 0. Numbers tab. To illustrate the Goal Seek feature.814 0.40 -0.Chapter 2 Root Approximations x -1. and when the Goal Seek dialog box appears. so that J1 contains 1. These indicate that for 2−16 Numerical Analysis Using MATLAB® and Excel®.50 -0. We use Goal Seek when we know the desired result of a single formula. if we have the function y = f ( x ) . find the value of the independent variable x which satisfies that goal. We do this with the following steps: 1.20 2.90 -0.059 0. we make the following entries: Set cell: K1 To value: 0 By changing cell: J1 3.829 -2.5.90 f(x) -3. Cells.30 2.60 0. we can use Goal Seek to set the dependent variable y to the desired value (goal) and from it.10 0. say J1 and K1.279 0.690 0.30 -0. Third Edition Copyright © Orchard Publications .8. but we do not know the input value which satisfies that result.039 -0.194 Figure 2.170 -1.70 -0.101 -2. we will observe the changes in J1 and K1. When this is done properly. Graph for Example 2.000 0.041 if range A25:B25 was copied).801 -1.000 0. we click on Goal Seek.00 -0.00 0. 2.1 6 4 f(x) 2 0 -2 -4 -1 0 1 2 3 4 5 6 x Real Root at Real Root between Real Root between x 0.50 0.668 -0.20 and K1 contains 0. We copy range A24:B24 (or A25:B25) to two blank cells.515 -2.00 1.80 0.510 0.

This is illustrated with the next example. For repetitive tasks. We will illustrate the procedure with the chart of Example 2. Example 2. We observe that other points are also displayed as the mouse is moved at different points near the curve. We click anywhere near the curve. Numerical Analysis Using MATLAB® and Excel®. (1.27647 .30 point.20 .5. 2.30.000. We repeat the above steps for the next root near x = 2. that we can use to find the complex roots of a polynomial with real coefficients. Third Edition Copyright © Orchard Publications 2−17 . which uses Newton’s method to approximate a real root of any polynomial with real coefficients up to the seventh power. y = f ( x ) = 0. then. with Excel.041). and we observe that five handles (black square boxes) are displayed along different points on the curve. We begin with a blank spreadsheet and we make the entries shown in Figure 2. is with a chart such as those we’ve created for the last three examples. in the By changing cell we enter A24 and we click on OK. we drag it towards the x−axis to change its value.28 and B24 displays 0.Approximations with Spreadsheets x = 1. We observe now that A24 displays 1. We will not discuss this method here. Another method of using the Goal Seek feature.6 Construct a template (model spreadsheet). it is prudent to construct a template (model spreadsheet) with the appropriate formulas and then enter the coefficients of the polynomial to find its real roots*. The Goal Seek dialog box then appears where the Set cell shows B24. near the x = 1. Solution: 1. it can be found in advanced numerical analysis textbooks. Then.00002 . and we verify that for x = 2.00020 . such as finding the roots of polynomials. use it to compute a root of the polynomial y = f ( x ) = x – 6x + 5x – 4x + 3x – 2x + x – 15 7 6 5 4 3 2 (2. in the To value box we enter 0. A square box appears and displays Series 1. known as Bairstow’s method. * There exists a numerical procedure.30 point. and when the cross symbol appears.9. 4. 1. Next. y = f ( x ) = 0. −0.22515 . We point the mouse at the curve where it intersects the x−axis. we click on the handle near the x = 1.17) given that one real root lies in the 4 ≤ x ≤ 6 interval.

we take the average 5 and we enter it in A16. This value is our first (initial) approximation. but this will change once we enter the polynomial coefficients. and in B16 we type the formula =A16-($A$7*A16^7+$B$7*A16^6+$C$7*A16^5+$D$7*A16^4 +$E$7*A16^3+$F$7*A16^2+$G$7*A16^1+$H$7)/ ($B$12*A16^6+$C$12*A16^5+$D$12*A16^4+$E$12*A16^3 +$F$12*A16^2+$G$12*A16^1+$H$12) The use of the dollar sign ($) is explained in Paragraph 4 below. is the familiar Newton’s formula which also appears in Row 14. Since we are told that one real root is between 4 and 6. Next. Third Edition Copyright © Orchard Publications . The formula in B16 of Figure 2. we save it with a different name. We also enter the polynomial coefficients.Chapter 2 Root Approximations A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 B C D E F G H Spreadsheet for finding approximations of the real roots of polynomials up the 7th power by Newton's Method. say Example_2_6.10.9. Then.9 with a name. We observe that B16 now displays #DIV/0! (this is a warning that some value is being divided by zero). 2−18 Numerical Analysis Using MATLAB® and Excel®. say template. We save the spreadsheet of Figure 2. 2. and the coefficients of the first derivative. therefore. we copy B16 to C16:F16 and the spreadsheet now appears as shown in the spreadsheet of Figure 2. and the coefficients of the first derivative in Rows 7 and 12 respectively. Powers of x and corresponding coefficients of given polynomial p(x) Enter coefficients of p(x) in Row 7 x6 x5 x4 x7 x3 x2 x Constant Coefficients of the derivative p'(x) Enter coefficients of p'(x) in Row 12 x5 x4 x6 x3 x2 x Constant Approximations: xn+1 = xn − p(xn)/p'(xn) Initial (x0) 1st (x1) 2nd (x2) 3rd (x3) 4th (x4) 5th (x5) 6th (x6) 7th (x7) Figure 2. We observe that there is no change in the values of E16 and F16.xls. Model spreadsheet for finding real roots of polynomials. 3.10.xls. we terminate the approximation steps there.

we made all cells.163190 Figure 2. B16 is a relative cell.163190 5. Powers of x and corresponding coefficients of given polynomial p(x) Enter coefficients of p(x) in Row 7 x6 x5 x4 x7 1 -6 5 -4 x3 3 x2 -2 x 1 Constant -15 Coefficients of the derivative p'(x) Enter coefficients of p'(x) in Row 12 x5 x4 x6 7 -36 25 x3 -16 x2 9 x -4 Constant 1 Approximations: xn+1 = xn − p(xn)/p'(xn) Initial (x0) 1st (x1) 2nd (x2) 3rd (x3) 4th (x4) 5th (x5) 6th (x6) 7th (x7) 5. The contents of a relative cell changes when it is copied from one location to another. changes to C16. we observe the successive approximations in Row 16. and in front of the row number. changes to B16. Thus. A cell that is not absolute is said to be relative cell. by first placing the cursor in front. All cells in the formula of B16. Numerical Analysis Using MATLAB® and Excel®. D16 and so on.6.3 The Bisection Method for Root Approximation The Bisection (or interval halving) method is an algorithm* for locating the real roots of a function. and so on. 4.0 5. then. We can easily convert a relative cell to absolute or vice versa. then. We can now use this template with any other polynomial by just entering the coefficients of the new polynomial in row 7 and the coefficients of its derivative in Row 12.The Bisection Method for Root Approximation A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 B C D E F G H Spreadsheet for finding approximations of the real roots of polynomials up the 7th power by Newton's Method. except A16. 2. especially an established. The relative cell A16. or between the letters and numbers of the cell. we press the function key F4. without changing its value.10. Third Edition Copyright © Orchard Publications 2−19 . These cells are said to be absolute. when copied to the next column.20409 5. Spreadsheet for Example 2. In this example. absolute so that the formula of B16 can be copied to C16. and $B$16 is an absolute cell. have dollar signs ($) in front of the column letter.16507 5. when copied to the next column to the right. at the end. The value of an absolute cell does not change when it is copied from one position to another. * This is a step−by−step problem−solving procedure. recursive computational procedure for solving a problem in a finite number of steps.163194 5. except A16.

11. To terminate the iterations.Chapter 2 Root Approximations The objective is to find two values of x. that is. f ( x m ) ⋅ f ( x 1 ) > 0 . In this case. f ( x 1 ) and f ( x m ) are both positive and thus their product is positive • x•1 x•m x 2 f ( x 1 ) and f ( x m ) are both negative and thus their product is positive • • x•1 x m x 2 Figure 2. we can compute the midpoint xm of the interval x 1 ≤ x ≤ x 2 with x1 + x2 x m = ---------------2 (2. In this case.12. If any of these two conditions is satisfied. Then. we replace x 2 with x m . Sketches to illustrate the bisection method when f ( x 1 ) and f ( x m ) have opposite signs After making the appropriate substitution. Sketches to illustrate the bisection method when f ( x 1 ) and f ( x m ) have same sign 2. the above process is repeated until the root we are seeking has a specified tolerance. specify a number of iterations b. specify a tolerance on the error of f ( x ) 2−20 Numerical Analysis Using MATLAB® and Excel®. This indicates that x m and x 1 are on the left side of the x−axis crossing as shown in Figure 2.11. Third Edition Copyright © Orchard Publications . If f ( x m ) and f ( x 1 ) have opposite signs. say x 1 and x 2 . f ( x 1 ) and f ( x m ) have opposite signs and thus their product is negative f ( x 1 ) and f ( x m ) have opposite signs and thus their product is negative • • x•1 x m x 2 x1 • • • xm x2 Figure 2. f ( x m ) ⋅ f ( x 1 ) < 0 . their product will be positive. that is. or f ( x 1 ) < 0 and f ( x 2 ) > 0 . If f ( x m ) and f ( x 1 ) have the same sign. the following decisions are made: 1. that is.18) Knowing x m . their product will be negative. This indicates that x m and x 2 are on the right side of the x−axis crossing as in Figure 2. we can find f ( x m ) .12. we replace x 1 with x m . so that f ( x 1 ) and f ( x 2 ) have opposite signs. we either: a. either f ( x 1 ) > 0 and f ( x 2 ) < 0 .

The special format \n specifies a linefeed. Here. The syntax is: for x = array commands.^ 3 + 6 .6f \n'.. The for end loop allows a group of functions to be repeated a fixed and predetermined number of times. k = 16 .6f are referred to as format specifiers or format scripts. fm must be expressed in decimal format with a total of 13 digits. function y= funcbisect01(x).6f %13. it prints everything specified up to that point and starts a new line. xm. We will define this function as funcbisect01 and will save it as funcbisect01. and using a while end loop MATLAB program Solution: This is the same polynomial as in Example 2.^ 5 − 2 .* x . 6 of which will be to the right of the decimal point. Numerical Analysis Using MATLAB® and Excel®. evaluate all commands down to the end command. Some other specifiers are %e for scientific format. by specifying 0. the first specifies that the value of xm must be expressed in decimal format also called fixed point format. the loop ends and any commands after the end are computed and displayed as commanded. with a total of 9 digits. the statement for k = 1:16 says for k = 1. For more information. % otherwise our script will fill the screen with values of y On the script below. Let us also review the meaning of the fprintf('%9. and using a for end loop MATLAB program b. % We must not forget to type the semicolon at the end of the line above. Example 2. we must define a function assigned to the given polynomial and save it as a function m−file. by specifying 16 iterations. Likewise. After the k = 16 iteration..6f and %13.00001 tolerance for f ( x ) . end Before we write the program script. k = 2. We will discuss other special formats as they appear in subsequent examples. a.* x . we can type help fprintf.19) a.4. y = 3 . %9. 6 of which will be to the right of the decimal point. and %d for integer format. %s for string format.The Bisection Method for Root Approximation We will illustrate the Bisection Method with examples using both MATLAB and Excel. ….m. that is.* x − 8. Third Edition Copyright © Orchard Publications 2−21 .7 Use the Bisection Method with MATLAB to approximate one of the roots of by y = f ( x ) = 3x – 2x + 6x – 8 5 3 (2.fm) line.

000732 1. MATLAB displays the following: xm fm ------------------------1.506944 1.6 disp(' xm fm') % xm is the average of x1 and x2...058594 -0. fm is f(xm) disp('-------------------------') % insert line under xm and fm for k=1:16.250000 4. x2=2. x1=1. 2−22 Numerical Analysis Using MATLAB® and Excel®.038318 1. end end When this program is executed.031250 -0.749023 1. Figure 2.060394 -0.002604 1.500000 17. xm.060547 0. else x1=xm.060303 -0. % We know this interval from Example 2. but for the integer part unnecessary leading zeros are not displayed.046875 -0.241184 1.060059 -0.000380 1.000176 1. if (f1*fm<0) x2=xm. xm=(x1+x2) / 2.031250 1.4.308441 1.059570 -0.125000 1. The syntax is: while expression commands.060410 0. Third Edition Copyright © Orchard Publications .6f \n'.6f %13.006289 1. The while end loop evaluates a group of commands an indefinite number of times.062500 0.032885 1.7 is given below. f2=funcbisect01(x2).Chapter 2 Root Approximations The script for the first part of Example 2. fm=funcbisect01(xm).015168 1. f1=funcbisect01(x1).103195 1. b.000102 We observe that the values are displayed with 6 decimal places as we specified.fm) % Prints xm and fm on same line.001844 1.060364 -0.060425 0.054688 -0. fprintf('%9.

disp(' xm fm'). Third Edition Copyright © Orchard Publications 2−23 . if (f1*fm<0). Now we type and execute the following while end loop program.308441 1.000732 1.060547 0.032885 1.060402 -0. we will use the same as in part a. f1=funcbisect01(x1). The script should be written so that eventually a false condition is reached and the loop then terminates.250000 4. x2=2.103195 1. fprintf('%9.6f %13.006289 1.The Bisection Method for Root Approximation end The commands between while and end are executed as long as all elements in expression are true.500000 17. MATLAB displays the following: xm fm ------------------------1.241184 1.000176 1.000380 1.060406 0.002604 1.031250 -0. disp('-------------------------') while (abs(x1-x2)>2*tol).058594 -0. fm=funcbisect01(xm).060404 -0.125000 1.060303 -0.059570 -0.060364 -0. f2=funcbisect01(x2). x1=1.031250 1. tol=0.000003 Numerical Analysis Using MATLAB® and Excel®.749023 1.506944 1.000032 1.fm).00001. end end When this program is executed.060394 -0.038318 1.000037 1. There is no need to create another function m−file.6f \n'.062500 0.015168 1.060425 0. xm.060059 -0.000102 1.054688 -0. xm=(x1+x2)/2.001844 1. x2=xm.060410 0.046875 -0. else x1=xm.

we will use an Excel spreadsheet to construct a template that approximates a real root of a function with the bisection method. =IF(M8<>N17. assign the number 800. =IF(C11>=1500. =IF(logical_test. value_if_false is the value that is returned if logical_test is false . L8/24):If the value in M8 is not equal to the value in N17. use the value in K7 multiplied by 12. Value_if_false can be another formula. =IF(D22<E22.A15. use the value in A15. B15):If the value in C11 is greater than or equal to 1500. true is returned.Chapter 2 Root Approximations Next.8 Use the bisection method with an Excel spreadsheet to approximate the value of 0. Example 2. otherwise use the value in L8 divided by 24. value_if_true: the value that is returned if logical_test is true. we make the following entries in rows 13 and 14. We expect the positive root to be in the 2 < x < 3 interval so we assign x 1 = 2 and x 2 = 3 . 1200):If the value in D22 is less than the value of E22.value_if_false) where logical_test: any value or expression that can be evaluated to true or false.value_if_true. This requires repeated use of the IF function which has the following syntax. The average of these values is x m = 2.6 so we can use it with any polynomial equation. If logical_test is false and value_if_false is omitted.13. A13: 2 B13: 3 C13: =(A13+B13)/2 2 5 within 2−24 Numerical Analysis Using MATLAB® and Excel®. K7*12. otherwise use the value in B15.00001 accuracy. We will create a template as we did in Example 2. Solution: Finding the square root of 5 is equivalent to finding the roots of x – 5 = 0 . Value_if_true can be another formula. Now.5 . otherwise assign the number 1200. If logical_test is true and value_if_true is omitted. 800. These statements may be clarified with the following examples. false is returned. We start with a blank spreadsheet and we make the entries in rows 1 through 12 as shown in Figure 2. Third Edition Copyright © Orchard Publications .

00000 1. C13. we highlight D13:F13 and on the Edit menu we click on Copy.14.00000 0.13. Finally. C13.00000 0. We place the cursor on D14 and from the Edit menu we click on Paste. B13) B14: =IF(A14=A13. Then.The Bisection Method for Root Approximation A 1 2 3 4 5 6 7 8 9 10 11 12 B C D E F G H Spreadsheet for finding approximations of the real roots of polynomials using the Bisection method Equation: y = f(x) = x − 5 = 0 Powers of x and corresponding coefficients of given polynomial f(x) Enter coefficients of f(x) in Row 9 2 x 7 x 6 x 5 x 4 x 3 x 2 x 0 Constant -5 0. Partial spreadsheet for Example 2.14.00000 x1 x2 xm (x1+x2)/2 f(x1) f(xm) f(x1)f(xm) Figure 2. Third Edition Copyright © Orchard Publications 2−25 . B13) We copy C13 into C14 and we verify that C14: =(A14+B14)/2 Next. We verify that the numbers on D14:F14 are as shown on the spreadsheet of Figure 2. and holding the mouse left button.00000 0. we highlight A14:F14. from the Edit menu we click on Copy. from the Edit menu. we highlight the range A15:A30. The square root of 5 accurate to six decimal places is shown on C30 in the spreadsheet of Figure 2.00000 0.8 D13: =$A$9*A13^7+$B$9*A13^6+$C$9*A13^5+$D$9*A13^4 +$E$9*A13^3+$F$9*A13^2+$G$9*A13^1+$H$9*A13^0 E13: =$A$9*C13^7+$B$9*C13^6+$C$9*C13^5+$D$9*C13^4 +$E$9*C13^3+$F$9*C13^2+$G$9*C13^1+$H$9*C13^0 F13: =D13*E13 A14: =IF(A14=A13. we click on Paste and we observe the values in A15:F30. Numerical Analysis Using MATLAB® and Excel®. we place the cursor on A15.

48438 0.00000 -0.23633 2.00000 -1.21484 -0.00320 -0.00757 -0.24219 2.23633 2.23438 2.06250 -0.00000 0.23606 f(x1) -1.00007 -0.8 2−26 Numerical Analysis Using MATLAB® and Excel®.07715 -0.00757 0.00047 -0.25000 2.00000 2.23602 2.00000 0.00000 -0.06250 0.23606 2.23584 2.00000 0.23828 2.23828 2.00001 0.25000 2.01657 0.00001 f(x1)f(xm) -1.00000 0.00058 -0.00006 0.21875 2.23608 2.23608 2.18750 2.23607 xm (x1+x2)/2 2.48438 -0.00006 -0.00116 -0.00000 0.23584 2.18750 2.Chapter 2 Root Approximations A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 B C D E F G H Spreadsheet for finding approximations of the real roots of polynomials using the Bisection method 2 Equation: y = f(x) = x − 5 = 0 Powers of x and corresponding coefficients of given polynomial f(x) Enter coefficients of f(x) in Row 9 x 7 x 6 x 5 x 4 x 3 x 2 x 0 Constant -5 0.00000 0.12500 2.23633 2.00102 -0.23438 2.00020 -0.21484 -0.00047 -0.10406 0.25000 2.00000 0.00020 -0.00757 -0.00320 -0.00757 -0.23605 2.23608 2.21875 2.00000 1.00000 2.25000 2.00000 0.07715 -0.23605 2. Entire spreadsheet for Example 2.24219 2.00021 -0.00000 0.23607 2.00000 2.00007 -0.23596 2.23607 2.23584 2.00003 -0.23438 2.50000 2.23438 2.50000 2.23633 2.00990 0.25000 2.00003 f(xm) 1.23608 2.23606 x2 3.23605 2.00002 0.00000 0.00000 -1.25000 2.23608 2.48438 -0.23535 2.00006 -0.00000 0.23602 2.25000 -0.02740 0.00102 -0.00757 -0. Third Edition Copyright © Orchard Publications .23535 2.25000 0.12500 2.23596 2.00102 0.00000 2.14.23438 2.00000 Figure 2.00000 x1 2.

this can best be done by plotting f ( x ) versus x . such as finding the roots of polynomials.value_if_true. say x 1 and x 2 . We use Goal Seek when we know the desired result of a single formula.4 Summary • Newton’s (or Newton−Raphson) method can be used to approximate the roots of any linear or non−linear equation of any degree. find the value of the independent variable x which satisfies that goal. In all cases. or f ( x 1 ) < 0 and f ( x 2 ) > 0 .value_if_false) Numerical Analysis Using MATLAB® and Excel®. • The Bisection (or interval halving) method is an algorithm for locating the real roots of a function. It uses the formula f ( xn ) x n + 1 = x n – -------------f ' ( xn ) To apply Newton’s method. • For repetitive tasks. This requires repeated use of the IF function which has the =IF(logical_test. • We can use a spreadsheet to approximate the real roots of linear and non−linear equations but to approximate all roots (real and complex conjugates) it is advisable to use MATLAB. we can compute the midpoint xm of the interval x 1 ≤ x ≤ x 2 with x1 + x2 x m = ---------------2 • We can use the Bisection Method with MATLAB to approximate one of the roots by specifying a number of iterations using a for end or by specifying a tolerance using a while end loop program. we can use Goal Seek to set the dependent variable y to the desired value (goal) and from it. Thus. if we have the function y = f ( x ) .Summary 2. either f ( x 1 ) > 0 and f ( x 2 ) < 0 . Third Edition Copyright © Orchard Publications 2−27 . • For approximating real roots we can use Excel’s Goal Seek feature. • We can use an Excel spreadsheet to construct a template that approximates a real root of a function with the bisection method. If any of these two conditions is satisfied. so that f ( x 1 ) and f ( x 2 ) have opposite signs. it is prudent to construct a template (model spreadsheet) with the appropriate formulas and then enter the coefficients of the polynomial to find its real roots. The objective is to find two values of x. but we do not know the input value which satisfies that result. that is. • The MATLAB the while end loop evaluates a group of statements an indefinite number of times and thus can be effectively used for root approximation. we must begin with a reasonable approximation of the root value.

Third Edition Copyright © Orchard Publications .5 using MATLAB.2 2−28 Numerical Analysis Using MATLAB® and Excel®. where a and b defined below. a. f 1 ( x ) = x + x – 3 b. Use MATLAB to sketch the graph y = f ( x ) for each of the following functions. Then. Repeat Exercise 1 above using the Bisection method. Hint: Use the procedure of Example 2. f 2 ( x ) = 4 a = 1 b = 2 a = 2 b = 4 2x + 1 – x + 4 Hint: Start with x 0 = ( a + b ) ⁄ 2 2.Chapter 2 Root Approximations 2. use Newton’s method to estimate the root of f ( x ) = 0 that lies between a and b . 3. and verify from the graph that f ( a ) and f ( b ) . have opposite signs. Repeat Example 2.5 Exercises 1.

= 1.169 ) + 1.= 1.169 ) + 1 Check with MATLAB: pa=[1 0 0 1 −3]. f1x=x.25 so we choose a = 1 and b = 1.1443 + 1. We compute the next value x 1 as 4 f ( x0 ) ( 1.0365 ( 1.f1x). a.= 1. Third Edition Copyright © Orchard Publications 2−29 . plot(x.1443 .6 Solutions to End-of-Chapter Exercises 1.05:2. grid 16 14 12 10 8 6 4 2 0 -2 -4 -2 -1.Solutions to End-of-Chapter Exercises 2.169 – 3 x 2 = x 1 – -------------.3241i 0.4526 0.1 – -------------------.25 so we take x 0 = 1.39 f ' ( x1 ) 4 ( 1.169 – --------------.= 1.1.= 1.436 ) x 1 = x 0 – -------------.5 1 1.5 -1 -0.164 3 7. roots(pa) ans = -1.5 0 0.= 1.1 ) + 1.1 – -----------------------------------.3241i 1.1640 Numerical Analysis Using MATLAB® and Excel®.1 – 3 ( – 0.^4+x−3. x=−2:0.5 2 From the plot above we see that the positive root lies between x = 1 and x = 1.1 as our first approximation.169 3 f ' ( x0 ) 6.324 4 ( 1.169 – -----------------------------------------------.1 ) + 1 The second approximation yields 4 f( x1 ) 0.

= 3 f ' ( x0 ) 1 ⁄ 7 – 1 ⁄ (2 7) 1 ⁄ (2 7) and Thus. 0.5 -1 -1.⋅ ( x + 4 ) – 1 ⁄ 2 ⋅ 1 = ------------------.– ------------------2 2 dx 2x + 1 2 x + 4 f( x0 ) 2×3+1– 3+4 0 x 1 = x 0 – -------------. f2x=sqrt(2. grid Warning: Imaginary parts of complex X and/or Y arguments ignored. 1 1 d 1 1 ----. ans = 3 2−30 Numerical Analysis Using MATLAB® and Excel®. solve(f2x) 7 – 7 = 0.05:5.*x+1)−sqrt(x+4).5 -2 -5 -4 -3 -2 -1 0 1 2 3 4 5 From the plot above we see that the positive root is very close to x = 3 and so we take x 0 = 3 as our first approximation.*x+1)−sqrt(x+4).⋅ f 2 ( x ) = -.= 3 – ----------------------------------------------. Third Edition Copyright © Orchard Publications .= 3 – --------------------. Check with MATLAB: syms x. We also observe that since f ( x 0 ) = there was no need to find the first derivative f ' ( x0 ) . We rewrite it as f2 ( x ) = 2x + 1 – x + 4 = ( 2x + 1 ) 1⁄2 1⁄2 – (x + 4) Then.5 0 -0.Chapter 2 Root Approximations b. x=−5:0.f2x). To compute the next value x 1 we first need to find the first derivative of f 2 ( x ) . f2x=sqrt(2.⋅ ( 2x + 1 ) – 1 ⁄ 2 ⋅ 2 – -. plot(x. the real root is exactly x = 3 .

% x1=a and x2=b disp(' xm fm') % xm is the average of x1 and x2. xm.m.057803 1. xm=(x1+x2) / 2. We will use the for end loop MATLAB program and specify 12 iterations.163574 -0.176041 1. fprintf('%9. f1=exercise2(x1).000200 1. end end MATLAB displays the following: xm fm ------------------------1. y = x .691406 1. fm is f(xm) disp('-------------------------') % insert line under xm and fm for k=1:12.m function y= exercise2(x).171875 0.014045 1. Before we write the program script.160156 -0.250000 0.162109 -0.Solutions to End-of-Chapter Exercises 2.273193 1. we must define a function assigned to the given polynomial and save it as a function m − file.156250 -0.^ 4 +x − 3.028229 1.fm)% Prints xm and fm on same line. f2=exercise2(x2).500000 3.00001.001584 b. Third Edition Copyright © Orchard Publications 2−31 .6f \n'. fm=exercise2(xm). x2=2. else x1=xm. we execute the following program: x1=1.6f %13. After saving this file as exercise2. if (f1*fm<0) x2=xm.056411 1.163818 -0.163086 -0. We will use the while end loop MATLAB program and specify a tolerance of 0. a.006930 1. We will define this function as exercise2 and will save it as exercise2.187500 0. We need to redefine the function m−file because the function in part (b) is not the same as in part a.164063 0.003367 1.125000 -0. Numerical Analysis Using MATLAB® and Excel®.562500 1.

000369 3.000166 2.010938 0.000012 2. disp('-------------------------') while (abs(x1-x2)>2*tol).062500 0.000443 2.fm). After saving this file as exercise2.1. x2=xm. fm=exercise2(xm). f2=exercise2(x2).002344 0.993750 -0.002065 3.925000 -0. % If we specify x1=a=2 and x2=b=4.998047 -0.000014 3.001182 3. y = sqrt(2.068779 2. end end When this program is executed. f1=exercise2(x1). else x1=xm.999994 -0.999927 -0.999121 -0.000065 2.000011 0.6f %13.6f \n'. if (f1*fm<0).005299 3.3.Chapter 2 Root Approximations function y= exercise2(x).037013 2.200000 0.999658 -0.000027 0.00001.m. xm=(x1+x2)/2.650000 -0.*x+1)−sqrt(x+4). the program % will not display any values because xm=(x1+x2)/2 = 3 = answer disp(' xm fm').014289 3.011733 2. x2=4. Third Edition Copyright © Orchard Publications .000195 0.000061 0. we execute the following program: x1=2.000001 3.028125 0. fprintf('%9.000002 2−32 Numerical Analysis Using MATLAB® and Excel®. tol=0. MATLAB displays the following: xm fm ------------------------3.000005 3.000037 2. xm.

function y=exercise3(x) % Finding roots by Newton's method using MATLAB y=cos(2. x=−5:0. To find a good approximation of the second root that lies between x = 2 and x = 3 .*x)+sin(2. function y=exercise3der(x) Numerical Analysis Using MATLAB® and Excel®. y=cos(2.*x)+sin(2.y). This is because when solving equations of periodic functions.02:5.Solutions to End-of-Chapter Exercises 3. The second value (2) is not exactly correct as we can see from the plot. plot(x.*x)+x−1. solve(y) ans = [0] [2] The first value (0) is correct as it can be seen from the plot above and also verified by substitution of x = 0 into the given function. Third Edition Copyright © Orchard Publications 2−33 . syms x. y=cos(2*x)+sin(2*x)+x−1. From Example 2.5. y = f ( x ) = cos 2x + sin 2x + x – 1 We use the following script to plot this function. we write and save the function files exercise3 and exercise3der as defined below. grid 6 4 2 0 -2 -4 -6 -8 -5 -4 -3 -2 -1 0 1 2 3 4 5 Let us find out what a symbolic solution gives. there are an infinite number of solutions and MATLAB restricts its search for solutions to a limited range near zero and returns a non−unique subset of solutions.*x)+x−1.

we write and execute the following program and we find that the second root is x = 2.*x)+2.*x)+1.*cos(2. Third Edition Copyright © Orchard Publications . x=xnext. disp(sprintf('First approximation is x = %9. fx = exercise3(x).2295 and this is consistent with the value shown on the plot. x = xnext. Now.1=yes)'). fprimex=exercise3der(x). fx=exercise3(x).6f \n'. x)) Enter starting value: 3 First approximation is x = 2. fprimex = exercise3der(x). fprimex = exercise3der(x). xnext=x−fx/fprimex.6f \n'. x)) while input('Next approximation? (<enter>=no. fx = exercise3(x).6f \n'. x)) end. disp(sprintf('Next approximation is x = %9.*sin(2.229485 2−34 Numerical Analysis Using MATLAB® and Excel®. x = input('Enter starting value: '). disp(sprintf('%9.Chapter 2 Root Approximations % Finding roots by Newton's method % The following is the first derivative of % the function defined as exercise3 y=−2. xnext = x−fx/fprimex.

5 1 0 Time 0 Time -0 . Also. are also introduced and their relationships to sinusoids are derived. Examples of alternating voltages and currents Thus an alternating current (AC) is defined as a periodic current whose average value over a period is zero.1 Alternating Voltages and Currents The waveforms shown in Figure 3. 3. The characteristics of sinusoids are discussed and the frequency. Phasors which are rotating vectors in terms of complex numbers. an alternating current alternates between positive and negative values at regularly recurring intervals of time. the average of the positive and negative values over a period is zero. Voltage or Current Voltage or Current 1 2 0 .1. Numerical Analysis Using MATLAB® and Excel®. and period are defined. Third Edition Copyright © Orchard Publications 3−1 . Stated differently. phase angle.Chapter 3 Sinusoids and Phasors T his chapter is an introduction to alternating current waveforms.1 may represent alternating currents or voltages. Voltage and current relationships are expressed in sinusoidal terms.5 -1 -1 0 2 T 4 6 8 1 0 1 2 -2 0 2 T 4 6 8 1 0 1 2 Voltage or Current Time Voltage or Current Time T T Figure 3.

is used to express the number of cycles per second. 3. We observe that when the phasor has completed a cycle (one revolution). then ωT = 2π or ----T = 2π ω (3. Unless otherwise stated. the cos ωt and sin ω t functions are generated from the projections of the phasor on the horizontal and vertical axis respectively. and let f ( t ) = A sin t where A is the amplitude of this function. A = 1 as shown. Generation of a sinusoid by rotation of a phasor At the completion of one cycle. our subsequent discussion will be restricted to sine or cosine waveforms and these are referred to as sinusoids. if we let the phasor (rotating vector) travel around the unit circle with an angular velocity ω . where f ( t ) may represent either a voltage or a current function. any periodic waveform which is not a sinusoid. we say 3−2 Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications . can be represented by a sum of sinusoids. it has traveled 2π radians or 360° degrees. commonly known as angular or radian frequency. or any other unit. A sinusoid (sine or cosine function) can be constructed graphically from the unit circle. Thus. such as the square and sawtooth waveforms on the previous page. Two main reasons for studying sinusoids are: (1) many physical phenomena such as electric machinery produce (nearly) sinusoidal voltages and currents and (2) by Fourier analysis.2. f (t) Voltage or Current Sine Wavef orm π ⁄ 2 ( 90° ) Phasor Direction of rotation 0 ( 0° ) 2π ( 360° ) A π ( 180° ) ω A = 1 0 π π /2 3π /2 2π −A 3π ⁄ 2 ( 270° ) Time Figure 3.2 Characteristics of Sinusoids Consider the sine waveform shown in Figure 3.1) The term frequency in Hertz.2. denoted as Hz . which is a circle with radius of one unit. if it takes one second to complete one cycle (one revolution around the unit circle). t = T (one period). and since ω is the angular velocity. that is. Thus.Chapter 3 Sinusoids and Phasors As shown in Figure 3. the period T of an alternating current or voltage is the smallest value of time which separates recurring values of the alternating waveform.1. and then repeats itself to form another cycle.

2) The frequency f is often referred to as the cyclic frequency to distinguish it from the radian frequency ω . in this case. It is possible. Numerical Analysis Using MATLAB® and Excel®. Since the cosine and sine functions are usually known in terms of degrees or radians. we say that the sine function lags (is behind) the cosine function by π ⁄ 2 radians or 90° . Plot of the cosine and sine functions By comparing the sinusoidal waveforms of Figure 3. or there is a phase angle of 90° between the cosine and sine functions.1) we have 1 f = --T or ω = 2π f (3. the two sinusoids are said to be in-phase. Obviously. If the phase angle between them is 0° degrees. Thus. We must remember that when we say that one sinusoid leads or lags another sinusoid. Likewise.4 shows three sinusoids which are outof-phase. or 90° . it is convenient to plot sinusoids versus ωt (radians) rather that time t .3. V max1 0.3. Figure 3. and i ( t ) = I max sin ω t are plotted as shown in Figure 3. The frequency is denoted by the letter f and in terms of the period T and (3.5 cos ω t sin ωt π⁄4 π⁄2 π 3π ⁄ 2 2π ωt 0 -0. of course. we say that the cosine function leads (is ahead of) the sine function by π ⁄ 2 radians or 90° . two sinusoids of different frequencies can never be in phase. we see that the cosine function will be the same as the sine function if the latter is shifted to the left by π ⁄ 2 radians.Characteristics of Sinusoids that the frequency is 1 Hz or one cycle per second. if we shift the cosine function to the right by π ⁄ 2 radians or 90° . Another common expression is that the cosine and sine functions are out-of-phase by 90° . that two sinusoids are out-of-phase by a phase angle other than 90° . v ( t ) = V max cos ωt . Third Edition Copyright © Orchard Publications 3−3 . we obtain the sine waveform.5 -1 – V max 0 1 2 3 T 4 5 6 7 Figure 3. For example.3. these are of the same frequency.

Example 3.5 0 -0. it is acceptable to express as v ( t ) = 100 sin ( 2000πt – π ⁄ 6 ) v ( t ) = 100 sin ( 2000πt – 30° ) since the subtraction inside the parentheses needs not to be performed.75 sin ( ωt + θ ) 0 ωt ϕ -2 0 2 4 6 8 Figure 3. When two sinusoids are to be compared in terms of their phase difference.5 -1 -1.4.Chapter 3 Sinusoids and Phasors 1. Out-of-phase sinusoids It is convenient to express the phase angle in degrees rather than in radians in a sinusoidal function. and should also be written with positive amplitudes. For example. Third Edition Copyright © Orchard Publications .25 sin ( ωt – ϕ ) 1. and – sin x = sin ( x ± 180 ° ) and sin x = cos ( x – 90 ° ) 3−4 Numerical Analysis Using MATLAB® and Excel®.1 Find the phase difference between the sinusoids i 1 = 120 cos ( 100πt – 30 ° ) and i 2 = – 6 sin ( 100πt – 30 ° ) Solution: We recall that the minus (−) sign indicates a ± 180° phase shift. Then. and that the sine function lags the cosine by 90° . We should remember also that a negative amplitude implies 180° phase shift. or both as sine functions.5 1 0. these must first be written either both as cosine functions.5 -4 sin ωt θ 0.

= 0.5. we see that i 2 leads i 1 by 90° .6) (3.283… radians in 360° degrees.= -----.4) (3. derivatives and integrals involving trigonometric functions.3 deg r r π radians Figure 3.Characteristics of Sinusoids i 2 = 6 sin ( 100πt – 210 ° ) = 6 sin ( 100πt + 150 ° ) = 6 cos ( 100πt + 150 ° – 90 ° ) = 6 cos ( 100πt + 60 ° ) and comparing i 2 with i 1 .5 3 2 (3. Then. cos 0° = cos 360° = cos 2π = 1 π 3 cos 30° = cos -. Then. 1 radian = 57.≈ 57. the radian is a circular angle subtended by an arc equal in length to the radius of the circle. whose radius is r units in length. In our subsequent discussion. The circumference of a circle is 2πr units.= -.866 6 2 π 2 cos 45° = cos -.= 0. there are 2π or 6.5) (3. has an angular velocity ω = 2πn radians per second. therefore. and it is denoted by the symbol ω .707 4 2 π 1 cos 60° = cos -.3° 2π (3. Let us also review the definition of a radian and its relationship to degrees with the aid of Figure 3. Definition of radian As shown in Figure 3. provide the following relations and formulas for quick reference.7) Numerical Analysis Using MATLAB® and Excel®. therefore. a rotating vector that completes n revolutions per second. 360° 1 radian = ---------.5. Third Edition Copyright © Orchard Publications 3−5 .3) The angular velocity is expressed in radians per second.= 0. or i 1 lags i 2 by 90° . we will be using several trigonometric identities. We.= -----.5. Some useful trigonometric relations are given below for quick reference.

866 3 2 (3.23) 3−6 Numerical Analysis Using MATLAB® and Excel®.= 0 2 2π –1 cos 120° = cos ----.14) (3.= -----.= 0. Third Edition Copyright © Orchard Publications .= 1 2 2π 3 sin 120 ° = sin ----.15) (3.10) (3.16) (3.= ----.5 3 2 ------------cos 150° = cos 5π = – 3 = – 0.= -.866 2 6 cos 180° = cos π = – 1 7π – 3 cos 210° = cos ----.= – 0.19) (3.5 3 11π cos 330° = cos -------.9) (3.21) (3.12) (3.20) (3.= -----.= 0.Chapter 3 Sinusoids and Phasors π cos 90° = cos -.8) (3.18) (3.866 6 sin 0 ° = sin 360 ° = sin 2 π = 0 --sin 30 ° = sin π = 1 = 0.13) (3.866 3 2 π sin 90 ° = sin -.707 2 4 --------cos 240° = cos 4π = – 1 = – 0.17) (3.707 4 2 π 1 sin 60 ° = sin -.= – 0.5 2 3 ----cos 270° = cos 3π = 0 2 5π cos 300° = cos ----.866 6 2 ------------cos 225° = cos 5π = – 2 = – 0.5 2 6 π 2 sin 45 ° = sin -.= 0.= 0.= 0.22) (3.11) (3.= --------.

= ----.= -.30) (3.25) (3.= ---------sin θ tan θ 1 sec θ = ----------cos θ 1 csc θ = ---------sin θ tan ( 90° + θ ) = – cot θ (3. Third Edition Copyright © Orchard Publications 3−7 .5 6 2 cos ( – θ ) = cos θ cos ( 90° + θ ) = – sin θ cos ( 180° – θ ) = – cos θ sin ( – θ ) = – sin θ sin ( 90° + θ ) = cos θ sin ( 180° – θ ) = sin θ sin θ tan θ = ----------cos θ cos θ 1 cot θ = ----------.= – 0.707 4 2 ------------sin 240 ° = sin 4π = – 3 = – 0.= – 0.866 3 2 11π –1 sin 330 ° = sin -------.= – 0.41) (3.5 6 2 5π – 2 sin 225 ° = sin ----.40) (3.866 2 3 ----sin 270 ° = sin 3π = – 1 2 5π – 3 sin 300 ° = sin ----.26) (3.33) (3.36) (3.Characteristics of Sinusoids 5π 1 sin 150 ° = sin ----.5 6 2 sin 180 ° = sin π = 0 7π –1 sin 210 ° = sin ----.= ----.38) (3.39) (3.24) (3.28) (3.34) (3.42) Numerical Analysis Using MATLAB® and Excel®.35) (3.37) (3.= – 0.= --------.= 0.29) (3.32) (3.31) (3.= --------.27) (3.

45) (3.51) (3.57) (3.( 1 + cos 2θ ) 2 1 2 sin θ = -.43) (3.sin ( θ + φ ) + -.53) (3.52) (3.58) (3.49) (3.55) (3.Chapter 3 Sinusoids and Phasors tan ( 180° – θ ) = – tan θ cos ( θ + φ ) = cos θ cos φ – sin θ sin φ cos ( θ – φ ) = cos θ cos φ + sin θ sin φ sin ( θ + φ ) = sin θ cos φ + cos θ sin φ sin ( θ – φ ) = sin θ cos φ – cos θ sin φ tan θ + tan φ tan ( θ + φ ) = ------------------------------1 – tan θ tan φ tan θ – tan φtan ( θ – φ ) = ------------------------------1 + tan θ tan φ cos θ + sin θ = 1 cos 2θ = cos θ – sin θ sin 2 θ = 2 sin θ cos θ 2 tan θ tan 2θ = --------------------2 1 – tan θ 1 2 cos θ = -.cos ( θ – φ ) – 1 cos ( θ + φ ) 2 2 2 2 2 2 (3.cos ( θ + φ ) + -.56) (3. Third Edition Copyright © Orchard Publications .50) (3.sin ( θ + φ ) – 1 sin ( θ – φ ) 2 2 1 1 sin θ cos φ = -.46) (3.44) (3.( 1 – cos 2θ ) 2 1 1 cos θ cos φ = -.54) (3.sin ( θ – φ ) 2 2 1 -sin θ sin φ = -.59) 3−8 Numerical Analysis Using MATLAB® and Excel®.cos ( θ – φ ) 2 2 1 -cos θ sin φ = -.47) (3.48) (3.

by the law of cosines. are used extensively in engineering.70) ∫ sin ax dx ∫ cos a x dx ∫e ax = – 1 cos ax + c -a 1 = -.= ---------.( α – β ) 2 a – b = --------------------------------------1 a+b tan -.69) (3.= ---------------------------1 b+c tan -.( γ + α ) 2 The following differential and integral trigonometric and exponential functions. by the law of sines.67) (3.( α + β ) 2 c = a + b – 2ab cos γ 1 tan -. a β c γ b α Figure 3. dv d ( sin v ) = cos v ----dx dx dv d ( cos v ) = – sin v ----dx dx d ( e v ) = e v dv ----dx dx (3. Third Edition Copyright © Orchard Publications 3−9 .( β – γ ) 2 2 2 2 b–c ---------. 1 tan -.e Numerical Analysis Using MATLAB® and Excel®.68) (3.Characteristics of Sinusoids Let Figure 3.66) (3.65) (3.61) (3.( β + γ ) 2 2 c–a ---------.sin ax + c a 1 ax +c a dx = -.62) (3.63) 1 tan -. General triangle Then.60) (3.6.6 be any triangle.64) tan -. a b c ---------.( γ – α ) and by the law of tangents.= ---------------------------1 c+a (3.= --------sin α sin β sin γ a = b + c – 2bc cos α b = a + c – 2ac cos β 2 2 2 2 2 2 (3.

then u = tan –1z . and thus its value is again A . if y = cos x . another multiplication of the new vector jA by j will produce another 90° counterclockwise direction. cos 60° = 0. 2 3 4 3−10 Numerical Analysis Using MATLAB® and Excel®. r is a real number and jr is an imaginary number. These are called Inverse Trigonometric Functions. Therefore. Thus.3 Inverse Trigonometric Functions The notation cos –1y or arc cos y is used to denote an angle whose cosine is y . j = – j . When this vector is rotated by another 90° for a total of 270° . j = 1 . we want to find the angle θ given that its cosine is 0.2 Find the angle θ if cos –10. i = – 1 . and the y -axis (ordinate) as the imaginary axis with the understanding that the “imaginary” axis is just as “real” as the real axis. In the electrical engineering field. * A more appropriate nomenclature for the real and imaginary axes would be the axis of the cosines and the axis of the sines respectively. From (3. multiplication of this vector by the operator j will result in a new vector jA whose magnitude remains the same. Essentially. θ = 60° 3. the square root of minus one is denoted as i . In other words. by the operator j . the imaginary axis is just as important as the real axis. we will designate the x -axis (abscissa) as the real axis. its value becomes j ( – A ) = – jA . say r . if w = sin v . Third Edition Copyright © Orchard Publications . that is. Also. A fourth 90° rotation returns the vector to its original position.7). the vector A has rotated 180° and its new value now is – A . then v = sin –1w . then x = cos –1y . we conclude that j = – 1 . and the rotating vector A is referred to as a phasor.5 . j is an operator that produces a 90° counterclockwise rotation to any vector to which it is applied as a multiplying factor.7. Thus. Note: In our subsequent discussion. Therefore. Example 3. Similarly. if it is given that a vector A has the direction along the right side of the x -axis as shown in Figure 3.Chapter 3 Sinusoids and Phasors 3.4 Phasors In the language of mathematics.5 = θ Solution: Here.5. but it has been rotated counterclockwise by 90° . and if z = tan u . In this case. we denote i as j to avoid confusion with current i . Thus.* An imaginary number is the product of a real number.

is a complex number.5 Addition and Subtraction of Phasors The sum of two phasors has a real component equal to the sum of the real components. we change the signs of the components of the subtrahend and we perform addition. For example. For subtraction. and B = 4 – j2 . henceforth any complex number will be referred to as a phasor. are equal if and only if their real parts are equal and also their imaginary parts are equal. The j operator A complex number is the sum (or difference) of a real number and an imaginary number. and b = Im { A } the imaginary part of A . it is said to be expressed in rectangular form.Addition and Subtraction of Phasors jA y j ( jA ) = j 2 A = – A A x 2 j ( – jA ) = – j A = A j ( – A ) = j 3 A = – jA Figure 3.7. A = B if and only if a = c and b = d . 3. By definition. Since in engineering we use complex quantities as phasors. When written as A = a + jb . if A = a + jb and B = c + jd . Third Edition Copyright © Orchard Publications 3−11 . the number A = a + jb where a and b are both real numbers. a = Re { A } and b = Im { A } where Re { A } denotes real part of A . Then. then and A + B = (a + c) + j(b + d) A – B = (a – c) + j(b – d ) Example 3. two phasors A and B where A = a + jb and B = c + jd . and an imaginary component equal to the sum of the imaginary components.3 It is given that A = 3 + j4 . Find A + B and A – B Solution: Numerical Analysis Using MATLAB® and Excel®. Thus. Thus.

Third Edition Copyright © Orchard Publications . Find A ⋅ B Solution: A ⋅ B = ( 3 + j4 ) ⋅ ( 4 – j2 ) = 12 – j6 + j16 – j 2 8 = 20 + j10 The conjugate of a phasor. Thus. Thus.5 It is given that A = 3 + j5 . denoted as A∗ . is another phasor with the same real component. A∗ = 3 – j 5 If a phasor A is multiplied by its conjugate. Thus.Chapter 3 Sinusoids and Phasors A + B = (3 + j4) + (4 – j2) = (3 + 4) + j(4 – 2) = 7 + j2 A – B = (3 + j4) – (4 – j2) = (3 – 4) + j(4 + 2) = – 1 + j6 3. Find A∗ Solution: The conjugate of the phasor A has the same real component. then A ⋅ A∗ = ( a + jb ) ( a – jb ) = a 2 – jab + jab – j 2 b 2 = a + b 2 2 3−12 Numerical Analysis Using MATLAB® and Excel®. and making use of the fact that j 2 = – 1 .6 Multiplication of Phasors Phasors are multiplied using the rules of elementary algebra. then A ⋅ B = ( a + jb ) ⋅ ( c + jd ) = ac + jad + jbc + j 2 bd and since j 2 = – 1 . if A = a + jb and B = c + jd .4 It is given that A = 3 + j4 and B = 4 – j2 . then A∗ = a – j b . Example 3. and with an imaginary component of opposite sign. the result is a real number. but the imaginary component has opposite sign. if A = a + jb . if A = a + jb . Then.71) Example 3. it follows that A ⋅ B = ac + jad + jbc – b d = ( ac – bd ) + j ( ad + bc ) (3.

Thus.= --. and it is done by multiplying the denominator by its conjugate.= ------------.⋅ -----.28 ------------------------------------------------2 2 25 25 B 25 4 + j3 (4 + j3)(4 – j3) 4 +3 3. if A = a + jb and B = c + jd .7 Division of Phasors When performing division of phasors.+ j ---------------------2 2 2 2 c +d c +d (3.96 + j 0.= ------------------------------------. we see that the quotient is easily separated into a real and an imaginary part.8 Exponential and Polar Forms of Phasors The relations e and Numerical Analysis Using MATLAB® and Excel®.6 It is given that A = 3 + j5 . Find A ⋅ A∗ Solution: A ⋅ A∗ = ( 3 + j5 ) ( 3 – j5 ) = 3 + 5 = 9 + 25 = 34 2 2 3.= 12 – j 9 + j 16 + 12 = ---------------.7 It is given that A = 3 + j4 . Using this procedure.73) 3−13 . Example 3. Find A ⁄ B Solution: Using the procedure of (3.= ----------------------------------------------------2 2 B B∗ B c + jd ( c + jd ) ( c – jd ) c +d ( ac + bd ) ( bc – ad ) = ---------------------.= -------------------------------------.Division of Phasors Example 3. and B = 4 + j3 . Third Edition Copyright © Orchard Publications jθ = cos θ + j sin θ (3. we get 73 + j4 (3 + j4)(4 – j3) 24 + j 7 A = ------------.72). it is desirable to obtain the quotient separated into a real part and an imaginary part. then. A B∗ a + jb ( a + jb ) ( c – jd ) ( ac + bd ) + j ( bc – ad ) A --.72) In (3. This procedure is called rationalization of the quotient.72).= 24 + j ----. we multiplied both the numerator and denominator by the conjugate of the denominator to eliminate the j operator from the denominator of the quotient.= 0.

and thus Ce jθ = a + jb (3. we get a = C cos θ and b = C sin θ Squaring and adding the expressions in (3.73) by the real positive constant C we get: Ce jθ – jθ = cos θ – j sin θ (3.75) This expression represents a phasor. from (3.--------------a C cos θ –1 b θ = tan ⎛ -.Chapter 3 Sinusoids and Phasors e are known as the Euler’s identities. say a + jb . we get a + b = ( C cos θ ) + ( C sin θ ) = C ( cos θ + sin θ ) = C Then.81) 3−14 Numerical Analysis Using MATLAB® and Excel®. we use the expression a + jb = a +b e 2 2 –1 (3.78) Also.77). Third Edition Copyright © Orchard Publications . to convert a phasor from rectangular to exponential form.79) Therefore.77) b = C sin θ = tan θ -.80) To convert a phasor from exponential to rectangular form. Multiplying (3.77) or C = a +b 2 2 (3.76).74) = C cos θ + j C sin θ (3.⎞ or ⎝a⎠ j ⎛ tan ⎝ b⎞ -a⎠ (3. C = a +b 2 2 2 2 2 2 2 2 2 2 2 (3.76) Equating real and imaginary parts in (3.75) and (3. we use the expressions Ce Ce jθ = C cos θ + j C sin θ = C cos θ – j C sin θ – jθ (3.

1 ° = 5 ∠53. Ce jθ = C ∠θ (3.8. 3 + j4 b. In Examples 3. – 1 + j2 c.82) is the exponential form. 3 + j4 = 3 +4 ⋅e 2 2 j tan ( 4 ⁄ 3 ) – = 5e j53.8 and 3.y] = pol2cart(theta.Exponential and Polar Forms of Phasors The polar form is essentially the same as the exponential form but the notation is different.8.r) − transforms from polar to Cartesian co−ordinates Example 3. – 2 – j d.8 Convert the following phasors to exponential and polar forms: a. The real and imaginary components of this phasor are shown in Figure 3. thetax=angle(x)*180/pi.82) where the left side of (3. and rotates in the counterclockwise direction. disp(thetax) 5 53. [x. magx=abs(x). that is. We must remember that the phase angle θ is always measured with respect to the positive real axis.1° 3 Re Figure 3. we will verify the results with the following MATLAB co-ordinate transformation functions: [theta.y) − transforms from Cartesian to polar co−ordinates. The components of 3 + j4 Then.r] = cart2pol(x. 4 – j3 Solution: a.1301 or Numerical Analysis Using MATLAB® and Excel®. and the right side is the polar form. 4 Im 5 53.9 below. Third Edition Copyright © Orchard Publications 3−15 .1° Check with MATLAB: x=3+j*4. disp(magx).

[theta. The components of – 1 + j2 1 +2 e 2 j tan ( 2 ⁄ – 1 ) – = 5e j116.4° −1 116.y). magy=abs(y).9273 r = 5 deg = 53. 3−16 Numerical Analysis Using MATLAB® and Excel®. For an introduction to Simulink.8 (a) b. please refer to “Introduction to Simulink with Engineering Applications”.9.10. y = 4.6° Re 2 Then. thetay=angle(y)*180/pi.1301 We can also verify the result with Simulink®* as shown in the model of Figure 3. The K value for the Gain block has been specified as 180 ⁄ π to convert radians into degrees. ISBN 09744239-7-1.6 ° = 5 ∠116. – 1 + j2 = 2 Figure 3. deg = theta*180/pi theta = 0.r] = cart2pol(x.9. Im 5 63. A brief introduction to Simulink is provided in Appendix B.236 ∠116. Third Edition Copyright © Orchard Publications .6° Check with MATLAB: y=−1+j*2. disp(magy).10. Simulink model for Example 3.6° = 2.Chapter 3 Sinusoids and Phasors x = 3. disp(thetay) * The reader who is not familiar with Simulink may skip this model and all others without loss of continuity. The real and imaginary components of this phasor are shown in Figure 3. Figure 3.

0344 r = 2.6° = 5e j ( – 153.5651 or x = −1. magv=abs(v).4°(Measured Clockwise) −1 Figure 3. disp(magv).6° −2 26. Simulink model for Example 3.2361 116.12.236 ∠– 153.6 ° = Im 5 ∠206.2361 deg = 116.8 (b) c.11. Then.6° 5 Re −153.5651 Check with the Simulink model of Figure 3.r] = cart2pol(x. –2 –j 1 = 2 +1 ⋅e 2 2 j tan ( – 1 ⁄ – 2 ) – = 5e j206. y = 2.4 ) ° = 2.11: Figure 3.4 ° 206.Exponential and Polar Forms of Phasors 2. disp(thetav) Numerical Analysis Using MATLAB® and Excel®. thetav=angle(v)*180/pi. The components of – 2 – j Check with MATLAB: v=−2−j*1.y).12. deg = theta*180/pi theta = 2. The real and imaginary components of this phasor are shown in Figure 3. [theta. Third Edition Copyright © Orchard Publications 3−17 .

Third Edition Copyright © Orchard Publications .2361 -153. disp(magw). Im 323.1° = 5e – j36.9° −3 5 4 Re Then.9 ° Check with MATLAB: w=4−j*3.9 ° = 5 ∠– 36. disp(thetaw) 3−18 Numerical Analysis Using MATLAB® and Excel®.14. thetaw=angle(w)*180/pi. The real and imaginary components of this phasor are shown in Figure 3. deg = theta*180/pi theta = -2.13.Chapter 3 Sinusoids and Phasors 2.y).1° −36. y = −1. magw=abs(w). 4 –j 3 = 4 +3 ⋅e 2 2 Figure 3.6779 r = 2.13: Figure 3.4349 Check with the Simulink model of Figure 3.1 ° = 5 ∠323.2361 deg = -153.8 (c) d. The components of 4 – j3 j tan ( – 3 ⁄ 4 ) – = 5e j323.4349 or x = −2.r] = cart2pol(x. [theta.14. Simulink model for Example 3.

– 2 ∠30° = 2 ∠( 30° + 180° ) = 2 ∠210° = 2 ∠– 150° The components of this phasor are shown in Figure 3. Simulink model for Example 3. Numerical Analysis Using MATLAB® and Excel®. y = −3.16. deg = theta*180/pi theta = -0.8699 Check with the Simulink model of Figure 3.15. then – 2 ∠30° is the same as 2 ∠30° rotated counterclockwise by 180° .6435 r = 5 deg = -36. Since each j rotates a vector by 90° counterclockwise. Therefore.r] = cart2pol(x. Solution: We recall that – 1 = j 2 .15: Figure 3. [theta.8 (d) Example 3.y).9 Express the phasor – 2 ∠30° in exponential and in rectangular forms.Exponential and Polar Forms of Phasors 5 -36.8699 or x = 4. Third Edition Copyright © Orchard Publications 3−19 .

Chapter 3 Sinusoids and Phasors Im 210° −1.7578 y = -0. we multiply the magnitudes and we add the phase angles.17: Figure 3.866 – j0. that is.r) x = -1. To multiply two phasors in exponential (or polar) form.17. The components of 2 ∠– 150° = 2 ( cos 150° – j sin 150° ) = 2 ( – 0. [x.73 – j Check with MATLAB: r = −2.73 30° 2 Re −150°(Measured Clockwise) −1 Then.9 Note: The rectangular form is most useful when we add or subtract phasors.9541 Check with the Simulink model of Figure 3. Simulink model for Example 3. AB = MN ∠( θ + φ ) = M e jθ Ne jφ = MN e j(θ + φ ) (3.83) 3−20 Numerical Analysis Using MATLAB® and Excel®. 2 ∠– 150 ° = 2e – j 150 ° Figure 3. however. theta = 30/pi.y] = pol2cart(theta*180/pi.16.5 ) = – 1. Third Edition Copyright © Orchard Publications . the exponential and polar forms are most convenient when we multiply or divide phasors. if A = M ∠θ and B = N ∠φ then.

7° Solution: Multiplication in polar form yields AB = ( 12.7° ) = 90.58.22.Exponential and Polar Forms of Phasors Example 3. deg=deg1+deg2 r = 90. deg2=−118. r=r1*r2.10 Multiply A = 12.3° ) ( 7.4° Check with MATLAB: r1=12.7° ) ] = 90. r2=7.3° by B = 7.22e – j 118.83e – j 44.83e j ( 74.4 ° and multiplication in exponential form yields AB = ( 12.18.4000 Check with the Simulink model of Figure 3.8276 deg = -44. Numerical Analysis Using MATLAB® and Excel®.18*: Figure 3.58 ∠74. deg1=74. Third Edition Copyright © Orchard Publications 3−21 .22 ∠– 118. The intent here is to introduce relevant Simulink blocks for more complicated models. It can be done faster with just MATLAB.22 ) ∠[ 74.58e j74.58 × 7. Simulink model for Example 3.3° – 118.7° ) = 90.3° + ( – 118.10 * It would certainly be a waste of time to use Simulink for such an application.83 ∠– 44.3.7.

74 ∠– 167 ° B 7.Chapter 3 Sinusoids and Phasors To divide one phasor by another when both are expressed in exponential or polar form. and we subtract the phase angle of the divisor from the phase angle of the dividend.= ---.19*: * Same comment as on the footnote of the previous page.3.58 ∠74.7.7° Division in exponential form yields 12.3° e j118.22e j74.58.22 ∠– 118.7° = 1.58e A = ---------------------------.3° j74.7° Solution: Division in polar form yields A 12.= ---.74e – j 167° Check with MATLAB: r1=12. deg2=−118. that is.7424 deg = 193 Check with the Simulink model of Figure 3.3° by B = 7. if then.3° – ( – 118. deg1=74. 3−22 Numerical Analysis Using MATLAB® and Excel®.74 ∠[ 74.7° ) ] = 1.11 Divide A = 12.= 1.7° B 7. we divide the magnitude of the dividend by the magnitude of the divisor. Third Edition Copyright © Orchard Publications .74e j193° = 1.74e --– j118.∠( θ – φ ) = -----------.3° --. r=r1/r2.84) Example 3. A = M ∠θ and B = N ∠φ M j(θ – φ ) M Me A --.22. r2=7.58 ∠74. deg=deg1−deg2 r = 1.74 ∠193° = 1.22 ∠– 118.= ---------------------------------.= 1.e N jφ N B Ne jθ (3.

19.Exponential and Polar Forms of Phasors Figure 3.11 Numerical Analysis Using MATLAB® and Excel®. Simulink model for Example 3. Third Edition Copyright © Orchard Publications 3−23 .

Alternately. if y = cos x . • It is important to remember that when we say that one sinusoid leads or lags another sinusoid. • The angular velocity ω is commonly known as angular or radian frequency and ωT = 2π • The term frequency in Hertz. Third Edition Copyright © Orchard Publications . and the sine function lags (is behind) the cosine function by π ⁄ 2 radians or 90° . • A phasor is a rotating vector expressed as a complex number where j is an operator that rotates a vector by 90° in a counterclockwise direction. • The cosine function leads (is ahead of) the sine function by π ⁄ 2 radians or 90° . f = 1 ⁄ T . The circumference of a circle is 2πr .9 Summary • An alternating current (or voltage) alternates between positive and negative values at regularly recurring intervals of time. • Two (or more) sinusoids can be out-of-phase by a phase angle other than 90° . and should also be written with positive amplitudes. These are called Inverse Trigonometric Functions. we say that the cosine and sine functions are out-of-phase by 90° . For example.Chapter 3 Sinusoids and Phasors 3. is used to express the number of cycles per second. these are of the same frequency since two sinusoids of different frequencies can never be in phase. we write v ( t ) = 100 sin ( 2000πt – π ⁄ 6 ) as v ( t ) = 100 sin ( 2000πt – 30° ) • When two sinusoids are to be compared in terms of their phase difference. The frequency is denoted by the letter f and in terms of the period T . then x = cos – 1y . whose radius is r units in length. • It is customary to express the phase angle in degrees rather than in radians in a sinusoidal function. 3−24 Numerical Analysis Using MATLAB® and Excel®. these must first be written either both as cosine functions. or there is a phase angle of 90° between the cosine and sine functions. • A negative amplitude implies 180° phase shift. • The radian is a circular angle subtended by an arc equal in length to the radius of the circle. The frequency f is often referred to as the cyclic frequency to distinguish it from the radian frequency ω. denoted as Hz . • The notation cos –1y or arc cos y is used to denote an angle whose cosine is y . or both as sine functions. Thus. • The period T of an alternating current or voltage is the smallest value of time which separates recurring values of the alternating waveform. • Sine and cosine waveforms and these are referred to as sinusoids.

that is. however. denoted as A∗ .+ j ---------------------2 2 2 2 2 2 B c + jd ( c + jd ) ( c – jd ) c +d c +d c +d • The relations e ties. we use the expression a + jb = a +b e 2 2 j ⎛ tan ⎝ –1 b⎞ -a⎠ • To convert a phasor from exponential to rectangular form. and rotates in the counterclockwise direction. the exponential and polar forms are most convenient when we multiply or divide phasors. is another phasor with the same real component. if A = a + jb . • When performing division of phasors.= ----------------------------------------------------. jθ = cos θ + j sin θ and e – jθ = cos θ – j sin θ are known as the Euler’s identi- • To convert a phasor from rectangular to exponential form. then A∗ = a – j b . then A ⋅ B = ac + jad + jbc – b d = ( ac – bd ) + j ( ad + bc ) • The conjugate of a phasor.= ------------------------------------. Thus. we use the expressions Ce Ce jθ = C cos θ + j C sin θ = C cos θ – j C sin θ – jθ • The polar form is essentially the same as the exponential form but the notation is different. For subtraction.( bc – ad ) ) A --. are equal if and only if their real parts are equal and also their imaginary parts are equal. • The rectangular form is most useful when we add or subtract phasors. If A = a + jb and B = c + jd . then A + B = ( a + c ) + j ( b + d ) and A – B = ( a – c ) + j ( b – d ) • Phasors are multiplied using the rules of elementary algebra.Summary • Two phasors A and B where A = a + jb and B = c + jd . Ce jθ = C ∠θ and it is important to remember that the phase angle θ is always measured with respect to the positive real axis.= ---------------------. a + jb ( a + jb ) ( c – jd ) ( ac + bd ) + j ( bc – ad ) ( ac + bd . and with an imaginary component of opposite sign. • The sum of two phasors has a real component equal to the sum of the real components. it is desirable to obtain the quotient separated into a real part and an imaginary part.= ------------. if A = a + jb and B = c + jd . This is achieved by multiplying the denominator by its conjugate. Thus. and an imaginary component equal to the sum of the imaginary components. Third Edition Copyright © Orchard Publications 3−25 . A = B if and only if a = c and b = d. Numerical Analysis Using MATLAB® and Excel®. Thus. Thus. if A = a + jb and B = c + jd . we change the signs of the components of the subtrahend and we perform addition. then.

Chapter 3 Sinusoids and Phasors • To multiply two phasors in exponential (or polar) form. we divide the magnitude of the dividend by the magnitude of the divisor.= ---. that is. we multiply the magnitudes and we add the phase angles. Third Edition Copyright © Orchard Publications . if A = M ∠θ and B = N ∠φ then. AB = MN ∠( θ + φ ) = M e jθ Ne jφ = MN e j(θ + φ ) • To divide one phasor by another when both are expressed in exponential or polar form.= ---.e N jφ N B Ne jθ 3−26 Numerical Analysis Using MATLAB® and Excel®.∠( θ – φ ) = -----------. if then. and we subtract the phase angle of the divisor from the phase angle of the dividend. that is. A = M ∠θ and B = N ∠φ M j(θ – φ) M Me A --.

( 2 – j4 ) ⋅ ( 3 + j5 ) f. 5. and check your answers with MATLAB. 22 + j6 8 + j6 120 ( 3 – j2 ) a. -----------------– 4 – j2 – 2 + j4 Check your answers with MATLAB. --------------------3 + j2 –3–j 4 – j10 ( 3 – j2 )∗ 3. -------------. ------------------– j30° 5 ∠– 150° – 2e j60° Check your answers with MATLAB 9 – j4 6. Perform the following operations.c.b. Any phasor A can be expressed as A = a + jb = r ( cos θ + j sin θ ) = re jθ Using the identities ( re ) = r e a. compute: 12 + j5 b.b. a.b. Find the real and imaginary components of -----------------– 5 + jx Numerical Analysis Using MATLAB® and Excel®. ---------------. ( 3 – j2 ) ⋅ ( – 2 – j3 ) g. and check your answers with MATLAB.d. Perform the following operations. ( 3 – j2 ) ⋅ ( 3 – j2 )∗ e. 4 100 2 ( 1 – j ) Check your answers with MATLAB 4. ( 2 – j4 ) ⋅ ( 3 + j5 ) ⋅ ( 3 – j2 ) ⋅ ( – 2 – j3 ) 2. ( 2 – j3 ) – ( 2 – j3 )∗ d.10 Exercises 1. ---------------------. ----------------. ---------------. Compute the exponential and polar forms of – 8 + j3 9 + j5a. ( – 3 + j5 ) – ( 1 + j6 ) c.Exercises 3. Compute the rectangular form of 4 ∠30° e a. Third Edition Copyright © Orchard Publications 3−27 . 6 jθ n jnθ or n re jθ = n re jθ ⁄ n . ( 2 – j4 ) + ( 3 + j4 ) b.

Check with MATLAB: (2−4j)+(3+4j).0000i ans = -3. (3−2j)*(−2−3j).. Third Edition Copyright © Orchard Publications .11 Solutions to End−of−Chapter Exercises 1. ( – 3 + j5 ) – ( 1 + j6 ) = – 4 – j c. (2−4j)*(3+5j)*(3−2j)*(−2−3j) ( 3 – j2 ) ⋅ ( – 2 – j3 ) = – 6 – j9 + j4 – 6 = – 12 – j5 ( 2 – j4 ) ⋅ ( 3 + j5 ) ⋅ ( 3 – j2 ) ⋅ ( – 2 – j3 ) = ( 6 + j10 – j12 + 20 ) ⋅ ( – 6 – j9 + j4 – 6 ) = ( 26 – j2 ) ⋅ ( – 12 – j5 ) = – 312 – j130 + j24 – 10 = – 322 – j106 ans = 5 ans = -4. ( 3 – j2 ) ⋅ ( 3 – j2 )∗ = ( 3 – j2 ) ⋅ ( 3 + j2 ) = 9 + j6 – j6 + 4 = 13 e.Chapter 3 Sinusoids and Phasors 3.1.5. (3−2j)*(3+2j).2200e+002 . g.0000i ans = -12. (−3+5j)−(1+6j).2.0000i ans = 0 . (2−4j)*(3+5j).0000 . a. (2−3j)−(2+3j).0000i ans = 13 ans = 26. ( 2 – j3 ) – ( 2 – j3 )∗ = ( 2 – j3 ) – ( 2 + j3 ) = 0 – j6 d. ( 2 – j4 ) + ( 3 + j4 ) = 5 + 0 = 5 b.0000 .1..0600e+002i 3−28 Numerical Analysis Using MATLAB® and Excel®.0000 .6. ( 2 – j4 ) ⋅ ( 3 + j5 ) = 6 + j10 – j12 + 20 = 26 – j2 f..

4 + j10 1200 120 -------c.⋅ ------------.53 + j0. ---------------.395 = 6 13 ⋅ e j0. (8+6j)/(−3−j).4485 × 1.3948 ⁄ 6 = 13 1⁄6 ⋅e j0. a.= 4802 + j1200 = 480 + j ⋅ ----------. -------------. 22 + j6 3 – j2 66 – j44 + j18 + 12 ---------------------------------a. 22 + j6 = ---------------.= – 30 – j10 = – 3 – j ----------------------2 2 –3–j –3–j –3+j 3 +1 10 300 120 .1i ans = 120/29 + 300/29i ans = 5/13 .0658 = 1. (100*sqrt(2)*(1−j))^(1/4) Numerical Analysis Using MATLAB® and Excel®.⋅ -------------.5334 ( cos 0.= 78 – j26 = 6 – j2 2 2 3 + j2 3 + j2 3 – j2 3 +2 13 8 + j6 – 3 + j – 24 + j8 – j18 – 6 8 + j6 b.= 120 + j ⋅ -----------------------------------------2 4 – j10 4 – j10 4 + j10 4 + 10 116 116 29 29 ( 3 – j2 ) ( 3 – j2 ) 12 ( 3 – j2 ) 5-----------------------------------------------d.12/13i 3.10 b.= -----------------.Solutions to End−of−Chapter Exercises 2.⋅ -----------------.6883 – j0.= -------------------------------------------.0658 + j sin 0. Third Edition Copyright © Orchard Publications 3−29 .0658 ) = 1. --------------------.= -------------.= ---------------------------------------------.= 9 – j6 – j6 – 4 = 5 – j12 = ----. 6 12 + j5 = 6 13e j0.= ---------------.0905 ) ( cos ( π ⁄ 16 ) – j sin ( π ⁄ 16 ) ) = 3. (3−2j)/(3+2j) ans = 6 .7337 Check with MATLAB: (12+5j)^(1/6). 4 100 2 ( 1 – j ) = 4 100 2 ⋅ 2e – jπ ⁄ 4 = ( 100 2 ⋅ 2e – jπ ⁄ 4 1 ⁄ 4 ) = ( 100 2 ) 1⁄4 ⋅ 2 1 ⁄ 4 – jπ ⁄ 16 e = ( 3.– j ⋅ ----2 2 ( 3 – j2 )∗ ( 3 + j2 ) ( 3 – j2 ) 3 +2 13 13 13 Check with MATLAB: 22+6j)/(3+2j).2i ans = -3 . 120/(4−10j).⋅ ---------------.

6883 . a.9105 ∠42.5 ( cos 90° + j sin 90° ) = – 0.3022e – j177.8789 5.= ---------------------------------.8 5 ∠– 150° e b. angle(y)*180/pi ans = 2.0981 9 + j5 9 +5 ⋅e 106 ⋅ e ----------------. – 2 + j4 2 +4 ⋅e = 1.= – 0. – j 3.3022 ans = -177.6052 – 4 – j2 2 2 j tan ( – 2 ⁄ – 4 ) 20 ⋅ e 4 +2 ⋅e 2 2 j tan ( 5 ⁄ 9 ) –1 j0.0.= 2. y=(−8+3j)/(−2+4j).9105e j42.9105 ans = 42.5081 ° –1 = 2.7337i 4.8744° Check with MATLAB: x=(9+5j)/(−4−2j)..3588 2 2 j tan ( 3 ⁄ – 8 ) 73 e j0. Third Edition Copyright © Orchard Publications .5 3−30 Numerical Analysis Using MATLAB® and Excel®.Chapter 3 Sinusoids and Phasors ans = 1. angle(x)*180/pi. 4 ∠30° ---------------------.1071 2 2 j tan ( 4 ⁄ – 2 ) 20 e b.5104 ans = 1.8744° = 1. a.7483 – 8 + j3 8 +3 ⋅e -----------------.5071 = 2.5301 + 0.. ------------------.5 ( 0 + j ) = – j0.5e – j30° – 2e j60° j90° = – 0.3022e –1 j3.= ----------------------------------------------------.= ------------------------------------------------------. abs(y).1008i ans = 3.3022 ∠– 177.= 1.9105e –1 – j1.= ( 4 ⁄ 5 ) ∠180° = – 0. abs(x).= --------.⋅ ----------------..5081 ° – j0.

.5000i 6..Solutions to End−of−Chapter Exercises Check with MATLAB: 4*(cos(pi/6)+sin(pi/6)*j)/(5*(cos(−5*pi/6)+sin(−5*pi/6)*j)).0000i ans = -0. Third Edition Copyright © Orchard Publications 3−31 . 9 – j4 – 5 – j x – 45 – j9x + j20 – 4x 9 – j4 – 4x – 45 – 9x + 20 -----------------.= -------------------------------------------------.⋅ -------------..8000 .= -----------------.0000 .+ j ---------------------2 2 2 2 – 5 + jx – 5 – j x – 5 + jx x + 25 5 +x x + 25 Numerical Analysis Using MATLAB® and Excel®.= ---------------------. exp(pi*j/3)/(−2*exp(−pi*j/6)) ans = -0.0.0.

1 Matrix Definition A matrix is a rectangular array of numbers such as those shown below. but are included for subject continuity. it is said to be a square matrix of order 5. the elements a 11. a 33. In a square matrix. Determinants. if a matrix has five rows and five columns. a 33. …. and j indicates the column in which each element is positioned. and Gauss’s elimination method are introduced. we say that the matrix elements a 11. are located on the main diagonal. Third Edition Copyright © Orchard Publications 4−1 . A matrix of m rows and n columns is said to be of m × n order matrix. the matrix is said to be a square matrix of order m (or n ). and reference to more advance topics in matrix theory. 2 3 7 1 –1 5 or 1 3 1 –2 1 –5 4 –7 6 In general form. Alternately. …. Some definitions and examples are not applicable to subsequent material presented in this text. These are denoted with a dagger ( † ) and may be skipped. Cramer’s rule. Thus. If m = n . Thus. a nn . a 22. 4. a matrix A is denoted as a 11 a 12 a 13 … a 1n a 21 a 22 a 23 … a 2n A = a 31 a 32 a 33 … a 3n … … … … … a m1 a m2 a m3 … a mn (4. Numerical Analysis Using MATLAB® and Excel®.Chapter 4 Matrices and Determinants T his chapter is an introduction to matrices and matrix operations. a 43 indicates the element positioned in the fourth row and third column. a nn are called the main diagonal elements.1) The numbers a ij are the elements of the matrix where the index i indicates the row. a22.

A+B % Define matrices A and B % Add A and B * Henceforth. A = B . all paragraphs and topics preceded by a dagger ( † ) may be skipped. if they are of the same order m × n. if and only if a ij = b ij i = 1. 4. C = A ± B = [ a ij ± b ij ] (4. 4−2 Numerical Analysis Using MATLAB® and Excel®.1 Compute A + B and A – B given that A = 1 2 3 and B = 2 3 0 0 1 4 –1 2 5 Solution: A+B = 1+2 0–1 2+3 1+2 3+0 = 3 5 4+5 –1 3 3 9 and A–B = 1–2 0+1 2 – 3 3 – 0 = –1 –1 3 1–2 4–5 1 –1 –1 Check with MATLAB: A=[1 2 3. These are discussed in matrix theory textbooks. B=[2 3 0.2) Two matrices are said to be conformable for addition (subtraction). 3 .3) Example 4. 2 . …. † A matrix in which every element is zero.Chapter 4 Matrices and Determinants † The sum of the diagonal elements of a square matrix A is called the trace* of A . where each element of C is the sum (difference) of the corresponding elements of A and B . n (4. …. 3. m j = 1 .2 Matrix Operations Two matrices A = a ij and B = b ij are equal. that is. 0 1 4]. is called a zero matrix. −1 2 5]. 2. their sum (difference) will be another matrix C with the same order as A and B . that is. Third Edition Copyright © Orchard Publications . If A = a ij and B = b ij are conformable for addition (subtraction).

Third Edition Copyright © Orchard Publications 4−3 . k1*A % Define scalars k1 and k2 % Define matrix A % Multiply matrix A by constant k1 ans = 5 10 k2*A -10 15 %Multiply matrix A by constant k2 Numerical Analysis Using MATLAB® and Excel®. then multiplication of a matrix A by the scalar k . k2=(−3 + 2*j). A=[1 −2. and not [ k ] which is a 1 × 1 matrix. k 1 ⋅ A = 5 × 1 – 2 = 5 × 1 5 × ( – 2 ) = 5 – 10 2 3 5×2 5×3 10 15 b.2 Multiply the matrix A = 1 –2 2 3 by (a) k 1 = 5 and (b) k 2 = – 3 + j2 Solution: a.Matrix Operations ans = 3 -1 A−B 5 3 3 9 % Subtract B from A ans = -1 1 -1 -1 3 -1 If k is any scalar (a positive or negative number). is the multiplication of every element of A by k . 2 3]. Example 4. k 2 ⋅ A = ( – 3 + j2 ) × 1 – 2 = ( – 3 + j2 ) × 1 ( – 3 + j2 ) × ( – 2 ) = – 3 + j2 2 3 ( – 3 + j2 ) × 2 ( – 3 + j2 ) × 3 – 6 + j4 6 – j4 – 9 + j6 Check with MATLAB: k1=5.

0000+ 2. then. A convenient way to determine if two matrices are conformable for multiplication is to write the dimensions of the two matrices side−by−side as shown below. That is. we add these products.0000+ 6. Third Edition Copyright © Orchard Publications .0000. only when the number of columns of matrix A is equal to the number of rows of matrix B . to obtain the product A ⋅ B . The product A ⋅ B will then be an m × n matrix. we multiply each element of a row of A by the corresponding element of a column of B .0000i -6. Shows that A and B are conformable for multiplication A m×p B p×n Indicates the dimension of the product A ⋅ B For the product B ⋅ A we have: Here.4. Example 4. the operation is row by column.0000i -9.3 Given that 1 C = 2 3 4 and D = – 1 2 compute the products C ⋅ D and D ⋅ C Solution: The dimensions of matrices C and D are respectively 1 × 3 3 × 1 . therefore the product C ⋅ D is 4−4 Numerical Analysis Using MATLAB® and Excel®. Thus.0000i Two matrices A and B are said to be conformable for multiplication A ⋅ B in that order.0000i 6. the product A ⋅ B (but not B ⋅ A ) is conformable for multiplication only if A is an m × p and matrix B is an p × n matrix.Chapter 4 Matrices and Determinants ans = -3.0000+ 4. B and A are not conformable for multiplication B p×n A m×p For matrix multiplication.

Special Forms of Matrices feasible. 1 D ⋅ C = –1 2 3 4 = 2 (1) ⋅ (2) (1) ⋅ (3) (1) ⋅ (4) ( –1 ) ⋅ ( 2 ) ( –1 ) ⋅ ( 3 ) ( –1 ) ⋅ ( 4 ) (2) ⋅ (2) (2) ⋅ (3) (2) ⋅ (4) 2 3 4 = –2 –3 –4 4 6 8 Check with MATLAB: C=[2 3 4]. the product D ⋅ C is also feasible. a 11 a 12 a 13 … a 1n A = 0 a 22 a 23 … a 2n 0 0 … … … … … 0 … … 0 0 0 … a mn (4.3 Special Forms of Matrices † A square matrix is said to be upper triangular when all the elements below the diagonal are zero. The matrix A below is an upper triangular matrix. is not defined. when we discuss the inverse of a matrix. that is. Third Edition Copyright © Orchard Publications 4−5 .4) Numerical Analysis Using MATLAB® and Excel®. D=[1. and it will become apparent later in this chapter. 1 C ⋅ D = 2 3 4 –1 = ( 2 ) ⋅ ( 1 ) + ( 3 ) ⋅ ( –1 ) + ( 4 ) ⋅ ( 2 ) = 7 2 The dimensions for D and C are respectively 3 × 1 1 × 3 and therefore. 2]. Multiplication of these will produce a 3 × 3 matrix as follows. 4. and will result in a 1 × 1 . an equivalent operation exists. However. C*D % Define matrices C and D % Multiply C by D ans = 7 D*C % Multiply D by C ans = 2 -2 4 3 -3 6 4 -4 8 Division of one matrix by another. −1.

For example. Shown below are 2 × 2 . if a 11 = a 22 = a 33 = … = a nn = k where k is a scalar. For applications. if all elements are zero. when all the elements above the diagonal are zero. 3 × 3 . except those in the diagonal. and 4 × 4 identity matrices. For applications.7) A scalar matrix with k = 1 . not all elements below the diagonal need to be non−zero. † A square matrix is said to be lower triangular. The matrix C below is a diagonal matrix. The matrix B below is a lower triangular matrix. a 11 0 C = 0 0 0 0 … 0 0 a 22 0 … 0 0 … 0 0 0 0 … 0 0 0 … a mn (4. is called an identity matrix I . a 11 B = 0 0 … 0 0 … 0 a 21 a 22 … … … 0 0 … … … … 0 a m1 a m2 a m3 … a mn (4.8) The MATLAB eye(n) function displays an n × n identity matrix.Chapter 4 Matrices and Determinants In an upper triangular matrix. refer to Chapter 14. refer to Chapter 14. Third Edition Copyright © Orchard Publications .6) † A diagonal matrix is called a scalar matrix. 4−6 Numerical Analysis Using MATLAB® and Excel®.5) In a lower triangular matrix. † A square matrix is said to be diagonal. not all elements above the diagonal need to be non−zero. 1 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 1 (4. 4 D = 0 0 0 0 4 0 0 0 0 4 0 0 0 0 4 (4. The matrix D below is a scalar matrix with k = 4 .

denoted as A . 4 5 6] % Define matrix A A = 1 4 2 5 3 6 Numerical Analysis Using MATLAB® and Excel®. Thus. For example. is the matrix that is obtained when the rows and columns of matrix A are interchanged. let A be defined as A=[1 3 1.9) In MATLAB we use the apostrophe (′) symbol to denote and obtain the transpose of a matrix. −2 1 −5. produces an identity matrix whose size is the same as matrix A . A=[1 2 3. the eye(size(A)) function. For example. Third Edition Copyright © Orchard Publications 4−7 .Special Forms of Matrices eye(4)% Display a 4 by 4 identity matrix ans = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 Likewise. if 1 1 2 3 then A T = 2 4 5 6 3 4 5 6 A= (4. 4 −7 6] % Define matrix A A = 1 -2 4 then. for the above example. eye(size(A)) 3 1 -7 1 -5 6 displays ans = 1 0 0 0 1 0 0 0 1 T † The transpose of a matrix A .

0 2 –3 A = –2 0 –4 3 4 0 0 –2 A = 2 0 –3 –4 T 3 4 = –A 0 4−8 Numerical Analysis Using MATLAB® and Excel®.0000i 3. For example. conj(x).0000 + 2. is called the conjugate of A . 1 2 3 2 4 –5 3 –5 6 1 2 3 2 4 –5 = A 3 –5 6 A = A = T (4.0000 0 .0000 .10) † If a matrix A has complex numbers as elements.0000 + 3. The first. computes the conjugate of a matrix A . Using MATLAB with the matrix A defined as above. Third Edition Copyright © Orchard Publications .0000 conj_A=conj(A) 0 + 1.0000i 3.0000i 2. is one such that A = A .1.0000 . 3 2−3j] % Define and display matrix A A = 1.3. the transpose of a matrix A is the same as A . An example of a symmetric matrix is shown below. conj(A).2. we obtain A = [1+2j j. the matrix obtained from A by replacing each element by its conjugate. that is.0000i % Compute and display the conjugate of A conj_A = 1.0000i T † A square matrix A such that A = – A . and it is denoted as A∗ . An example is shown below. and the second. is called skew−symmetric. computes the complex conjugate of any complex number.Chapter 4 Matrices and Determinants A'% Display the transpose of A ans = 1 2 3 4 5 6 T † A symmetric matrix A . A = 1 + j2 3 j 2 – j3 A∗ = 1 – j2 3 –j 2 + j3 † MATLAB has two built−in functions which compute the complex conjugate of a number.0000i 2.

denoted as detA . that is. A = a 11 a 12 a 21 a 22 (4. –1–j 3j j –2 –j T* j A = 1+j 0 2 –1+j – 3j –j –2 –j = –A 0 j 2 T j A = 1–j 2 0 Therefore. 1+j 3 j 2 1 T* A = 1–j –j 0 2 1+j 3 j 2 –j = A 0 2 1 T A = 1–j j 0 2 Therefore. matrix A above is skew−Hermitian. † A square matrix A such that A j A = –1–j –2 1–j 3j j T∗ = – A .Determinants Therefore. is defined as detA = a 11 a 22 a 33 …a nn + a 12 a 23 a 34 …a n 1 + a 13 a 24 a 35 …a n 2 + … – a n 1 …a 22 a 13 … – a n 2 …a 23 a 14 – a n 3 …a 24 a 15 – … The determinant of a square matrix of order n is referred to as determinant of order n . is called skew−Hermitian.11) then. † A square matrix A such that A 1 A = 1+j 2 1–j 3 –j T∗ = A . For example. For example.13) Numerical Analysis Using MATLAB® and Excel®.4 Determinants Let matrix A be defined as the square matrix a 11 a 12 a 13 … a 1n a 21 a 22 a 23 … a 2n A = a a a …a 31 32 33 3n … … … … … a n1 a n2 a n3 … a nn (4. the determinant of A . matrix A above is Hermitian. Third Edition Copyright © Orchard Publications 4−9 . matrix A above is skew symmetric. is called Hermitian.12) (4. Let A be a determinant of order 2 . 4.

Page 16−3. please refer to Introduction to Simulink with Engineering Applications. B=[2 −1. % This file computes the determinant of a 2x2 matrix % It must be saved as function (user defined) file % det2x2.14) Example 4. % function y=det2x2(A). * For an example using this block.4 Given that A = 1 2 and B = 2 – 1 3 4 2 0 compute detA and detB . 4−10 Numerical Analysis Using MATLAB® and Excel®. It is highly recommended that this % function file is created in MATLAB's Editor Window. ISBN 0−9744239−7−1. Third Edition Copyright © Orchard Publications . 3 4]. Make sure % that his directory is added to MATLAB's search % path accessed from the Editor Window as File>Set Path> % Add Folder. det(A) ans = -2 det(B) % Compute the determinant of B ans = 2 While MATLAB has the built−in function det(A) for computing the determinant of a matrix A.* The MATLAB user−defined function file below can be used to compute the determinant of a 2 × 2 matrix. detA = a 11 a 22 – a 21 a 12 (4.m in the current Work Directory. this function is not included in the MATLAB Run−Time Function Library List that is used with the Simulink Embedded MATLAB Function block. Solution: detA = 1 ⋅ 4 – 3 ⋅ 2 = 4 – 6 = – 2 detA = 2 ⋅ 0 – 2 ⋅ ( – 1 ) = 0 – ( – 2 ) = 2 % Define matrices A and B % Compute the determinant of A Check with MATLAB: A=[1 2. 2 0].Chapter 4 Matrices and Determinants Then.

a 11 a 12 a 13 A = a 21 a 22 a 23 a 31 a 32 a 33 (4.2)−A(1.] and then % type det2x2(A) at the command prompt.1)*A(2. % % To run this program.. To evaluate higher order determinants. we obtain (4.16) A convenient method to evaluate the determinant of order 3.2)*A(2..15) then. When this is done properly.16) above. a 11 a 12 a 13 a 11 a 12 a 21 a 22 a 23 a 21 a 22 a 31 a 32 a 33 a 31 a 32 − + This method works only with second and third order determinants. detA is found from detA = a 11 a 22 a 33 + a 12 a 23 a 31 + a 11 a 22 a 33 – a 11 a 22 a 33 – a 11 a 22 a 33 – a 11 a 22 a 33 (4. that is.. we must first compute the cofactors. define the 2x2 matrix in % MATLAB's Command Window as A=[. Let A be a matrix of order 3. and add the products formed by the diagonals from upper left to lower right. these will be defined shortly.Determinants y=A(1.1).5 Compute detA and detB given that 2 A = 1 2 3 5 0 1 1 0 2 –3 –4 0 –2 0 –5 –6 and B = 1 Solution: Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications 4−11 . Example 4. then subtract the products formed by the diagonals from lower left to upper right as shown on the diagram of the next page. is to write the first two columns to the right of the 3 × 3 matrix.

1)*A(3..3)−A(3. y=A(1.2)*A(1. det(A) ans = 9 B=[2 −3 −4. % function y=det3x3(A)..1)*A(2. detA = ( 2 × 0 × 0 ) + ( 3 × 1 × 1 ) + ( 5 × 1 × 1 ) – ( 2 × 0 × 5 ) – ( 1 × 1 × 2 ) – ( 0 × 1 × 3 ) = 11 – 2 = 9 2 –3 –4 2 –3 detB = 1 0 – 2 1 – 2 0 –5 –6 2 –6 detB = [ 2 × 0 × ( – 6 ) ] + [ ( – 3 ) × ( – 2 ) × 0 ] + [ ( – 4 ) × 1 × ( – 5 ) ] – [ 0 × 0 × ( – 4 ) ] – [ ( – 5 ) × ( – 2 ) × 2 ] – [ ( – 6 ) × 1 × ( – 3 ) ] = 20 – 38 = – 18 or Check with MATLAB: A=[2 3 5. 2 1 0]. define the 3x3 matrix in % MATLAB's Command Window as A=[.] and then % type det3x3(A) at the command prompt. Make sure % that his directory is added to MATLAB's search % path accessed from the Editor Window as File>Set Path> % Add Folder.3)*A(2. 1 0 1.3)+A(1.Chapter 4 Matrices and Determinants 2 detA = 1 2 3 5 2 3 0 1 1 0 1 0 2 1 or Likewise.1)+A(1.m in the current Work Directory. It is highly recommended that this % function file is created in MATLAB's Editor Window.3)*A(1.2)*A(2.1)*A(2..2)*A(2. % This file computes the determinant of a 3x3 matrix % It must be saved as function (user defined) file % det3x3.2)*A(3.1)*A(1. % % To run this program. −A(3.2).3)*A(3.3)*A(2.2). 4−12 Numerical Analysis Using MATLAB® and Excel®..1)−A(3. 1 0 −2.. Third Edition Copyright © Orchard Publications . det(B) % Define matrix B and compute detB % Define matrix A and compute detA ans = -18 The MATLAB user−defined function file below can be used to compute the determinant of a 3 × 3 matrix. 0 −5 −6].

M 22 .17) If we remove the elements of its ith row. the determinant of the remaining n – 1 square matrix is called the minor of determinant A . M 31 . and jth column. M 33 and cofactors Numerical Analysis Using MATLAB® and Excel®.5 Minors and Cofactors Let matrix A be defined as the square matrix of order n as shown below. and it is denoted as M ij . M 13 and the cofactors α 11 . Example 4. The signed minor ( – 1 ) i+j M ij is called the cofactor of a ij and it is denoted as α ij . M 12 = a 21 a 23 a 31 a 33 M 11 = a 21 a 22 a 31 a 32 and α 11 = ( – 1 ) 1+1 M 11 = M 11 α 12 = ( – 1 ) 1+2 M 12 = – M 12 α 13 = M 13 = ( – 1 ) 1+3 M 13 The remaining minors M 21 . M 32 .6 Given that a 11 a 12 a 13 A = a 21 a 22 a 23 a 31 a 32 a 33 (4. α 12 and α 13 .18) compute the minors M 11 .Minors and Cofactors 4. a 11 a 12 a 13 … a 1n a 21 a 22 a 23 … a 2n A = a a a … a 31 32 33 3n … … … … … a n1 a n2 a n3 … a nn (4. Solution: M 11 = a 22 a 23 a 32 a 33 M 12 . M 23 . Third Edition Copyright © Orchard Publications 4−13 .

the value of the determinant of A is the sum of the products obtained by multiplying each element of any row or any column by its cofactor.Chapter 4 Matrices and Determinants α 21. Solution: α 11 = ( – 1 ) 1+1 – 4 2 = 20 2 –6 1+3 α 12 = ( – 1 ) 1+2 2 2 = 10 –1 –6 2+1 (4. α 32. α 23.24) It is useful to remember that the signs of the cofactors follow the pattern + − − + + − − + + − + − − + + − − + + − + − + − + that is.19) compute its cofactors. α 22. –4 2 α 32 = ( – 1 ) 3+2 1 – 3 = –8 2 2 (4.20) α 13 = ( – 1 ) 2 –4 = 0 –1 2 1 –3 = –9 –1 –6 α 21 = ( – 1 ) 2 –3 = 6 2 –6 1 2 = –4 –1 2 (4. Example 4. 4−14 Numerical Analysis Using MATLAB® and Excel®.22) α 31 = ( – 1 ) 3+1 2 – 3 = – 8.7 Given that 1 2 –3 A = 2 –4 2 –1 2 –6 (4.21) α 22 = ( – 1 ) 2+2 α 23 = ( – 1 ) 2+3 (4. Third Edition Copyright © Orchard Publications . α 31. and α 33 are defined similarly. Let A be a square matrix of any size.23) α 33 = ( – 1 ) 3+3 1 2 = –8 2 –4 (4. the cofactors on the diagonals have the same sign as their minors.

25) Solution: detA = 1 – 4 2 – 2 2 2 – 3 2 – 4 = 1 × 20 – 2 × ( – 10 ) – 3 × 0 = 40 2 –6 –1 –6 –1 2 Check with MATLAB: A=[1 2 −3.8 Compute the determinant of A using the elements of the first row.26) +a 31 a 22 a 23 a 24 – a 41 a 22 a 23 a 24 Determinants of order five or higher can be evaluated similarly. a 11 a 12 a 13 a 14 A = a 21 a 22 a 23 a 24 a 31 a 32 a 33 a 34 a 41 a 42 a 43 a 44 a 22 a 23 a 24 a 42 a 43 a 44 a 12 a 13 a 14 a 42 a 43 a 44 a 12 a 13 a 14 = a 11 a 32 a 33 a 34 – a 21 a 32 a 33 a 34 a 42 a 43 a 44 a 12 a 13 a 14 a 32 a 33 a 34 (4. Third Edition Copyright © Orchard Publications 4−15 . −1 2 −6]. A = 1 2 –3 2 –4 2 –1 2 –6 (4.9 Compute the value of the determinant Numerical Analysis Using MATLAB® and Excel®.Minors and Cofactors Example 4. We must use the above procedure to find the determinant of a matrix A of order 4 or higher. a fourth−order determinant can first be expressed as the sum of the products of the elements of its first row by its cofactor as shown below. det(A) % Define matrix A and compute detA ans = 40 The MATLAB user−defined function file below can be used to compute the determinant of a 4 × 4 matrix. Example 4. Thus. 2 −4 2.

% The following statement defines the size of the matrix A [n. −3 0 0 1]. % This file computes the determinant of a nxn matrix % It must be saved as function (user defined) file % detnxn. % and det3x3(A) for a 3x3 matrix. delta = det(A) delta = -33 The MATLAB user−defined function file below can be used to compute the determinant of a n × n matrix.8. Then. % function y=detnxn(A). we will multiply each element of the first column by its cofactor. [ b ] = – 3 . It is highly recommended that this % function file is created in MATLAB's Editor Window. Make sure % that his directory is added to MATLAB's search % path accessed from the Editor Window as File>Set Path> % Add Folder.n]=size(A). % MATLAB allows us to use the user-defined functions to be recursively % called on themselves so we can call det2x2(A) for a 2x2 matrix. 1 0 –1 A=2 0 3 – 2 0 0 1 [a] –1 0 –3 –( –1 ) 0 3 –2 0 0 1 [b] –1 0 – 3 +4 1 0 – 1 0 0 1 [c] –1 0 – 3 –( –3 ) 1 0 – 1 0 3 –2 [d] ⎧ ⎪ ⎪ ⎨ ⎪ ⎪ ⎩ ⎧ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎩ Next. we find and thus [ a ] = 6 . 4 0 3 −2.m in the current Work Directory. Third Edition Copyright © Orchard Publications ⎧ ⎪ ⎪ ⎨ ⎪ ⎪ ⎩ ⎧ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎩ . using the procedure of Example 4. [ d ] = – 36 detA = [ a ] + [ b ] + [ c ] + [ d ] = 6 – 3 + 0 – 36 = – 33 We can verify our answer with MATLAB as follows: A=[ 2 −1 0 −3. % The following statement initializes y y=0. 4−16 Numerical Analysis Using MATLAB® and Excel®.5 or Example 4. −1 1 0 −1.27) Solution: Using the above procedure. [ c ] = 0 .Chapter 4 Matrices and Determinants 2 –1 0 A = –1 1 0 4 0 3 –3 0 0 –3 –1 –2 1 (4.

. det(A) ans = 0 Numerical Analysis Using MATLAB® and Excel®. 1 2 1]. detA is zero because the second column in A is 2 times the first column. Property 1: If all elements of one row or one column are zero. define the nxn matrix in % MATLAB's Command Window as A=[.. if 2 A = 3 1 4 6 2 1 1 1 (4. Third Edition Copyright © Orchard Publications 4−17 . return end % For 4x4 or higher order matrices we use the following: % (We can define n and matrix A in Command Window for i=1:n y=y+(−1)^(i+1)*A(1. An example of this is the determinant of the cofactor [ c ] above.28) then.Minors and Cofactors if n==2 y=det2x2(A). detA = 2 3 1 4 6 2 1 1 1 2 3 1 4 6 = 12 + 4 + 6 – 6 – 4 – 12 = 0 2 (4. 3 6 1. the determinant is zero. Some useful properties of determinants are given below.i)*detnxn(A(2:n. return end % if n==3 y=det3x3(A).. the determinant is zero. [1:(i−1) (i+1):n])). end % % To run this program.] and then % type detnxn(A) at the command prompt.29) Here. For example. Property 2: If all the elements of one row or column are m times the corresponding elements of another row or column. Check with MATLAB: A=[2 4 1.

6 Cramer’s Rule Let us consider the systems of the three equations below a 11 x + a 12 y + a 13 z = A a 21 x + a 22 y + a 23 z = B a 31 x + a 32 y + a 33 z = C (4. and D 3 are all zero as we found in Property 1 above. D 2.30) is a homogeneous set of equations. v 2.10 Use Cramer’s rule to find v 1. and C. Then. 4. and z can be found from the relations D1 x = ----- Δ D2 y = ----- Δ D3 z = ----- Δ (4. B. then. for the coefficients of the desired unknown. Example 4. Cramer’s rule applies to systems of two or more equations. and v 3 if 2v 1 – 5 – v 2 + 3v 3 = 0 – 2v 3 – 3v 2 – 4v 1 = 8 v 2 + 3v 1 – 4 – v 3 = 0 (4. This follows from Property 2 with m = 1 . D 1. the determinant is zero. If (4.Chapter 4 Matrices and Determinants Property 3: If two rows or two columns of a matrix are identical. x = y = z = 0 also. that is.31) provided that the determinant Δ (delta) is not zero. if A = B = C = 0 . y .30) and let Δ a 11 a 12 a 13 = a 21 a 22 a 23 a 31 a 32 a 33 D1 = A a 11 a 13 B a 21 a 23 C a 31 a 33 D2 = a 11 A a 13 a 21 B a 23 a 31 C a 33 D3 = a 11 a 12 A a 21 a 22 B a 31 a 32 C Cramer’s rule states that the unknowns x . We observe that the numerators of (4. Third Edition Copyright © Orchard Publications .31) are determinants that are formed from Δ by the substitution of the known values A.32) and verify your answers with MATLAB. 4−18 Numerical Analysis Using MATLAB® and Excel®.

% Compute the determinant D of B d1=[5 −1 3. % Compute the determinant of D1 d2=[2 5 3. 3 4 −1].Cramer’s Rule Solution: Rearranging the unknowns v . % Compute he determinant of D3 Numerical Analysis Using MATLAB® and Excel®.31) we obtain D1 85 17 x 1 = ----.34) We will verify with MATLAB as follows. 4 1 −1]. 3 1 −1].33) Now.= ----. % The elements of D2 detd2=det(d2). Third Edition Copyright © Orchard Publications 4−19 . and transferring known values to the right side.= – ----.= – ----35 7 Δ D3 55 11 x 3 = ----.= – -------. −4 8 −2. Δ = 2 –1 3 –4 –3 –2 3 1 –1 5 –1 3 8 –3 –2 4 1 –1 2 –4 3 5 3 8 –2 4 –1 5 8 4 2 –1 – 4 – 3 = 6 + 6 – 12 + 27 + 4 + 4 = 35 3 1 5 –1 8 – 3 = 15 + 8 + 24 + 36 + 10 – 8 = 85 4 1 2 –4 3 5 8 = – 16 – 30 – 48 – 72 + 16 – 20 = – 170 4 D1 = D2 = D3 = 2 –1 –4 –3 3 1 2 –1 – 4 – 3 = – 24 – 24 – 20 + 45 – 16 – 16 = – 55 3 1 Therefore. using (4. % The elements of D1 detd1=det(d1). 3 1 4]. % Compute the determinant of D2 d3=[2 −1 5. we obtain 2v 1 – v 2 + 3v 3 = 5 – 4v 1 – 3v 2 – 2v 3 = 8 3v 1 + v 2 – v 3 = 4 (4. −4 −3 8. −4 −3 −2. % The elements of the determinant D delta=det(B).= – ----35 7 Δ (4. % The following script will compute and display the values of v1. format rat % Express answers in ratio form B=[2 −1 3. % The elements of D3 detd3=det(d3). by Cramer’s rule.= ----35 7 Δ D2 170 34 x 2 = ----. 8 −3 −2. v2 and v3.

This procedure is repeated until all unknowns are found. With this method. % disp('v1=').11 Use the Gaussian elimination method to find v 1. v3=detd3/delta.disp(v2). and v 3 of 2v 1 – v 2 + 3v 3 = 5 – 4v 1 – 3v 2 – 2v 3 = 8 3v 1 + v 2 – v 3 = 4 (4. Example 4. we can find the second unknown. by substitution to another equation with two unknowns.35) with the third to eliminate the unknown v 2 and we obtain the following equation. % Compute the value of v1 % Compute the value of v2 % Compute the value of v3 % Display the value of v1 % Display the value of v2 % Display the value of v3 v1= 17/7 v2= -34/7 v3= -11/7 These are the same values as in (4. v2=detd2/delta. disp('v3='). we add the first equation of (4.disp(v1). Subsequently. the objective is to eliminate one unknown at a time.35) Solution: As a first step. 4−20 Numerical Analysis Using MATLAB® and Excel®.34) 4. disp('v2=').7 Gaussian Elimination Method We can find the unknowns in a system of two or more equations also by the Gaussian elimination method. v 2. Third Edition Copyright © Orchard Publications . Then.disp(v3). This method is best illustrated with the following example which consists of the same equations as the previous example.Chapter 4 Matrices and Determinants v1=detd1/delta. This can be done by multiplying the terms of any of the equations of the system by a number such that we can add (or subtract) this equation to another equation in the system so that one of the unknowns will be eliminated. substitution of the two values found can be made into an equation with three unknowns from which we can find the value of the third unknown.

Numerical Analysis Using MATLAB® and Excel®.37).38) Now.= – ----7 7 7 7 (4. 4.36) or (4. we can find the last unknown v 2 from any of the three equations of (4. However. The Gaussian elimination is further discussed in Chapter 14 in conjunction with the LU factorization method.38) into (4.10.– ----.36) Next. we multiply the third equation of (4.36) yields 11 7v 3 = – 11 or v 3 = – ----7 (4.– ----. and we add it with the second to eliminate v 2 . we can find the unknown v 1 from either (4. as in Example 4.39) Finally.11.37) Subtraction of (4.35). The Gaussian elimination method works well if the coefficients of the unknowns are small integers.35) by 3. denoted as adjA . is defined as the n square matrix shown on the next page.The Adjoint of a Matrix 5v 1 + 2v 3 = 9 (4. Then. we obtain the following equation. By substitution of (4.40) These are the same values as those we found in Example 4.37) from (4. By substitution into the first equation we obtain 34 33 35 34 v 2 = 2v 1 + 3v 3 – 5 = ----. Third Edition Copyright © Orchard Publications 4−21 . Then the adjoint of A .8 The Adjoint of a Matrix Let us assume that A is an n square matrix and α ij is the cofactor of a ij . it becomes impractical if the coefficients are large or fractional numbers. 5v 1 – 5v 3 = 20 (4.36) we obtain --------5v 1 + 2 ⋅ ⎛ – 11 ⎞ = 9 or v 1 = 17 ⎝ 7 ⎠ 7 (4.

Third Edition Copyright © Orchard Publications . A is called non−singular. if the determinant of that matrix is very small. if detA ≠ 0 .12 Compute adjA given that 1 2 3 A = 1 3 4 1 4 3 (4. If an n square matrix A is nearly singular. are the elements of the ith column (row) of adjA . Example 4.Chapter 4 Matrices and Determinants α 11 α 21 α 31 … α n1 α 12 α 22 α 32 … α n2 adjA = α α α … α 13 23 33 n3 … … … … … α 1n α 2n α 3n … α nn (4. This topic is discussed in Appendix C.42) Solution: 3 4 adjA = – 1 1 1 1 4 3 4 3 3 4 – 2 4 1 1 3 3 3 3 2 3 3 4 – 2 3 3 4 = –7 6 –1 1 0 –1 1 –2 1 – 1 2 1 4 1 2 1 3 4.13 Given that 4−22 Numerical Analysis Using MATLAB® and Excel®. Example 4.41) We observe that the cofactors of the elements of the ith row (column) of A . the matrix is said to be ill−conditioned.9 Singular and Non−Singular Matrices An n square matrix A is called singular if detA = 0 . that is.

matrix A is singular.44). A = B –1 If a matrix A is non−singular. denoted as B = A–1 . that is.12. From Example 4.44) Example 4.14 Given that 1 2 3 A = 1 3 4 1 4 3 (4. and likewise. Numerical Analysis Using MATLAB® and Excel®. where I is the identity matrix. that is. we can compute its inverse from the relation A –1 1 = ----------.The Inverse of a Matrix 1 A = 2 3 2 3 3 4 5 7 (4. B is called the inverse of A . Solution: detA = 1 2 3 2 3 3 4 5 7 1 2 2 3 = 21 + 24 + 30 – 27 – 20 – 28 = 0 3 5 Therefore.45) compute its inverse. and since this is a non−zero value. detA = 9 + 8 + 12 – 9 – 16 – 6 = – 2 . 4. find A–1 Solution: Here. it is possible to compute the inverse of A using (4.43) determine whether this matrix is singular or non−singular.10 The Inverse of a Matrix If A and B are n square matrices such that AB = BA = I .adjA detA (4. Third Edition Copyright © Orchard Publications 4−23 . A is called the inverse of B .

5 0 0.47) Example 4.47) for A = 4 2 3 2 2 –3 –2 4 Proof: detA = 8 – 6 = 2 and adjA = Then.5000 0. Third Edition Copyright © Orchard Publications .5 (4.5 –2 detA 1 –2 1 – 0.5 1 – 0.Chapter 4 Matrices and Determinants adjA = –7 6 –1 1 0 –1 1 –2 1 Then.5000 -0.5000 -0.15 Prove the validity of (4. AA –1 = I or A A = I –1 (4.0000 0.5000 Multiplication of a matrix A by its inverse A–1 produces the identity matrix I .adjA = ----.46) Check with MATLAB: A=[1 2 3.2 – 3 = 2 –2 4 detA –1 2 and 4−24 Numerical Analysis Using MATLAB® and Excel®.5 1 1 = ----------.1 0 – 1 = – 0.adjA = -. that is. 1 4 3]. A –1 –7 6 –1 3.5000 -0.5 – 3 0.0000 0 1. 1 3 4. A –1 1 1 1 –3 ⁄ 2 = ----------.5000 2 3 4 3 4 3 -3. invA=inv(A) % Define matrix A and compute its inverse A = 1 1 1 invA = 3.

16 Given the system of equations ⎧ 2x 1 + 3x 2 + x 3 = 9 ⎫ ⎪ ⎪ ⎨ x 1 + 2x 2 + 3x 3 = 6 ⎬ ⎪ ⎪ ⎩ 3x 1 + x 2 + 2x 3 = 8 ⎭ (4.49) (4. we can use (4. Solution: In matrix form. the given set of equations is AX = B where 2 A= 1 3 x1 3 1 9 . We assume that A and X are conformable for multiplication.48) where A and B are matrices whose elements are known.52) Then.50) or X=A B –1 Therefore.11 Solution of Simultaneous Equations with Matrices Consider the relation AX = B (4. Numerical Analysis Using MATLAB® and Excel®. We will refer to this method as the inverse matrix method of solution of simultaneous equations.50) to solve any set of simultaneous equations that have solutions. and X is a matrix (a column vector) whose elements are the unknowns. Third Edition Copyright © Orchard Publications 4−25 .Solution of Simultaneous Equations with Matrices AA –1 = 4 2 3 1 –3 ⁄ 2 = 4 – 3 2 –1 2 2–2 –6+6 = 1 –3+4 0 0 = I 1 4. X = x2 . B = 6 2 3 1 2 8 x3 (4. Multiplication of both sides of (4. Example 4. and x 3 using the inverse matrix method.51) compute the unknowns x 1. x 2.48) by A–1 yields: A AX = A B = IX = A B –1 –1 –1 (4.

53) –1 or x1 x2 x3 2 = 1 3 3 1 2 3 1 2 9 6 8 (4. For this % Observe that B is a column vector –1 A=[2 3 1. and the adjoint adjA .2778 As stated earlier.61 18 18 5 ⁄ 18 0.29 = 29 ⁄ 18 = 1. we could use the MATLAB inv(A) function. this function is not included in the MATLAB Run−Time Function Library List that is used with the Simulink Embedded MATLAB Function block. 1.Chapter 4 Matrices and Determinants X = A B –1 (4.54) Next.55) To verify our results.7 1 – 5 18 detA –5 7 1 and by (4. The MATLAB user− defined function file below can be used to compute the determinant of a 2 × 2 matrix. we find the determinant detA . where matrix X is the same size as matrix B . A B for the matrix equation A ⋅ X = B . X=A \ B 4−26 Numerical Analysis Using MATLAB® and Excel®.28 –5 7 1 8 5 x3 x1 (4. 3 1 2].53) we obtain the solution as follows. 1 2 3. A userdefined function to compute the inverse of an n × n is presented in Chapter 14. B=[9 6 8]'.adjA = ----. X = 1.94 1 –5 7 9 35 35 ⁄ 18 1 1 X = x 2 = ----.6111 0. However. this is MATLAB’s solution of example. 1 –5 7 detA = 18 and adjA = 7 1 – 5 –5 7 1 Therefore.9444 1.7 1 – 5 6 = ----. Third Edition Copyright © Orchard Publications . and multiply A–1 by B . while MATLAB has the built−in function det(A) for computing the determinant of a matrix A. A –1 1 –5 7 1 1 = ----------. it is easier to use the matrix left division operation X = A \ B .

17 For the electric circuit of Figure 4. where 10 – 9 0 100 R = – 9 20 – 9 .1.58) Then. the mesh equations are 1Ω 2Ω 9Ω 2Ω 9Ω 4Ω − I 1 V = 100 v + I2 I3 Figure 4.1.56) Use the inverse matrix method to compute the values of the currents I 1. This is found from the relation R –1 1 = ----------. and I 3 . R –1 219 135 81 1 1 = ----------. the matrix equation is RI = V or I = R–1 V . V = 0 0 – 9 15 0 I1 and I = I 2 I3 The next step is to find R–1 .Solution of Simultaneous Equations with Matrices Example 4.17 10I 1 – 9I 2 = 100 0 0 – 9I 1 + 20I 2 – 9I 3 = – 9I 2 + 15I 3 = (4. adjR = 135 150 90 81 90 119 (4. we find that 219 135 81 detR = 975.57) Therefore. we find the determinant and the adjoint of R . For this example. Solution: For this example.adjR detR (4. Third Edition Copyright © Orchard Publications 4−27 . I 2. Circuit for Example 4.adjR = -------.135 150 90 975 detR 81 90 119 and Numerical Analysis Using MATLAB® and Excel®.

3) since it is zero. Solution of Example 4.154 0. 0 −9 15].2)=−9. we can use Microsoft Excel’s MINVERSE (Matrix Inversion) and MMULT (Matrix Multiplication) functions. R(2.8462 8.2)=−9.4615 13. we enter the elements of matrix V in G3:G5.1)=10.225 0.3)=−9. The procedure is as follows: 1. R(2. A B C D E F G H 1 Spreadsheet for Matrix Inversion and Matrix Multiplication 2 3 10 -9 0 100 4 R= -9 20 -9 V= 0 5 0 -9 15 0 6 7 0.2)=20. % No need to make entry for A(1.85 975 975 81 90 119 0 81 8. R(3. say B3:D5.17 with a spreadsheet 4−28 Numerical Analysis Using MATLAB® and Excel®. to obtain the values of the three currents in Example 4.846 8 0.2.135 = 13.083 0.46 1 100 I = I 2 = -------.083 22. We start with a blank spreadsheet and in a block of cells.092 0. V=[100 0 0]'.8462 8. For instance. −9 20 −9.092 I= 13. R(3. I=R\V I = 22. R(2.2.31 I3 I1 Check with MATLAB: R=[10 −9 0.138 0.462 -1 R = 0.17.135 150 90 0 = -------. the above script could also have been written as: R(1.Chapter 4 Matrices and Determinants 219 135 81 100 219 22.122 8.3077 We can also use subscripts to address the individual elements of the matrix.138 0. Then.3077 Spreadsheets also have the capability of solving simultaneous equations using the inverse matrix method. Accordingly. we enter the elements of matrix R as shown in Figure 4. R(1.3077 9 10 Figure 4. I=R\V I = 22.1)=−9.3)=15.4615 13. V=[100 0 0]'. Third Edition Copyright © Orchard Publications .

and with the cell marker positioned in G7.+ -----------------. Example 4.60) (4. we compute and display the inverse of R. we choose the block of cells G7:G9 for the values of the current I .18 For the phasor circuit of Figure 4. Circuit for Example 4.59) and the voltages V 1 and V 2 can be computed from the nodal equations V 1 – 170 ∠0° V 1 – V 2 V 1 – 0 ------------------------------.= 0 – j100 100 50 (4.61) Compute. the current I X can be found from the relation VS + 85 Ω V1 j200 Ω R1 C IX R2 −j100 Ω V2 50 Ω − 170∠0° R3 = 100 Ω L Figure 4.18 V1 – V2 I X = -----------------R3 (4.+ -------------. We format this block for number display with three decimal places. Third Edition Copyright © Orchard Publications 4−29 . We observe that R–1 appears in these cells.3. Now. As before.+ -----------------.3.G3:G5) and we press the Crtl−Shift−Enter keys simultaneously. and express the current I x in both rectangular and polar forms by first simplifying like Numerical Analysis Using MATLAB® and Excel®.Solution of Simultaneous Equations with Matrices 2. R–1 .+ -------------. We choose B7:D9 for the elements of this inverted matrix. Next. 3. we type the formula =MININVERSE(B3:D5) and we press the Crtl−Shift−Enter keys simultaneously. we highlight them. With this range highlighted and making sure that the cell marker is in B7.= 0 85 100 j200 V 2 – 170 ∠0° V 2 – V 1 V 2 – 0 ------------------------------. we type the formula =MMULT(B7:D9. The values of I then appear in G7:G9. that is.

01 Y V1 V2 V = 2 j1. V = voltage . and I = current .0218−0. I=[2. and then writing the above relations in matrix form as YV = I .7 ⎧ ⎨ ⎩ I (4.0590i and this is the rectangular form of I X .5149 .01 – 0.01. Y=[0.0218 – j0. collecting.7j]. IX=(V(1)−V(2))/R3 % Compute the value of IX IX = 0. Third Edition Copyright © Orchard Publications . The script is shown below.3f\n'.03 + j0.61). For the polar form we use magIX=abs(IX) magIX = % Compute the magnitude of IX 4−30 ⎧ ⎪ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎪ ⎩ ⎧ ⎨ ⎩ Numerical Analysis Using MATLAB® and Excel®.V(2)) % Display values of V1 and V2 in tabular form fprintf('\n')% Insert another line V1 V2 -----------------104.03 + j0. V .005 )V 1 – 0.01 V 1 + ( 0. we find I X from R3=100.905 53.01 0.005j −0.7 Next.01j].0.01 )V 2 = j1.Chapter 4 Matrices and Determinants terms.005 – 0.60) and (4. and to do all other computations.416 Next. I. Solution: The elements of the Y matrix are the coefficients of V 1 and V 2 .62) where the matrices Y . we write (4. We will use MATLAB to compute the voltages V 1 and V 2 . % Insert a line disp(' V1 V2').01 0. and find V fprintf('\n').01V 2 = 2 – 0.V(1).3f %9. % Display V1 and V2 with dash line underneath fprintf('%9. where Y = admit tan ce .62) in matrix form as 0.03+0. V=Y\I. we obtain ( 0. −0. disp(' ------------------').63). % Define Y. 1.0218 – j0. and I are as indicatedin (4. Simplifying and rearranging the nodal equations of (4.

5326 Therefore.5183 thetaIX=angle(IX)*180/pi % Compute angle theta in degrees thetaIX = -6. in polar form I X = 0.53° Spreadsheets have limited capabilities with complex numbers.518 ∠– 6.Solution of Simultaneous Equations with Matrices 0. and thus we cannot use them to compute matrices that include complex numbers in their elements. Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications 4−31 .

is the multiplication of every element of A by k .e.12 Summary • A matrix is a rectangular array of numbers whose general form is a 11 a 12 a 13 … a 1n a 21 a 22 a 23 … a 2n A = a 31 a 32 a 33 … a 3n … … … … … a m1 a m2 a m3 … a mn The numbers a ij are the elements of the matrix where the index i indicates the row. C = A ± B = [ a ij ± b ij ] • If k is any scalar (a positive or negative number). the matrix is said to be a square matrix of order m. The product A ⋅ B will then be an m × n matrix. …. that is. A matrix of m rows and n columns is said to be of m × n order matrix. • For matrix multiplication. and j indicates the column in which each element is positioned. 3 . If m = n . A = B . 4−32 Numerical Analysis Using MATLAB® and Excel®.Chapter 4 Matrices and Determinants 4. is not defined. 3. That is. their sum (dif- ference) will be another matrix C with the same order as A and B . to obtain the product A ⋅ B . then. 2 . Thus. the operation is row by column. Third Edition Copyright © Orchard Publications . n • Two matrices are said to be conformable for addition (subtraction). …. only when the number of columns of matrix A is equal to the number of rows of matrix B . • Two matrices A = a ij and B = b ij are equal. m j = 1 .. If A = a ij and B = b ij are conformable for addition (subtraction). where each element of C is the sum (difference) of the corresponding elements of A and B . if and only if a ij = b ij i = 1. • Two matrices A and B are said to be conformable for multiplication A ⋅ B in that order. • Division of one matrix by another. we multiply each element of a row of A by the corresponding element of a column of B . and not [ k ] which is a 1 × 1 matrix. then multiplication of a matrix A by the scalar k . the product A ⋅ B (but not B ⋅ A ) is conformable for multiplication only if A is an m × p and matrix B is an p × n matrix. 2. we add these products. if they are of the same order m × n . i.

We must use this procedure to find the determinant of a matrix A of order 4 or higher. the value of the determinant of A is the sum of the products obtained by multiplying each element of any row or any column by its cofactor. • Let A be a square matrix of any size. is called an identity matrix I . • The signed minor ( – 1 ) i+j M ij is called the cofactor of a ij and it is denoted as α ij . A scalar matrix with k = 1 . • The determinant of a square matrix A where a 11 a 12 a 13 … a 1n a 21 a 22 a 23 … a 2n A = a a a …a 31 32 33 3n … … … … … a n1 a n2 a n3 … a nn T is denoted as detA and it is defined as detA = a 11 a 22 a 33 …a nn + a 12 a 23 a 34 …a n 1 + a 13 a 24 a 35 …a n 2 + … – a n 1 …a 22 a 13 … – a n 2 …a 23 a 14 – a n 3 …a 24 a 15 – … • If from a matrix A be defined as a 11 a 12 a 13 … a 1n a 21 a 22 a 23 … a 2n A = a a a …a 31 32 33 3n … … … … … a n1 a n2 a n3 … a nn we remove the elements of its ith row. the determinant of the remaining n – 1 square matrix is called the minor of determinant A . • The MATLAB eye(n) function displays an n × n identity matrix and the eye(size(A)) function displays an identity matrix whose size is the same as matrix A .Summary • A scalar matrix is a square matrix where a 11 = a 22 = a 33 = … = a nn = k and k is a scalar. Numerical Analysis Using MATLAB® and Excel®. • The transpose of a matrix A . and it is denoted as M ij . denoted as A . and jth column. Third Edition Copyright © Orchard Publications 4−33 . is the matrix that is obtained when the rows and columns of matrix A are interchanged.

• We can find the unknowns in a system of two or more equations also by the Gaussian elimination method. c. This can be done by multiplying the terms of any of the equations of the system by a number such that we can add (or subtract) this equation to another equation in the system so that one of the unknowns will be eliminated. the determinant is zero. by substitution to another equation with two unknowns. the objective is to eliminate one unknown at a time. This procedure is repeated until all unknowns are found. y . With this method. If all elements of one row or one column are zero. If all the elements of one row or column are m times the corresponding elements of another row or column. is defined as the n square matrix below.Chapter 4 Matrices and Determinants • Some useful properties of determinants are: a. the determinant is zero. If two rows or two columns of a matrix are identical. 4−34 Numerical Analysis Using MATLAB® and Excel®. the adjoint of A . b. Third Edition Copyright © Orchard Publications . we can find the second unknown. denoted as adjA . the determinant is zero. • If A is an n square matrix and α ij is the cofactor of a ij . Subsequently. Then. • Cramer’s rule states that if a system of equations is defined as a 11 x + a 12 y + a 13 z = A a 21 x + a 22 y + a 23 z = B a 31 x + a 32 y + a 33 z = C and we let Δ a 11 a 12 a 13 = a 21 a 22 a 23 a 31 a 32 a 33 D1 = A a 11 a 13 B a 21 a 23 C a 31 a 33 D2 = a 11 A a 13 a 21 B a 23 a 31 C a 33 D3 = a 11 a 12 A a 21 a 22 B a 31 a 32 C the unknowns x . and z can be found from the relations D1 x = ----- Δ D2 y = ----- Δ D3 z = ----- Δ provided that the determinant Δ (delta) is not zero. substitution of the two values found can be made into an equation with three unknowns from which we can find the value of the third unknown.

to solve any set of simultaneous equations that have solutions. where matrix X is the same size as matrix B . and likewise. that is. we cannot use them to compute matrices that include complex numbers in their elements. this is MATLAB’s solution of A B for the matrix equation A ⋅ X = B . • The matrix left division operation is defined as X = A \ B . X is a matrix (a column vector) whose elements are the unknowns and A and X are conformable for multiplication. B is called the inverse of A . Numerical Analysis Using MATLAB® and Excel®. A = B –1 • If a matrix A is non-singular. AA –1 = I or A A = I –1 • If A and B are matrices whose elements are known. A is called the inverse of B . we can compute its inverse from the relation A –1 1 = ----------.Summary α 11 α 21 α 31 … α n1 α 12 α 22 α 32 … α n2 adjA = α α α … α 13 23 33 n3 … … … … … α 1n α 2n α 3n … α nn • An n square matrix A is called singular if detA = 0 . • If A and B are n square matrices such that AB = BA = I . A is called non-singular. denoted as B = A –1 . Third Edition Copyright © Orchard Publications 4−35 . we can use the relation X=A –1 B to solve any set of simultaneous equations that have solutions. that is.adjA detA • Multiplication of a matrix A by its inverse A –1 produces the identity matrix I . where I is the identity matrix. However. if detA ≠ 0 . –1 • We can use Microsoft Excel’s MINVERSE (Matrix Inversion) and MMULT (Matrix Multiplication) functions. We refer to this method as the inverse matrix method of solution of simultaneous equations.

A ⋅ B b. Perform the following computations. A + C c. A – C g. detB c. if possible. Verify your answers with Excel or MATLAB. Verify your answers with Excel or MATLAB. C – D 2. det ( A ⋅ C ) 4. x 1 – 2x 2 + x 3 = – 4 – 2x 1 + 3x 2 + x 3 = 9 3x 1 + 4x 2 – 5x 3 = 0 5. B .13 Exercises For Exercises 1 through 3 below. C ⋅ D e. Solve the following system of equations using Cramer’s rule. Repeat Exercise 4 using the Gaussian elimination method. detD e. 6. Perform the following computations. A – B f. det ( A ⋅ B ) f. if possible. · a. B + D d. C + D e. a. Solve the following system of equations using the inverse matrix method. detC d. Verify your answers with Excel or MATLAB. A + B b. B ⋅ D d. Third Edition Copyright © Orchard Publications .Chapter 4 Matrices and Determinants 4. B – D h. B ⋅ A f. detA b. Verify your answers with Excel or MATLAB. D ⋅ A h. Perform the following computations. D ⋅ C 3. C ⋅ A g. Verify your answers with Excel or MATLAB. – x 1 + 2x 2 – 3x 3 + 5x 4 = 14 x 1 + 3x 2 + 2x 3 – x 4 = 9 3x 1 – 3 x 2 + 2x 3 + 4x 4 = 19 4x 1 + 2x 2 + 5x 3 + x 4 = 27 7. a. Use the MATLAB det(A) function to find the unknowns of the system of equations below. A ⋅ C c. x1 –3 1 3 4 3 1 –2 ⋅ x2 = –2 0 2 3 5 x3 4−36 Numerical Analysis Using MATLAB® and Excel®. the matrices A . if possible. C and D are defined as: 1 –1 –4 A = 5 7 –2 3 –5 6 5 9 –3 B = –2 8 2 7 –4 6 4 6 C= – 3 8 5 –2 D = 1 –2 3 –3 6 –4 1.

Exercises 8. Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications 4−37 . Use Excel to find the unknowns for the system 2 2 –1 2 4 3 –4 1 3 –4 –2 2 x1 1 –2 x2 10 3 ⋅ = x3 – 14 2 7 1 x4 Verify your answers with the MATLAB left division operation.

Chapter 4 Matrices and Determinants 4. A + B = 5 – 2 6 8 –7 1+5 –1+9 –4–3 = 3 15 0 7+8 –2+2 10 – 9 12 3+7 –5–4 6+6 b. B=[5 9 −3. 7 −4 6]. C + D not conformable for addition e. A + C not conformable for addition c. A ⋅ C = 17 109 -37 -29 -13 17 1 × 6 + ( –1 ) × 8 + ( –4 ) × ( –2 ) 5 × 6 + 7 × 8 + ( –2 ) × ( –2 ) 3 × 6 + ( –5 ) × 8 + 6 × ( –2 ) 1 × 4 + ( –1 ) × ( –3 ) + ( –4 ) × 5 5 × 4 + 7 × ( –3 ) + ( –2 ) × 5 3 × 4 + ( –5 ) × ( –3 ) + 6 × 5 – 13 6 = – 11 90 57 – 34 c.14 Solutions to End−of−Chapter Exercises 1. A – B = 5 + 2 3–7 1–5 –1–9 7–8 –5+4 – 4 – 10 – 1 –4+3 = 7 –1 –4 –2–2 –4 –1 0 6–6 f. −2 8 2. = Check with MATLAB: A=[1 −1 −4. B + D not conformable for addition d. C – D not conformable for subtraction 2. B ⋅ D not conformable for multiplication d. ⋅ D = ( – 3 ) × 1 + 8 × ( – 3 ) 4 × ( –2 ) + 6 × 6 4 × 3 + 6 × ( –4 ) ( –3 ) × ( –2 ) + 8 × 6 ( –3 ) × 3 + 8 × ( –4 ) 5 × 1 + ( –2 ) × ( –3 ) 5 × ( –2 ) + ( –2 ) × 6 5 × 3 + ( –2 ) × ( –4 ) 4 × 1 + 6 × ( –3 ) – 14 28 – 12 = – 27 54 – 41 11 – 22 23 4−38 Numerical Analysis Using MATLAB® and Excel®. 5 7 −2. A*B ans = -21 -3 67 b. A⋅B = 1 × 5 + ( –1 ) × ( –2 ) + ( –4 ) × 7 5 × 5 + 7 × ( –2 ) + ( –2 ) × 7 3 × 5 + ( –5 ) × ( –2 ) + 6 × 7 – 21 17 – 29 – 3 109 – 13 67 – 37 17 1 × 9 + ( –1 ) × 8 + ( –4 ) × ( –4 ) 5 × 9 + 7 × 8 + ( –2 ) × ( –4 ) 3 × 9 + ( –5 ) × 8 + 6 × ( –4 ) 1 × ( –3 ) + ( –1 ) × 2 + ( –4 ) × 6 5 × ( –3 ) + 7 × 2 + ( –2 ) × 6 3 × ( –3 ) + ( –5 ) × 2 + 6 × 6 a. 3 −5 6]. Third Edition Copyright © Orchard Publications . B – D not conformable for subtraction h. A – C not conformable for subtraction g. a.

detD does not exist.Solutions to End−of−Chapter Exercises 5 × 1 + 9 × 5 + ( –3 ) × 3 B ⋅ A = 5 × ( –1 ) + 9 × 7 + ( –3 ) × ( –5 ) 5 × ( –4 ) + 9 × ( –2 ) + ( –3 ) × 6 41 73 – 56 = 44 48 4 5 – 65 16 ( –2 ) × 1 + 8 × 5 + 2 × 3 ( –2 ) × ( –1 ) + 8 × 7 + 2 × ( –5 ) ( –2 ) × ( –4 ) + 8 × ( –2 ) + 2 × 6 7 × 1 + ( –4 ) × 5 + 6 × 3 7 × ( –1 ) + ( –4 ) × 7 + 6 × ( –5 ) 7 × ( –4 ) + ( –4 ) × ( –2 ) + 6 × 6 e. c. det ( A ⋅ C ) does not exist because detC does not exist Numerical Analysis Using MATLAB® and Excel®. detC does not exist. matrix must be square e. 1 –1 –4 1 –1 detA = 5 7 – 2 5 7 3 –5 6 3 –5 = 1 × 7 × 6 + ( –1 ) × ( –2 ) × 3 + ( –4 ) × 5 × ( –5 ) – [ 3 × 7 × ( –4 ) + ( –5 ) × ( –2 ) × 1 + 6 × 5 × ( –1 ) ] = 42 + 6 + 100 – ( – 84 ) – 10 – ( – 30 ) = 252 5 9 –3 5 9 detB = – 2 8 2 – 2 8 7 –4 6 7 –4 = 5 × 8 × 6 + 9 × 2 × 7 + ( –3 ) × ( –2 ) × ( –4 ) – [ 7 × 8 × ( –3 ) + ( –4 ) × 2 × 5 + 6 × ( –2 ) × 9 ] = 240 + 126 – 24 – ( – 168 ) + 40 – ( – 108 ) = 658 b. matrix must be square d. D ⋅ C = 3. det ( A ⋅ B ) = 252 × 658 = 165816 f. Third Edition Copyright © Orchard Publications 4−39 . f. a. = h. C ⋅ A not conformable for multiplication D⋅A = 1 × 1 + ( –2 ) × 5 + 3 × 3 1 × ( –1 ) + ( –2 ) × 7 + 3 × ( –5 ) 1 × ( –4 ) + ( –2 ) × ( –2 ) + 3 × 6 ( –3 ) × 1 + 6 × 5 + ( –4 ) × 3 ( –3 ) × ( –1 ) + 6 × 7 + ( –4 ) × ( –5 ) ( –3 ) × ( –4 ) + 6 × ( –2 ) + ( –4 ) × 6 0 – 30 18 15 65 – 24 1 × 4 + ( –2 ) × ( –3 ) + 3 × 5 ( –3 ) × 4 + 6 × ( –3 ) + ( –4 ) × 5 1 × 6 + ( –2 ) × 8 + 3 × ( –2 ) = 25 – 16 ( –3 ) × 6 + 6 × 8 + ( –4 ) × ( –2 ) – 50 38 g. et ( A ⋅ B ) = detA ⋅ detBand from parts (a) and (b).

= -------.= – 1 Δ – 22 D2 – 44 x 2 = -----.= 2 Δ – 22 D3 – 22 x 3 = -----.= -------.= -------.= 1 Δ – 22 5. 1 –2 1 1 –2 Δ = –2 3 1 –2 3 3 4 –5 3 4 = 1 × 3 × ( –5 ) + ( –2 ) × 1 × 3 + 1 × ( –2 ) × 4 – [ 3 × 3 × 1 + 4 × 1 × 1 + ( –5 ) × ( –2 ) × ( –2 ) ] = – 15 – 6 – 8 – 9 – 4 + 20 = – 22 –4 –2 1 4 –2 9 3 1 9 3 0 4 –5 0 4 D1 = = –4 × 3 × ( –5 ) + ( – 2 ) × 1 × 0 + 1 × 9 × 4 – [ 0 × 3 × 1 + 4 × 1 × 4 + ( –5 ) × 9 × ( –2 ) ] = 60 + 0 + 36 – 0 + 16 – 90 = 22 1 –4 1 1 –4 D2 = –2 9 1 –2 9 3 0 –5 3 0 = 1 × 9 × ( –5 ) + ( –4 ) × 1 × 3 + 1 × ( –2 ) × 0 – [ 3 × 9 × 1 + 0 × 1 × 1 + ( –5 ) × ( –2 ) × ( –4 ) ] = – 45 – 12 – 0 – 27 – 0 + 40 = – 44 1 –2 –4 1 –2 D3 = –2 3 9 –2 3 3 4 0 3 4 = 1 × 3 × 0 + ( –2 ) × 9 × 3 + ( –4 ) × ( –2 ) × 4 – [ 3 × 3 × ( –4 ) + 4 × 9 × 1 + 0 × ( –2 ) × ( –2 ) ] = 0 – 54 + 32 + 36 – 36 – 0 = – 22 D1 22 x 1 = -----. Third Edition Copyright © Orchard Publications .Chapter 4 Matrices and Determinants 4. x 1 – 2x 2 + x 3 = – 4 (1) – 2x 1 + 3x 2 + x 3 = 9 (2) 3x 1 + 4x 2 – 5x 3 = 0 (3) Multiplication of (1) by 2 yields 2x 1 – 4x 2 + 2x 3 = – 8 (4) Addition of (2) and (4) yields – x 2 + 3x 3 = 1 (5) 4−40 Numerical Analysis Using MATLAB® and Excel®.

D1=[14 2 −3 5. x3=det(D3)/det(Delta). x4=det(D4)/det(Delta) x1=1 x2=2 x3=3 x4=4 Numerical Analysis Using MATLAB® and Excel®. 3 −3 19 4. 4 2 5 1]. 1 3 2 9. 1 3 9 −1. 4 27 5 1]. 9 3 2 −1. 4 2 27 1]. 1 9 2 −1.. 3 −3 2 4. 3 −3 2 19. D2=[−1 14 −3 5. Delta=[−1 2 −3 5. 27 2 5 1]. D3=[−1 2 14 5. 19 −3 2 4.. x1=det(D1)/det(Delta). D4=[−1 2 −3 14.Solutions to End−of−Chapter Exercises Multiplication of (1) by – 3 yields – 3 x 1 + 6x 2 – 3x 3 = 12 (6) Addition of (3) and (6) yields 10x 2 – 8x 3 = 12 (7) Multiplication of (5) by 10 yields – 10x 2 + 30x 3 = 10 (8) Addition of (7) and (8) yields 22x 3 = 22 (9) or x 3 = 1 (10) Substitution of (10) into (7) yields 10x 2 – 8 = 12 (11) or x 2 = 2 (12) and substitution of (10) and (12) into (1) yields x 1 – 4 + 1 = – 4 (13) or x 1 = – 1 (14) 6. 1 3 2 −1. x2=det(D2)/det(Delta). 4 2 5 27].. Third Edition Copyright © Orchard Publications 4−41 . 3 19 2 4.

50 – 3.50 4−42 Numerical Analysis Using MATLAB® and Excel®.⋅ adjA = -------. 1 3 4 1 3 detA = 3 1 – 2 3 1 2 3 5 2 3 = 1 × 1 × 5 + 3 × ( –2 ) × 2 + 4 × 3 × 3 – [ 2 × 1 × 4 + 3 × ( – 2 ) × 1 + 5 × 3 × 3 ] = 5 – 12 + 36 – 8 + 6 – 45 = – 18 11 – 3 – 10 adjA = – 19 – 3 14 7 3 –8 –1 11 – 3 – 10 – 11 ⁄ 18 3 ⁄ 18 10 ⁄ 18 1 1 = ----------.⋅ – 19 – 3 14 = 19 ⁄ 18 3 ⁄ 18 – 14 ⁄ 18 detA – 18 – 7 ⁄ 18 – 3 ⁄ 18 8 ⁄ 18 7 3 –8 – 11 ⁄ 18 3 ⁄ 18 10 ⁄ 18 – 3 19 ⁄ 18 3 ⁄ 18 – 14 ⁄ 18 – 2 = – 7 ⁄ 18 – 3 ⁄ 18 8 ⁄ 18 0 33 ⁄ 18 – 6 ⁄ 18 + 0 – 57 ⁄ 18 – 6 ⁄ 18 + 0 = 21 ⁄ 18 + 6 ⁄ 18 + 0 27 ⁄ 18 – 63 ⁄ 18 = 27 ⁄ 18 A x1 X = x2 = x3 1. Third Edition Copyright © Orchard Publications .50 1.Chapter 4 Matrices and Determinants 7.

2 −2 2 1].Solutions to End−of−Chapter Exercises 8.5000 12. 2 −4 1 3. Third Edition Copyright © Orchard Publications 4−43 .5000 1.0000 Numerical Analysis Using MATLAB® and Excel®. −1 3 −4 2. A\B ans = -11. B=[1 10 −14 7]'. A=[2 4 3 −2.0000 9.

Example 5. Solution: It is given that the current.2) By substitution of (5.= I dt and by separation of the variables. 5. Find the voltage v C across this capacitor as a function of time given that the voltage at some reference time t = 0 is V 0 .3) we obtain v C ( t ) = It + k where k represents the constants of integration of both sides. and the constant C is the capacitance in farads (F).1) where i C ( t ) is the current through the capacitor.1 The current and voltage in a capacitor are related by dv C i C ( t ) = C -------dt (5. dv C = Idt (5. and State Equations T his chapter is a review of ordinary differential equations and an introduction to state variables and state equations.2) into (5. that is. v C ( t ) is the voltage across the capacitor. Solutions of differential equations with numerical methods is discussed in Chapter 9. Third Edition Copyright © Orchard Publications 5−1 . i C ( t ) = I = cons tan t (5. as a function of time.3) (5. For this example C = 1 F and the capacitor is being charged by a constant current I .Chapter 5 Differential Equations. Numerical Analysis Using MATLAB® and Excel®.1) we obtain dv C -------.4) Integrating both sides of (5.1 Simple Differential Equations In this section we present two simple examples to show the importance of differential equations in engineering applications. State Variables. is constant.

**Chapter 5 Differential Equations, State Variables, and State Equations
**

We can find the value of the constant k by making use of the initial condition, i.e., at t = 0 , v C = V 0 and (5.4) then becomes

V0 = 0 + k

(5.5) (5.6)

**or k = V 0 , and by substitution into (5.4),
**

v C ( t ) = It + V 0

This example shows that when a capacitor is charged with a constant current, a linear voltage is produced across the terminals of the capacitor. Example 5.2 Find the current i L ( t ) through an inductor whose slope at the coordinate ( t, i L ) is cos t and the current i L passes through the point ( π ⁄ 2 ,1 ) . Solution: We are given that

di L ------- = cos t dt

(5.7) (5.8) (5.9)

**By separating the variables we obtain
**

di L = cos tdt

**and integrating both sides we obtain
**

i L ( t ) = sin t + k

where k represents the constants of integration of both sides. We find the value of the constant k by making use of the initial condition. For this example, ω = 1 and thus at ωt = t = π ⁄ 2 , i L = 1 . With these values (5.9) becomes

-1 = sin π + k 2

(5.10)

**or k = 0 , and by substitution into (5.9),
**

i L ( t ) = sin t

(5.11)

5.2 Classification

Differential equations are classified by: 1. Type - Ordinary or Partial

5−2

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

Classification

2. Order - The highest order derivative which is included in the differential equation 3. Degree - The exponent of the highest power of the highest order derivative after the differential equation has been cleared of any fractions or radicals in the dependent variable and its derivatives For example, the differential equation

2 ⎛ d 4 y⎞ ⎛ d 3 y⎞ ⎛ d 2 y⎞ dy 8 y ------- ⎟ + 5 ⎜ ------- ⎟ + 6 ⎜ ------- ⎟ + 3 ⎛ ----- ⎞ + -------------- = ye – 2x ⎜ 4 ⎝ dx⎠ 3 ⎝ dx ⎠ ⎝ dx 3⎠ ⎝ dx 2⎠ x +1 2 4 6

is an ordinary differential equation of order 4 and degree 2 . If the dependent variable y is a function of only a single variable x , that is, if y = f ( x) , the differential equation which relates y and x is said to be an ordinary differential equation and it is abbreviated as ODE. The differential equation

2 dy d y ------- + 3 ----- + 2 = 5 cos 4t 2 dt dt

**is an ODE with constant coefficients. The differential equation
**

dy d y 2 2 x 2 ------- + x ----- + ( x – n ) = 0 2 dt dt

2

is an ODE with variable coefficients. If the dependent variable y is a function of two or more variables such as y = f ( x, t ) , where x and t are independent variables, the differential equation that relates y , x , and t is said to be a partial differential equation and it is abbreviated as PDE. An example of a partial differential equation is the well-known one-dimensional wave equation shown below.

2 2∂ y ∂ y ------- = a ------2 2 ∂x ∂t 2

Most engineering problems are solved with ordinary differential equations with constant coefficients; however, partial differential equations provide often quick solutions to some practical applications as illustrated with the following three examples.

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

5−3

**Chapter 5 Differential Equations, State Variables, and State Equations
**

Example 5.3 The equivalent resistance R T of three resistors R 1 , R 2 , and R 3 in parallel is obtained from

1 1 1 1 ------ = ----- + ----- + ----RT R1 R2 R3

Given that initially R 1 = 5 Ω , R 2 = 20 Ω , and R 3 = 4 Ω , compute the change in R T if R 2 is increased by 10 % and R 3 is decreased by 5 % while R 1 does not change. Solution: The initial value of the equivalent resistance is R T = 5 || 20 || 4 = 2 Ω . Now, we treat R 2 and R 3 as constants and differentiating R T with respect to R 1 we obtain

RT 2 ∂R T 1 1 ∂R T – ------ --------- = – ----- or --------- = ⎛ ------ ⎞ 2 2 ∂R 1 ⎝ R 1 ⎠ R1 R T ∂R 1

Similarly,

RT 2 ∂R T ⎛ R T ⎞ 2 ∂R T --------- = -----and --------- = ⎛ ------ ⎞ ∂R 2 ⎝ R 2 ⎠ ∂R 3 ⎝ R 3 ⎠

**and the total differential dRT is
**

RT 2 ∂R T ∂R T ∂R T RT 2 RT 2 R T = --------- dR 1 + --------- dR 2 + --------- dR 3 = ⎛ ------ ⎞ dR 1 + ⎛ ------ ⎞ dR 2 + ⎛ ------ ⎞ dR ⎝ R1 ⎠ ⎝ R2 ⎠ ⎝ R3 ⎠ ∂R 1 ∂R 2 ∂R 3

**By substitution of the given numerical values we obtain
**

2- 2 2 2 2 2 dR T = ⎛ -- ⎞ ( 0 ) + ⎛ ----- ⎞ ( 2 ) + ⎛ -- ⎞ ( – 0.2 ) = 0.02 – 0.05 = – 0.03 ⎝ 20 ⎠ ⎝4⎠ ⎝5 ⎠

Therefore, the eequivalent resistance decreases by 3 % . Example 5.4 In a series RC electric circuit that is excited by a sinusoidal voltage, the magnitude of the impedance Z is computed from Z =

R + X C . Initially, R = 4 Ω and X C = 3 Ω . Find the change

2 2

in the impedance Z if the resistance R is increased by 0.25 Ω ( 6.25 % ) and the capacitive reactance X C is decreased by 0.125 Ω ( – 4.167% ).

5−4

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

Classification

Solution:

∂Z ∂Z We will first find the partial derivatives ------ and ---------- ; then we compute the change in impedance ∂R ∂X C

**from the total differential dZ . Thus,
**

XC ∂Z R ∂Z ------ = --------------------------- and --------- = --------------------------∂R ∂X C 2 2 2 2 R + XC R + XC

and

R dR + X C dX C ∂Z ∂Z dZ = ------ dR + ---------- dX C = --------------------------------------∂X C ∂R 2 2 R + XC

**and by substitution of the given values
**

1 – 0.375 4 ( 0.25 ) + 3 ( – 0.125 ) dZ = ---------------------------------------------------- = ------------------------- = 0.125 5 2 2 4 +3

**Therefore, if R increases by 6.25 % and X C decreases by 4.167% , the impedance Z increases by
**

4.167% .

Example 5.5 A light bulb is rated at 120 volts and 75 watts. If the voltage decreases by 5 volts and the resistance of the bulb is increased by 8 Ω , by how much will the power change? Solution: At V = 120 volts and P = 75 watts, the bulb resistance is

--------------R = V - = 120 - = 192 Ω P 75

2 2

and since

V∂P V∂P -----P = ----- then ------ = 2V and ------ = – ----2 ∂R R ∂V R R

2 2

and the total differential is

2 2 2 ( 120 ) ∂P ∂P 2V 120 VdP = ------ dV + ------ dR = ------ dV – ----- dR = ---------------- ( – 5 ) – ---------- ( 8 ) = – 9.375 2 2 192 ∂V ∂R R R 192

That is, the power will decrease by 9.375 watts.

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

5−5

**Chapter 5 Differential Equations, State Variables, and State Equations 5.3 Solutions of Ordinary Differential Equations (ODE)
**

A function y = f ( x) is a solution of a differential equation if the latter is satisfied when y and its derivatives are replaced throughout by f ( x) and its corresponding derivatives. Also, the initial conditions must be satisfied. For example a solution of the differential equation

d y ------- + y = 0 2 dx

2

is

y = k 1 sin x + k 2 cos x

since y and its second derivative satisfy the given differential equation. Any linear, time-invariant system can be described by an ODE which has the form

d y d y dy a n -------- + a n – 1 --------------- + … + a 1 ----- + a 0 y n n–1 dt dt dt d x d x dx b m --------- + b m – 1 ---------------- + … + b 1 ----- + b 0 x m n–1 dt = dt dt Excitation ( Forcing ) Function x ( t ) NON – HOMOGENEOUS DIFFERENTIAL EQUATION

m m–1 n n–1

(5.12)

If the excitation in (B12) is not zero, that is, if x ( t ) ≠ 0 , the ODE is called a non-homogeneous ODE. If x ( t ) = 0 , it reduces to:

d y d y dy a n -------- + a n – 1 --------------- + … + a 1 ----- + a 0 y = 0 n n–1 dt dt dt HOMOGENEOUS DIFFERENTIAL EQUATION

n n–1

⎧ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎩

(5.13)

The differential equation of (5.13) above is called a homogeneous ODE and has n different linearly independent solutions denoted as y 1 ( t ), y 2 ( t ), y 3 ( t ), …, y n ( t ) . We will now prove that the most general solution of (5.13) is:

yH ( t ) = k1 y1 ( t ) + k2 y2 ( t ) + k3 y3 ( t ) + … + kn yn ( t )

(5.14)

where the subscript H on the left side is used to emphasize that this is the form of the solution of the homogeneous ODE and k 1, k 2, k 3, …, k n are arbitrary constants.

5−6

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Solutions of Ordinary Differential Equations (ODE)
**

Proof: Let us assume that y 1 ( t ) is a solution of (5.13); then by substitution,

d y1 d y1 dy 1 a n ----------- + a n – 1 ----------------- + … + a 1 ------- + a 0 y 1 = 0 n n–1 dt dt dt

n n–1

(5.15)

**A solution of the form k 1 y 1 ( t ) will also satisfy (5.13) since
**

d d d a n ------ ( k 1 y 1 ) + a n – 1 ------------- ( k 1 y 1 ) + … + a 1 ---- ( k 1 y 1 ) + a 0 ( k 1 y 1 ) n n–1 dt dt dt d y1 dy 1 ⎛ d y1 ⎞ = k 1 ⎜ a n ----------- + a n – 1 ----------------- + … + a 1 ------- + a 0 y 1⎟ = 0 n n–1 dt ⎝ dt ⎠ dt

n n–1 n n–1

(5.16)

**If y = y 1 ( t ) and y = y 2 ( t ) are any two solutions, then y = y 1 ( t ) + y 2 ( t ) will also be a solution since
**

d y1 d y1 dy 1 a n ----------- + a n – 1 ----------------- + … + a 1 ------- + a 0 y 1 = 0 n n–1 dt dt dt

n n–1

and

d y2 d y2 d y2 a n ----------- + a n – 1 ----------------- + … + a 1 --------- + a 0 y 2 = 0 n n–1 dt dt dt

n n–1

Therefore,

dd da n ------ ( y 1 + y 2 ) + a n – 1 ------------- ( y 1 + y 2 ) + … + a 1 ---- ( y 1 + y 2 ) + a 0 ( y 1 + y 2 ) n n–1 dt dt dt n n–1 d d d = a n ------ y 1 + a n – 1 ------------- y 1 + … + a 1 ---- y 1 + a 0 y 1 n n–1 dt dt dt n n–1 d d d + a n ------ y 2 + a n – 1 ------------- y 2 + … + a 1 ---- y 2 + a 0 y 2 = 0 n n–1 dt dt dt

n n–1

(5.17)

In general, if

y = k 1 y 1 ( t ), k 2 y 1 ( t ), k 3 y 3 ( t ), …, k n y n ( t )

**are the n solutions of the homogeneous ODE of (5.13), the linear combination
**

y = k1 y1 ( t ) + k2 y1 ( t ) + k3 y3 ( t ) + … + kn yn ( t )

is also a solution. In our subsequent discussion, the solution of the homogeneous ODE, i.e., the complementary

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

5−7

**Chapter 5 Differential Equations, State Variables, and State Equations
**

solution, will be referred to as the natural response, and will be denoted as y N ( t ) or simply y N . The particular solution of a non-homogeneous ODE will be referred to as the forced response, and will be denoted as y F ( t ) or simply y F . Accordingly, we express the total solution of the non-homogeneous ODE of (5.12) as:

y(t) = y

Natural Response

+y

Forced Response

= yN + yF

(5.18)

The natural response y N contains arbitrary constants and these can be evaluated from the given initial conditions. The forced response y F , however, contains no arbitrary constants. It is imperative to remember that the arbitrary constants of the natural response must be evaluated from the total response.

**5.4 Solution of the Homogeneous ODE
**

Let the solutions of the homogeneous ODE

d y d y dy a n -------- + a n – 1 --------------- + … + a 1 ----- + a 0 y = 0 n n–1 dt dt dt

n n–1

(5.19)

**be of the form
**

y = ke

st

(5.20)

**Then, by substitution of (5.20) into (5.19) we obtain
**

a n ks e + a n – 1 ks

n st n – 1 st

e + … + a 1 kse + a 0 ke

st

st

st

= 0

or

( an s + an – 1 s

n n–1

+ … + a 1 s + a 0 ) ke

= 0

(5.21)

**We observe that (5.21) can be satisfied when
**

( an s + an – 1 s

n n–1

+ … + a 1 s + a 0 ) = 0 or k = 0

or s = – ∞

(5.22)

but the only meaningful solution is the quantity enclosed in parentheses since the latter two yield trivial (meaningless) solutions. We, therefore, accept the expression inside the parentheses as the only meaningful solution and this is referred to as the characteristic (auxiliary) equation, that is,

⎧ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎩ an s + an – 1 s

n n–1

+ … + a1 s + a0 = 0

(5.23)

Characteristic Equation

Since the characteristic equation is an algebraic equation of an nth-power polynomial, its solutions are s 1, s 2, s 3, …, s n , and thus the solutions of the homogeneous ODE are:

5−8

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Solution of the Homogeneous ODE
**

y 1 = k 1 e , y 2 = k 2 e , y 3 = k 3 e , …, y n = k n e

s1 t s2 t s3 t sn t

(5.24)

Case I − Distinct Roots If the roots of the characteristic equation are distinct (different from each another), the n solutions of (5.23) are independent and the most general solution is:

yN = k1 e

s1 t

+ k2 e

s2 t

+ … + kn e

sn t

(5.25)

FOR DISTINCT ROOTS

Case II − Repeated Roots If two or more roots of the characteristic equation are repeated (same roots), then some of the terms of (5.24) are not independent and therefore (5.25) does not represent the most general solution. If, for example, s 1 = s 2 , then, k1 e

s1 t s t

s1 t

+ k2 e

s2 t

= k1 e

s1 t

+ k2 e

s1 t

= ( k 1 + k 2 )e

s1 t

= k3 e

s1 t

and we see that one term of (5.25) is lost. In this case, we express one of the terms of (5.25), say as k 2 te 1 . These two represent two independent solutions and therefore the most general solution has the form:

k2 e y N = ( k 1 + k 2 t )e

s1 t

+ k3 e

s3 t

+ … + kn e

sn t

(5.26)

**If there are m equal roots the most general solution has the form:
**

yN = ( k1 + k2 t + … + km t

m–1

)e

s1 t

+ kn – i e

s2 t

+ … + kn e

sn t

(5.27)

FOR M EQUAL ROOTS

Case III − Complex Roots If the characteristic equation contains complex roots, these occur as complex conjugate pairs. Thus, if one root is s 1 = – α + jβ where α and β are real numbers, then another root is

s 1 = – α – j β . Then, k1 e

s1 t

+ k2 e

s2 t

= k1 e = e = e = e

– αt + jβt

+ k2 e

– αt – j βt

= e

– αt

( k1 e

jβt

+ k2 e

– j βt

)

– αt – αt – αt

**( k 1 cos βt + jk 1 sin β t + k 2 cos βt – jk 2 sin β t ) [ ( k 1 + k 2 ) cos βt + j ( k 1 – k 2 ) sin β t ] ( k 3 cos βt + k 4 sin β t ) = e
**

– αt

k 5 cos ( βt + ϕ )

FOR TWO COMPLEX CONJUGATE ROOTS

(5.28)

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

5−9

**Chapter 5 Differential Equations, State Variables, and State Equations
**

If (5.28) is to be a real function of time, the constants k 1 and k 2 must be complex conjugates. The other constants k 3 , k 4 , k 5 , and the phase angle ϕ are real constants. The forced response can be found by a. The Method of Undetermined Coefficients or b. The Method of Variation of Parameters We will study the Method of Undetermined Coefficients first.

**5.5 Using the Method of Undetermined Coefficients for the Forced Response
**

For simplicity, we will only consider ODEs of order 2 . Higher order ODEs are discussed in differential equations textbooks. Consider the non-homogeneous ODE

a dy

2 2

d + b ---- y + cy = f ( x ) dt dt

(5.29)

where a , b , and c are real constants. We have learned that the total (complete) solution consists of the summation of the natural and forced responses. For the natural response, if y 1 and y 2 are any two solutions of (5.29), the linear combination

y 3 = k 1 y 1 + k 2 y 2 , where k 1 and k 2 are arbitrary constants, is also a solution, that is, if we know

the two solutions, we can obtain the most general solution by forming the linear combination of y 1 and y 2 . To be certain that there exist no other solutions, we examine the Wronskian Determinant defined below.

y1 y2 d d W ( y 1, y 2 ) ≡ d = y1 ----- y 2 – y 2 ----- y1 ≠ 0 d dx dx ----- y1 ----- y 2 dx dx WRONSKIAN DETERMINANT

(5.30)

If (5.30) is true, we can be assured that all solutions of (5.29) are indeed the linear combination of y 1 and y 2 . The forced response is obtained by observation of the right side of the given ODE as it is illustrated by the examples that follow.

5−10

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Using the Method of Undetermined Coefficients for the Forced Response
**

Example 5.6 Find the total solution of the ODE

dy + 4 ----- + 3y = 0 dt dt d y

2 2

(5.31)

subject to the initial conditions y ( 0 ) = 3 and y' ( 0 ) = 4 where y' = dy ⁄ dt Solution: This is a homogeneous ODE and its total solution is just the natural response found from the characteristic equation s + 4s + 3 = 0 whose roots are s 1 = – 1 and s 2 = – 3 . The total response is:

y ( t ) = yN ( t ) = k1 e + k2 e

–t – 3t 2

(5.32)

**The constants k 1 and k 2 are evaluated from the given initial conditions. For this example,
**

y ( 0 ) = 3 = k1 e + k2 e

0 0

or

k1 + k2 = 3

(5.33)

–t – 3t t=0

Also,

dy y' ( 0 ) = 4 = ----dt = – k 1 e – 3k 2 e

t=0

or

– k 1 – 3k 2 = 4

(5.34)

**Simultaneous solution of (5.33) and (5.34) yields k 1 = 6.5 and k 2 = – 3.5 . By substitution into (5.32), we obtain
**

y ( t ) = y N ( t ) = 6.5e – 3.5e

–t – 3t

(5.35)

**Check with MATLAB:
**

y=dsolve('D2y+4*Dy+3*y=0', 'y(0)=3', 'Dy(0)=4')

**y = (-7/2*exp(-3*t)*exp(t)+13/2)/exp(t)
**

pretty(y)

- 7/2 exp(-3 t) exp(t) + 13/2 ----------------------------exp(t) The function y = f ( t ) , of relation (5.35), shown in Figure 5.1, was plotted with the use of the MATLAB script Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

5−11

**Chapter 5 Differential Equations, State Variables, and State Equations
**

y=dsolve('D2y+4*Dy+3*y=0', 'y(0)=3', 'Dy(0)=4'); ezplot(y,[0 5])

3.5 3 2.5 2 1.5 1 0.5 0 13/2 exp(-t)-7/2 exp(-3 t)

0

1

2 t

3

4

5

Figure 5.1. Plot for the function y = f ( t ) of Example 5.6.

**Example 5.7 Find the total solution of the ODE
**

dy – 2t + 4 ----- + 3y = 3e dt dt dy

2 2

(5.36)

subject to the initial conditions y ( 0 ) = 1 and y' ( 0 ) = – 1 Solution: The left side of (5.36) is the same as that of Example 5.6.Therefore,

yN ( t ) = k1 e + k2 e

–t – 3t

(5.37)

(We must remember that the constants k 1 and k 2 must be evaluated from the total response). To find the forced response, we assume a solution of the form

y F = Ae

– 2t

(5.38)

We can find out whether our assumption is correct by substituting (5.38) into the given ODE of (5.36). Then,

4Ae

– 2t

– 8Ae

– 2t

+ 3Ae

– 2t

= 3e

– 2t

(5.39)

from which A = – 3 and the total solution is

5−12

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Using the Method of Undetermined Coefficients for the Forced Response
**

y ( t ) = yN + yF = k1 e + k2 e

–t – 3t

–3 e

– 2t

(5.40)

**The constants k 1 and k 2 are evaluated from the given initial conditions. For this example,
**

y ( 0 ) = 1 = k 1 e + k 2 e – 3e

0 0 0

or

k1 + k2 = 4

(5.41)

–t – 3t

Also,

dy y' ( 0 ) = – 1 = ----dt = – k 1 e – 3k 2 e

t=0

+ 6e

– 2t t=0

or

– k 1 – 3k 2 = – 7

(5.42)

**Simultaneous solution of (5.41) and (5.42) yields k 1 = 2.5 and k 2 = 1.5 . By substitution into (5.40), we obtain
**

y ( t ) = y N + y F = 2.5e + 1.5e

–t – 3t

–3 e

– 2t

(5.43)

**Check with MATLAB:
**

y=dsolve('D2y+4*Dy+3*y=3*exp(−2*t)', 'y(0)=1', 'Dy(0)=−1')

**y = (-3*exp(-2*t)*exp(t)+3/2*exp(-3*t)*exp(t)+5/2)/exp(t)
**

pretty(y)

-3 exp(-2 t) exp(t) + 3/2 exp(-3 t) exp(t) + 5/2 -----------------------------------------------exp(t) The plot is shown in Figure 5.2 was produced with the MATLAB script

y=dsolve('D2y+4*Dy+3*y=3*exp(−2*t)', 'y(0)=1', 'Dy(0)=−1'); ezplot(y,[0 8])

**Example 5.8 Find the total solution of the ODE
**

dy + 6 ----- + 9y = 0 dt dt dy

2 2

(5.44)

subject to the initial conditions y ( 0 ) = – 1 and y' ( 0 ) = 1

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

5−13

4 0. we evaluate the constants k 1 and k 2 from the given initial conditions.47) From (5. y ( 0 ) = – 1 = k 1 e + k 2 ( 0 )e 0 0 or k1 = –1 (5.9 0. the total response is y ( t ) = yN = k1 e – 3t 2 + k 2 te – 3t (5. For this example. Solution: This is a homogeneous ODE and therefore its total solution is just the natural response found from the characteristic equation s + 6s + 9 = 0 whose roots are s 1 = s 2 = – 3 (repeated roots). Thus. Check with MATLAB: y ( t ) = –e – 3t – 2te – 3t (5.46) and (5. and State Equations 1 0.3 0. State Variables.1 0 0 1 2 t 3 4 5 5/2 exp(-t)+3/2 exp(-3 t)-3 exp(-2 t) Figure 5.7.7 0. Third Edition Copyright © Orchard Publications .48) y=dsolve('D2y+6*Dy+9*y=0'. Plot for the function y = f ( t ) of Example 5. 'Dy(0)=1') 5−14 Numerical Analysis Using MATLAB® and Excel®. By substitution into (5.46) – 3t Also.45) Next. 'y(0)=−1'.5 0.47) we obtain k 1 = – 1 and k 2 = – 2 .2 0.8 0. ----y' ( 0 ) = 1 = dy dt = – 3k 1 e t=0 + k2 e – 3t – 3k 2 te – 3t t=0 or – 3k 1 + k 2 = 1 (5.Chapter 5 Differential Equations.45).6 0.2.

3 was produced with the MATLAB script y=dsolve('D2y+6*Dy+9*y=0'.6 -0.5 1 1. the roots of the characteristic equation of (5. ezplot(y.50) Next.5 -0. Example 5. therefore.3 -0.8.+ 6y = 3e dt dt dy 2 2 (5. we will express the solution in terms of the constants k 1 and k 2 .Using the Method of Undetermined Coefficients for the Forced Response y = -exp(-3*t)-2*exp(-3*t)*t The plot shown in Figure 5.9 -1 0 0.4 -0.1 -0.2 -0. Third Edition Copyright © Orchard Publications 5−15 .49).3. we find the forced response by assuming a solution of the form y F = Ae – 2t (5.9 Find the total solution of the ODE dy – 2t + 5 ----.[0 3]) 0 -0.49) are s 1 = – 2 and s 2 = – 3 and thus the natural response has the form yN = k1 e – 2t + k2 e – 3t (5.5 3 -exp(-3 t)-2 exp(-3 t) t Figure 5.5 t 2 2. Then. 'Dy(0)=1'). Numerical Analysis Using MATLAB® and Excel®.8 -0.51) into the given ODE of (5.49) Solution: No initial conditions are given.51) We can find out whether our assumption is correct by substitution of (5. By inspection. Plot for the function y = f ( t ) of Example 5.7 -0. 'y(0)=−1'.

53) that is. that is. we assume that the forced response has the form y F = Ate – 2t (5.53) into (5.52) but the sum of the three terms on the left side of (5. we find that A = 3 . We observe that the left side of (5.55) is the same of that of Example 5. Then.49) and equating like terms.56) Next. to find the forced response and we assume a solution of the form 5−16 Numerical Analysis Using MATLAB® and Excel®. we multiply (5. and State Equations 4Ae – 2t – 10Ae – 2t + 6Ae – 2t = 3e – 2t (5.Chapter 5 Differential Equations. it has the form yN = k1 e – 2t + k2 e – 3t (5.55) Solution: No initial conditions are given.9. Example 5. the natural response is the same. therefore. State Variables.10 Find the total solution of the ODE d 2y + 5 dy + 6y = 4 cos 5t ----2 dt dt (5. To work around this problem.52) is zero whereas the right side can never be zero unless we let t → ∞ and this produces a meaningless result. Therefore. The problem here is that the right side of the given ODE of (5.51) by t in order to eliminate the duplication of terms in the total response. Third Edition Copyright © Orchard Publications .54) Check with MATLAB: y=dsolve('D2y+5*Dy+6*y=3*exp(−2*t)') y = -3*exp(-2*t)+3*t*exp(-2*t)+C1*exp(-3*t)+C2*exp(-2*t) We observe that the first and last terms of the displayed expression above have the same form and thus they can be combined to form a single term C3*exp(-2*t). by substitution of (5.49) has the same form as one of the terms of the natural response of (5. namely the term k 1 e – 2t .50). the total response is y ( t ) = yN + yF = k1 e – 2t + k2 e – 3t + 3te – 2t (5. we will express solution in terms of the constants k 1 and k 2 . Therefore.

sin kx . [k3 k4]=solve(19*x+25*y.cos 5t 493 493 (5.57) into the given ODE of (5.Using the Method of Undetermined Coefficients for the Forced Response y F = A cos 5t (5. cos kx . – 25A cos 5t – 25A sin 5 t + 6A cos 5t = – 19A cos 5t – 25A sin 5 t = 4 cos 5t but this relation is invalid since by equating cosine and sine terms. we find that A = – 4 ⁄ 19 and also A = 0 . we obtain the following set of equations 19k 3 + 25k 4 = 0 25k 3 – 19 k 4 = 4 (5. x where n is a positive integer.57) We can find out whether our assumption is correct by substitution of the assumed solution of (5. the total solution is y ( t ) = yN + yF ( t ) = k1 e – 2t + k2 e – 3t – 38 50 + -------.1 summarizes the forms of the forced response for a second order Numerical Analysis Using MATLAB® and Excel®. This inconsistency is a result of our failure to recognize that the derivatives of A cos 5t produce new terms of the form B sin 5t and these terms must be included in the forced response. Table 5. Third Edition Copyright © Orchard Publications n kx 5−17 .58) and by substitution into (5. we let y F = k 3 sin 5 t + k 4 cos 5t (5. 25*x−19*y−4) k3 = 50/493 k4 = -38/493 Therefore. Accordingly.60) Check with MATLAB: y=dsolve('D2y+5*Dy+6*y=4*cos(5*t)').59) format rat. y=simple(y) y = -38/493*cos(5*t)+50/493*sin(5*t)+C1*exp(-3*t)+C2*exp(-2*t) In most engineering problems the right side of the non−homogeneous ODE consists of elementary functions such as k (constant). e . and linear combinations of these.55) we obtain – 25 k 3 sin 5t – 25k 4 cos 5 t + 25k 3 cos 5 t – 25k 4 sin 5 t + 6k 3 sin 5t + 6k 4 cos 5 t = 4 cos 5 t Collecting like terms and equating sine and cosine terms. Then.sin 5t + -------.59) We use MATLAB to solve (5.56).

the most general form of the forced response y F ( t ) is the linear combination of these terms. r = – 2 .11 Find the total solution of the ODE d 2y 2 dy – 2t – 2t + 4 ----. that is. This term with n = 1 .+ cy = f ( t ) 2 dt dt f (t) k (constant) k t ( n = positive integer) ke rt n 2 Form of Forced Response y F ( t ) K (constant) K0 t + K1 t Ke rt n n–1 + … + Kn – 1 t + Kn ( r =real or complex) k cos αt or k sin αt ( α =constant) K 1 cosαt + K 2 sin αt k t e cos αt or k t e sin α t n rt n rt ( K0 t + K1 t n n n–1 + … + K n – 1 t + K n )e cos αt + … + K n – 1 t + K n )e sin αt rt rt + ( K0 t + K1 t n–1 We must remember that if f ( t ) is the sum of several terms. and State Equations ODE with constant coefficients.62) To find the forced response (particular solution). we must multiply y F ( t ) by the lowest power of t that will eliminate the duplication. Also.+ 4y = te – e dt dt (5.+ b ----. The roots of the characteristic equation are equal. if a term in y F ( t ) is a duplicate of a term in the natural response y N ( t ) . State Variables. we refer to the table of the previous page and from the last row we choose the term k t e cos αt . Third Edition Copyright © Orchard Publications . n rt 5−18 Numerical Analysis Using MATLAB® and Excel®. and α = 0 .Chapter 5 Differential Equations. therefore we will express solution in terms of the constants k 1 and k 2 . Example 5. s 1 = s 2 = – 2 .61) Solution: No initial conditions are given.1 Form of the forced response for 2nd order differential equations d y dy Forced Response of the ODE a ------. and thus the natural response has the form yN = k1 e –2 t + k 2 te –2 t (5. TABLE 5.

64) into the given ODE of (5.64) % Compute and simplify first derivative f1 = -t*exp(-2*t)*(-3*k3*t-2*k4+2*k3*t^2+2*k4*t) f2=diff(f0. we need to evaluate the constants k 3 and k 4 .64) and combining the forced response with the natural response.62) by t to obtain a suitable form for the forced response which now is y F = ( k 3 t + k 4 t )e 3 2 –2 t – 2t – 2t (5. that is 2 ( 3k 3 t + k 4 )e – 2t = te – 2t –e – 2t (5.t e 6 2 (5.Using the Method of Undetermined Coefficients for the Forced Response reduces to kte –2 t .61). f2=simple(f2) % Compute and simplify second derivative f2 = 2*exp(-2*t)*(3*k3*t+k4-6*k3*t^2-4*k4*t+2*k3*t^3+2*k4*t^2) f=f2+4*f1+4*f0. therefore. f1=simple(f1) % Define symbolic variables % Forced response (5. we obtain the total solution y ( t ) = k1 e –2 t + k 2 te –2 t 1 3 –2 t 1 2 –2 t + -. we equate f above with the right side of the given ODE. This is done by substituting (5. f1=diff(f0). We use MATLAB do the computations as shown below. Therefore the forced response will have the form y F = ( k 3 t + k 4 )e –2 t (5.66) We verify this solution with MATLAB as follows: z=dsolve('D2y+4*Dy+4*y=t*exp(−2*t)−exp(−2*t)') z = 1/6*exp(-2*t)*t^3-1/2*exp(-2*t)*t^2 +C1*exp(-2*t)+C2*t*exp(-2*t) Numerical Analysis Using MATLAB® and Excel®. we multiply (5. f=simple(f) % Form and simplify the left side of the given ODE f = 2*(3*k3*t+k4)*exp(-2*t) Finally.63) 2 But the terms e and te are also present in (5. Third Edition Copyright © Orchard Publications 5−19 . By substitution of these values into (5.61) and equating with the right side.t e – -.65) and we find k 3 = 1 ⁄ 6 and k 4 = – 1 ⁄ 2 .2).64) Now. syms t k3 k4 f0=(k3*t^3+k4*t^2)*exp(−2*t).

⋅ ------. then. State Variables.= f ( t ) dt dt dt dt (5. method of variation of parameters Solution: With either method.6 Using the Method of Variation of Parameters for the Forced Response In certain non−homogeneous ODEs.+ α ( t ) ----.67) provided that the general form of the natural response is known.12 Find the total solution of d 2 y + 4 dy + 3y = 12 ----------2 dt dt (5. we must first find the natural response. Third Edition Copyright © Orchard Publications .y1 + ------. and State Equations 5.68) and (5. method of undetermined coefficients b. For these ODEs we must use the method of variation of parameters. Example 5.68) (5. This method will work with all linear equations including those with variable coefficients such as dy d2 y ------. The method of variation of parameters replaces the constants k 1 and k 2 by two variables u 1 and u 2 that satisfy the following three relations: y = u1 y1 + u2 y2 du1 du2 -----.71) in terms of the constants k 1 and k 2 by the a.y2 = 0 dt dt du1 dy1 du 2 dy 2 ------. Our discussion will be restricted to second order ODEs with constant coefficients.⋅ ------. the right side f ( t ) cannot be determined by the method of undetermined coefficients.Chapter 5 Differential Equations. integration of these will produce u 1 and u 2 .67) will yield the total solution.+ ------. The characteristic equation yields 5−20 Numerical Analysis Using MATLAB® and Excel®.69) will yield the values of du1 ⁄ dt and du 2 ⁄ dt .70) Simultaneous solution of (5. which when substituted into (5.+ β ( t )y = f ( t ) 2 dt dt (5.69) (5.

( – e – t ) + ------. du 2 du 1 ------. the natural response is yN = k1 e + k2 e –t –3 t (5. Therefore.77) Next.= ------------------------------.e = 0 dt dt (5.72) and we let the solutions y 1 and y 2 be represented as y1 = e –t and y 2 = e – 3t (5. Third Edition Copyright © Orchard Publications 5−21 .( – 3e – 3t ) = 12 dt dt (5.= f ( t ) dt dt dt dt or du 1 du 2 ------.76) and from (5.y 2 = 0 dt dt or du 1 – t du 2 – 3t ------.+ ------.71) we obtain k 3 = 4 and thus the total solution is y ( t ) = yN + yF = k1 e + k2 e –t –3 t +4 (5. Using the method of undetermined coefficients we let y F = k 3 (a constant).74) Then by (5.= -----------------------------------------.y 1 + ------.⋅ ------. from (5. by substitution into (5.⋅ ------. With the method of variation of parameters we begin with the natural response found above as (5. Then.e + ------.Using the Method of Variation of Parameters for the Forced Response the roots s 1 = – 1 and s 2 = – 3 .73) b.75) Also. we find du1 ⁄ dt and du 2 ⁄ dt by Cramer’s rule as follows: 0 e – 3t – 3t – 3t – 3t du 1 t 12 – 3e – 12e – 12e ------. du1 dy1 du 2 dy 2 ------.69).= ----------------.68).72) a.= 6e –t – 3t – 4t – 4t – 4t dt e – 3e + e – 2e e (5.78) –e –t – 3e – 3t and Numerical Analysis Using MATLAB® and Excel®. the total solution is y = u1 y1 + u2 y2 or y = u1 e + u2 e –t – 3t (5.70).

79) Now. by (5. Solution: This ODE cannot be solved by the method of undetermined coefficients.75) yields u 1 = 6 e dt = 6e + k 1 y = u1 e + u2 e –t –t – 3t t ∫ t t u 2 = – 6 e dt = – 2 e + k 2 –t 3t – 3t ∫ 3t 3t (5. State Variables.Chapter 5 Differential Equations.+ 4y = tan 2t 2 dt 2 (5. The characteristic equation is s + 4 = 0 from which s = ± j2 and thus the natural response is yN = k1 e j2t 2 + k2 e – j 2t (5. Third Edition Copyright © Orchard Publications . and State Equations e –t 0 –t –t du 2 3t 12e –e 12------.81) is the same as (5.73) of part (a).13 Find the total solution of d y ------. therefore.85) We let y 1 = cos 2t and y 2 = sin 2t Then.= -------------------------------. we will use the method of variation of parameters.68) the solution is y = u1 y 1 + u 2 y 2 = u1 cos 2t + u 2 sin 2t 5−22 Numerical Analysis Using MATLAB® and Excel®. Check with MATLAB: y=dsolve('D2y+4*Dy+3*y=12') y = (4*exp(t)+C1*exp(-3*t)*exp(t)+C2)/exp(t) Example 5.82) in terms of the constants k 1 and k 2 by any method.79) and substitution into (5.81) = ( 6e + k 1 )e + ( – 2 e + k 2 )e – 3t = 6 + k1 e – 2 + k2 e = k1 e + k2 e –t – 3t +4 We observe that the last expression in (5. integration of (5.78) and (5.84) (5.= -------------.83) (5.80) (5.= – 6 e – 4t – 4t dt – 2e – 2e (5.

⋅ ------.91) 1 cos 2t u 2 = -.+ k 2 sin 2t .+ k 2 2 4 ∫ sin 2t cos 2t 1 sin 2t cos 2t y = u1 y 1 + u 2 y 2 = -------------------------.89) Now.= ----------------2 2 cos 2t sin 2t 2 cos 2t dt 2 cos 2t + 2 sin 2t – 2 sin 2t 2 cos 2t 0 sin 2t 2 (5. integration of (5.85) yields 1 sin 2t sin 2t 1 u 1 = – -.( 2 cos 2t ) = tan 2t dt dt dt dt dt dt (5.-------------.y1 + ------. du 2 du1 dy1 du 2 dy 2 du1 ------. we find du1 ⁄ dt and du 2 ⁄ dt by Cramer’s rule as follows: sin 2t – -------------2 du1 tan 2t 2 cos 2t cos 2t – sin 2t ------.90) (5.⋅ ------.88) and cos 2t 0 du 2 sin 2t – 2 sin 2t tan 2t ------. Third Edition Copyright © Orchard Publications 5−23 .cos 2t + ------.Using the Method of Variation of Parameters for the Forced Response Also. from (5.70).87) Next.ln ( sec 2t + tan 2t ) + k 1 4 2 cos 2t 4 ∫ 2 (5.88) and (5.69).= f ( t ) = ------.= -------------------------------------------------.= -----------------------------------------------------.sin 2t dt = – ------------.y 2 = 0 dt dt or du 2 du1 ------.86) and from (5. du1 du 2 ------.cos 2t ln ( sec 2t + tan 2t ) + k 1 cos 2t – -------------------------.= ------------------------------------------.– -.92) Check with MATLAB: y=dsolve('D2y+4*y=tan(2*t)') y = -1/4*cos(2*t)*log((1+sin(2*t))/cos(2*t))+C1*cos(2*t)+C2*sin(2*t) Numerical Analysis Using MATLAB® and Excel®.sin 2t = 0 dt dt (5.( – 2 sin 2t ) + ------.= -----------2 2 dt (5.4 4 4 1 = – -.89) and substitution into (5.– -.+ ------.cos 2t ln ( sec 2t + tan 2t ) + k 1 cos 2t + k 2 sin 2t 4 (5.dt = -----------.

14 A system is described by the integro−differential equation di 1 .+ --dt C t ∫ – ∞ i dt = e jωt (5. or simply state equations.98) (5.+ a 0 y ( t ) = x ( t ) dt (5. Example 5.= x 1 dt dt Then.Chapter 5 Differential Equations.93) In a second order differential equation the highest order is a second derivative. we define two state variables x 1 and x 2 such that x1 = i (5.i = -. State equations can also be solved with numerical methods such as Taylor series and Runge− Kutta methods.97) (5.Ri + L ---.= ------. 2 2 · x 2 = d i ⁄ dt 5−24 Numerical Analysis Using MATLAB® and Excel®. The state variable method is best illustrated through several examples presented in this chapter.---.+ ------.------t + --. The resulting first−order differential equations are called state space equations. The state variable method offers the advantage that it can also be used with non−linear and time−varying systems. However.-----. time−invariant systems.= – --.jωe 2 L L dt LC dt jωt (5.R di .7 Expressing Differential Equations in State Equation Form A first order differential equation with constant coefficients has the form dy a 1 ----.99) and dx 1 di · x 2 = ---. State Variables. these will be discussed in Chapter 9. and State Equations 5.94) Differentiating both sides and dividing by L we obtain 2 1 1d . An nth−order differential equation can be resolved to n first−order simultaneous differential equations with a set of auxiliary variables called state variables. Third Edition Copyright © Orchard Publications .i + -.jωe 2 L L dt LC dt jωt (5.---.– ------.96) Next.95) or 2 1 R di 1 d t . our discussion will be limited to linear.

· x2 A = 0 1 – -----LC 1 . and d is a column vector. we obtain the state equations · x1 = x2 1 1 jωt R · x 2 = – -. b= 1 .101) We usually write (5.100) as 0 · x1 = 1 · – -----x2 LC 1 x 0 1 + 1 u R – -. Third Edition Copyright © Orchard Publications 5−25 .105) can be realized with the block diagram of Figure 5.102) 0 where · x · x = 1.x 2 -. Block diagram for the realization of the state equations of (5.100) It is convenient and customary to express the state equations in matrix form.99). –R -L x = x1 x2 . we write the state equations of (5. and u = any input -.101) in a compact form as · x = Ax + bu (5. · x + A d u b + Σ ∫ dt x C + Σ + y Figure 5.103) The output y ( t ) is expressed by the state equation y = Cx + du (5.x 2 – -----.104) where C is another matrix.1.105) The state space equations of (5. Therefore.4. Thus.j ω e jωt L (5.j ω e jωt L L (5. the state representation of a system can be described by the pair of the of the state space equations · x = Ax + bu y = Cx + du (5.jωe L LC L (5. From (5.Expressing Differential Equations in State Equation Form · where x k denotes the derivative of the state variable x k .96) through (5.x 1 + -.105) Numerical Analysis Using MATLAB® and Excel®.

we must define four state variables that will be used with the resulting four first−order state equations. x 3 . and we relate them to the terms of the given differential equation as x1 = y ( t ) dy x 2 = ----dt d y x 3 = -------2 dt 2 d y x 4 = -------3 dt 3 (5. Third Edition Copyright © Orchard Publications . We denote the state variables as x 1.Chapter 5 Differential Equations.106) is of fourth−order.= x 4 = – a 0 x 1 – a 1 x 2 – a 2 x 3 – a 3 x 4 + u ( t ) 4 dt 4 (5.106) as a set of state equations. State Variables. (5. and x 4 . x 2. Solution: The differential equation of (5.15 A fourth−order system is described by the differential equation 4 d y + a d y + a d y + a dy + a y ( t ) = u ( t ) --------3 -------2 ------1 ----0 3 2 4 dt dt dt dt 3 2 (5.108) and in matrix form · x1 · x2 · x3 · x4 0 0 = 0 –a0 1 0 0 –a1 0 1 0 –a2 0 0 1 –a3 x1 0 x2 + 0 u(t) x3 0 1 x4 (5. Example 5.109) In compact form. Express (5.105) in the subsequent sections. therefore.107) We observe that · x1 = x2 · x2 = x3 · x3 = x4 d y · --------.109) is written as · x = Ax + bu (5.110) where 5−26 Numerical Analysis Using MATLAB® and Excel®.106) where y ( t ) is the output and u ( t ) is any input. and State Equations We will learn how to solve the matrix equations of (5.

we differentiate (5.113).111). Then.114) is zero since the upper and lower limits of integration are the same.112) We will now prove that the solution of the first state equation in (5. and k 2 are scalar constants. (5.8 Solution of Single State Equations Let us consider the state equations · x = αx + βu y = k1 x + k2 u (5. k 1 .( e x 0 ) + ---.α ( t – t0 ) d.113) satisfies also the first equation in (5. x ( t0 ) = e α ( t0 – t0 ) x0 + e αt ∫t t0 0 e –α τ β u ( τ ) dτ (5.111) where α . 0 b= 0. and u = u ( t ) 5. and the initial condition.111) is x(t) = e α ( t – t0 ) x0 + e αt ∫t e 0 t – ατ β u ( τ ) dτ (5.115) The second term of (5. we must show that (5.113) with respect to t and we obtain d. we must prove that (5. Third Edition Copyright © Orchard Publications 5−27 .114) The first term in the right side of (5. Next. 0 1 · x= . β . Therefore.113) satisfies the initial condition of (5. To prove this. if non−zero.113) Proof: First.114) reduces to x ( t 0 ) = x 0 and thus the initial condition is satisfied.114) reduces to x 0 since e α ( t0 – t0 ) x0 = e x0 = x0 0 (5. 1 –a3 x1 x= x2 x3 x4 .⎨ e dt dt ⎩ ∫t e 0 t – ατ β u ( τ ) dτ ⎬ ⎫ ⎭ Numerical Analysis Using MATLAB® and Excel®. is denoted as x0 = x ( t0 ) (5.Solution of Single State Equations · x1 · x2 · x3 · x4 0 0 A= 0 –a0 1 0 0 –a1 0 1 0 –a2 0 0 .⎧ αt · x ( t ) = ---.112). This is done by substitution of t = t 0 in (5.

Chapter 5 Differential Equations. · x = αx + βu and this is the same as the first equation of (5.113). and we will prove that the solution of the matrix differential equation · (5.116) We observe that the bracketed terms of (5. In this section we will introduce the state transition matrix e . and State Equations α ( t – t0 ) αt · x(t) = αe x0 + α e α ( t – t0 ) αt ∫t ∫t t 0 t 0 e e – ατ β u ( τ ) dτ + e [ e αt – ατ βu(τ)] τ = t βu(t) = α e x0 + e t 0 – ατ β u ( τ ) dτ + e e αt – αt α ( t – t0 ) · x(t)= α e x0 + ∫t e α(t – τ) β u ( τ ) dτ + β u ( t ) (5.111). Third Edition Copyright © Orchard Publications .111) is an algebraic equation whose coefficients are scalar constants. and b and d are column vectors with two or more rows.120) where for two or more simultaneous differential equations A and C are 2 × 2 or higher order matrices.119) 5. The second equation of (5. Therefore. if α and β are scalar constants. the solution of · x = αx + βu (5.118) with initial condition x0 = x ( t0 ) is obtained from the relation x( t) = e α ( t – t0 ) x0 + e αt ∫t e 0 t –α τ β u ( τ ) dτ (5. State Variables.117) (5.121) x = Ax + bu with initial conditions (5. In summary.116) are the same as the right side of the assumed solution of (5.9 The State Transition Matrix Let us again consider the state equations pair · x = Ax + bu y = Cx + du (5.122) x ( t0 ) = x0 is obtained from the relation At 5−28 Numerical Analysis Using MATLAB® and Excel®.

if it is related to the matrix A as the matrix power series ϕ(t) ≡ e At 1 22 1 33 1 nn = I + At + ---.A t 3! 2! n! (5.120) is also satisfied.123) is the solution of the first equation of (5. we must prove that it satisfies both the initial condition and the matrix differential equation.127).127) To prove that (5. Third Edition Copyright © Orchard Publications 5−29 . that is.34).124) where I is the n × n identity matrix.124) with respect to t yields d At 2 2 ϕ' ( t ) = ---.124).123) Proof: Let A be any n × n matrix whose elements are constants. From (5. Then.A t + … + ---.125) Differentiation of (5.124) we obtain d ---.The State Transition Matrix x(t) = e A ( t – t0 ) x0 + e At ∫t e 0 t –A τ bu ( τ ) dτ (5. The integral is zero since the upper and lower limits of integration are the same.126) and by comparison with (5. another n × n matrix denoted as ϕ ( t ) . we differentiate the assumed solution x( t) = e A ( t – t0 ) x0 + e At ∫t e 0 t –A τ bu ( τ ) dτ with respect to t and we use (5.e = 0 + A ⋅ 1 + A t + … = A + A t + … dt (5. d ---.e At = Ae At dt Numerical Analysis Using MATLAB® and Excel®.120). is said to be the state transition matrix of (5.128) where we have used (5. To prove that the first equation of (5.e At = Ae At dt (5.A t + ---. we find that ϕ(0) = e A0 = I + A0 + … = I (5.125) for the initial condition. The initial condition is satisfied from the relation x ( t0 ) = e A ( t0 – t0 ) x0 + e At 0 ∫t t0 0 e –A τ bu ( τ ) dτ = e A0 x 0 + 0 = Ix 0 = x 0 (5.

134) 5−30 Numerical Analysis Using MATLAB® and Excel®.130) with initial condition x0 = x ( t0 ) (5. the solution of · x ( t ) = Ax + bu (5. A ( t – t0 ) At · x ( t ) = Ae x 0 + Ae t ∫t e 0 –A τ bu ( τ ) dτ + e e At – A t bu ( t ) or A ( t – t0 ) At · x0 + e x(t) = A e ∫t e 0 t –A τ bu ( τ ) dτ + e e At – A t bu ( t ) (5.129) as x ( t ) . if A is an n × n matrix whose elements are constants. By definition.133) We recall that expansion of a determinant produces a polynomial.132) Therefore. and I be the n × n identity matrix. This theorem states that a matrix can be expressed as an ( n – 1 )th degree polynomial in terms of the matrix A as e At At = a0 I + a1 A + a2 A + … + an – 1 A 2 n–1 (5. the expression (5.Chapter 5 Differential Equations. or complex numbers. and the last term as bu ( t ) . n of A are the roots of the nth order polynomial det [ A – λI ] = 0 At Let A be an n × n matrix. Thus. and b is a column vector with n elements. Third Edition Copyright © Orchard Publications .131) is x(t) = e A ( t – t0 ) x0 + e At ∫t e 0 t –A τ bu ( τ ) dτ (5. the solution of second or higher order systems using the state variable method.129) reduces to · x ( t ) = Ax + bu In summary. …. Evaluation of the state transition matrix e is based on the Cayley−Hamilton theorem.10 Computation of the State Transition Matrix e i = 1. and integration of (5. The roots of the polynomial of (5. n ≥ 2 . (5. and State Equations Then.132). 2.133) can be real (unequal or equal). the eigenvalues λ i .129) We recognize the bracketed terms in (5. At 5. State Variables. entails the computation of the state transition matrix e .

135) = e λn t Example 5. Since A is a 2 × 2 matrix. Since the coefficients a i are functions of the eigenvalues λ . Numerical Analysis Using MATLAB® and Excel®. det [ A – λI ] = 0 At given that A = – 2 1 0 –1 ⎧ ⎫ 1 det [ A – λI ] = det ⎨ – 2 1 – λ 1 0 ⎬ = det – 2 – λ = 0 0 1 ⎭ 0 –1–λ ⎩ 0 –1 or Therefore.134). The proof can be found in Linear Algebra and Matrix Theory textbooks. if all eigenvalues of a given matrix A are distinct. that is. we must consider the following cases: Case I: Distinct Eigenvalues (Real or Complex) If λ 1 ≠ λ 2 ≠ λ 3 ≠ … ≠ λ n . we only need to consider the first two terms of that relation.16 Compute the state transition matrix e Solution: We must first find the eigenvalues λ of the given matrix A . These are found from the expansion of For this example.136) Next. we must find the coefficients a i of (5.Computation of the State Transition Matrix where the coefficients a i are functions of the eigenvalues λ . = (– 2 – λ)(– 1 – λ) = 0 (λ + 1)(λ + 2) = 0 λ 1 = – 1 and λ 2 = – 2 (5. We accept (5. Third Edition Copyright © Orchard Publications 5−31 .134) without proving it. the coefficients a i are found from the simultaneous solution of the following system of equations: a0 + a1 λ1 + a2 λ1 + … + an – 1 λ1 a0 + a1 λ2 + a2 λ2 + … + an – 1 λ2 … a0 + a1 λn + a2 λn + … + an – 1 λn 2 n–1 2 2 n–1 n–1 = e = e λ1 t λ2 t (5. that is.

137). we use the first 3 terms.139) and by substitution into (5. Third Edition Copyright © Orchard Publications . We find the eigenvalues λ from det [ A – λI ] = 0 . If the dimension of A is a 2 × 2 matrix. For this example. State Variables.138) Simultaneous solution of (5. If the dimension of A is a 2 × 2 matrix. if it is a 3 × 3 matrix. and so on.135). it will yield three eigenvalues. otherwise we refer to Case II. we perform steps 2 through 4 below. it will yield two eigenvalues.141) If A matrix is a 3 × 3 matrix. a0 + a1 λ1 = e a0 + a1 λ2 = e λ1 t λ2 t or a0 + a1 ( –1 ) = e a0 + a1 ( –2 ) = e –t – 2t (5. and State Equations e At = a0 I + a1 A (5. 5−32 Numerical Analysis Using MATLAB® and Excel®. we compute the state transition matrix e procedure: At for a given matrix A using the following 1.138) yields a 0 = 2e – e a1 = e – e –t –t – 2t – 2t (5.Chapter 5 Differential Equations. We can write [ A – λI ] at once by subtracting λ from each of the main diagonal elements of A .140) 0 In summary. e At = ( 2e – e –t – 2t ) 1 0 0 1 –t + (e – e –t – 2t ) –2 1 0 –1 or e At = e – 2t e –e e –t – 2t (5. and so on. we use only the first 2 terms of the right side of the state transition matrix e At = a0 I + a1 A + a2 A + … + an – 1 A 2 n–1 (5. If the eigenvalues are distinct. 2.137) The coefficients a 0 and a 1 are found from (5.

r=roots(p)... r(1)). fprintf('lambda1 = %5.00 lambda3 = 1. Example 5. We obtain [ A – λI ] at once.17 Compute the state transition matrix e At given that 7 –5 4 –1 8 –3 5 A = 0 2 (5. We obtain the a i coefficients from a0 + a1 λ1 + a2 λ1 + … + an – 1 λ1 a0 + a1 λ2 + a2 λ2 + … + an – 1 λ2 … a0 + a1 λn + a2 λn + … + an – 1 λn 2 n–1 2 2 n–1 n–1 λ1 t λ2 t = e = e = e λn t We use as many equations as the number of the eigenvalues. 4.. We substitute the a i coefficients into the state transition matrix of (5.2f \t'.00 lambda2 = 2.143) and expansion of this determinant yields the polynomial λ – 6λ + 11λ – 6 = 0 3 2 (5.141). det [ A – λI ] = det 5–λ 0 2 7 –5 = 0 4–λ –1 8 –3–λ (5. Third Edition Copyright © Orchard Publications 5−33 .2f'. r(2)). r(3)) lambda1 = 3. fprintf('lambda2 = %5.00 and thus the eigenvalues are Numerical Analysis Using MATLAB® and Excel®. fprintf('lambda3 = %5.142) Solution: 1. and we solve for the coefficients ai .Computation of the State Transition Matrix 3.144). Then. and we simplify.144) We will use MATLAB roots(p) function to obtain the roots of (5. We first compute the eigenvalues from det [ A – λI ] = 0 .2f \t'. by subtracting λ from each of the main diagonal elements of A . fprintf(' \n'). p=[1 −6 11 −6].

fprintf(' \n'). b=sym('[exp(t).147) We will use the following MATLAB script for the solution of (5. syms t.e + 4e – -. Since A is a 3 × 3 matrix. disp('a0 = '). exp(3*t)]'). 1 2 4.. we need to use the first 3 terms of (5. disp(a(1)). disp('a1 = '). A = [5 7 −5. We obtain the coefficients a 0. 0 4 −1. a 0 = 3e – 3e + e t 2t 3t 5 t 2t 3 3t a 1 = – -. a0 = 3*exp(t)+exp(3*t)−3*exp(2*t).148) 4.147).145) 2. 1 3 9]').146) 3. and State Equations λ1 = 1 λ2 = 2 λ3 = 3 (5. disp(a(3)) a0 = 3*exp(t)-3*exp(2*t)+exp(3*t) a1 = -5/2*exp(t)+4*exp(2*t)-3/2*exp(3*t) a2 = 1/2*exp(t)-exp(2*t)+1/2*exp(3*t) Thus. Third Edition Copyright © Orchard Publications .. a1 = −5/2*exp(t)−3/2*exp(3*t)+4*exp(2*t). eAt=a0*eye(3)+a1*A+a2*A^2 5−34 Numerical Analysis Using MATLAB® and Excel®. State Variables.134). a=B\b... e At = a0 I + a1 A + a2 A 2 (5..e 2 2 1 t 2t 1 3t a 2 = -. The script is shown below. We also use MATLAB to perform the substitution into the state transition matrix. disp('a2 = '). that is..Chapter 5 Differential Equations. and a 2 from a0 + a1 λ1 + a2 λ1 = e a0 + a1 λ2 + a2 λ2 = e a0 + a1 λ3 + a2 λ3 = e 2 2 2 λ1 t λ2 t λ3 t or a0 + a1 + a2 = e a 0 + 2a 1 + 4a 2 = e a 0 + 3a 1 + 9a 2 = e t 2t 3t (5. disp(a(2)).e – e + -.. a 1. a2 = 1/2*exp(t)+1/2*exp(3*t)−exp(2*t). B=sym('[1 1 1. exp(2*t)...e 2 2 (5. 2 8 −3]. and to perform the matrix multiplications.

λm + 1 . 6*exp(t)-6*exp(2*t)+exp(3*t)] Thus.152) below. For this example.151) are found from the simultaneous solution of the system of equations of (5.150) The coefficients a i of the state transition matrix e At = a0 I + a1 A + a2 A + … + an – 1 A 2 n–1 (5. 4*exp(t)-3*exp(2*t)-exp(3*t)] [-exp(t)+2*exp(2*t)-exp(3*t).-6*exp(t)+5*exp(2*t)+exp(3*t). We first find the eigenvalues λ of the matrix A and these are found from the polynomial of det [ A – λI ] = 0 .-9*exp(t)+10*exp(2*t)-exp(3*t).149) has n roots. and m of these roots are equal. the roots are λ1 = λ2 = λ3 … = λm . e At – 2e + 2e + e = – e + 2e – e t 2t t 2t t 2t 3t – 6 e + 5e + e – 3e + 5e – e t 2t t 2t 3t t 2t 3t 4e – 3e – e 2e – 3e + e 6e – 6e + e t 2t t 2t t 2t 3t 3t 3t 3t 3t – 3e + 4e – e – 9e + 10e – e 3t Case II: Multiple Eigenvalues In this case. we will assume that the polynomial of det [ A – λI ] = 0 (5. In other words. Numerical Analysis Using MATLAB® and Excel®. λn (5.18 Compute the state transition matrix e At given that A = –1 0 2 –1 Solution: 1. Example 5. Third Edition Copyright © Orchard Publications 5−35 . 2*exp(t)-3*exp(2*t)+exp(3*t)] [-3*exp(t)+4*exp(2*t)-exp(3*t).Computation of the State Transition Matrix eAt = [-2*exp(t)+2*exp(2*t)+exp(3*t).-3*exp(t)+5*exp(2*t)-exp(3*t).

Chapter 5 Differential Equations.e 1 dλ 1 dλ 1 or a0 + a1 λ1 = e λ1 t λ1 t a 1 = te and by substitution with λ 1 = λ 2 = – 1 .λt d -------2 ( a 0 + a 1 λ 1 + a 2 λ 2 + … + a n – 1 λ n – 1 ) = -------2 e 1 1 1 dλ 1 dλ 1 … d d -------------. and State Equations a0 + a1 λ1 + a2 λ1 + … + an – 1 λ1 2 n–1 = e λ1 t d d λt -------.152). Third Edition Copyright © Orchard Publications .152) λ1 t λ m + 1t … = e λn t 0 = 0 det [ A – λI ] = det – 1 – λ 2 –1–λ = (– 1 – λ)(– 1 – λ) = 0 = (λ + 1) = 0 λ1 = λ2 = –1 2 and thus.e 1 1 m–1 m–1 dλ 1 dλ 1 a0 + a1 λm + 1 + a2 λm + 1 + … + an – 1 λm + 1 = e a 0 + a 1 λn + a 2 λ n + … + a n – 1 λ n 2 n–1 2 n–1 m–1 m–1 2 2 (5.153) 3. We find a 0 and a 1 from (5. we only need the first two terms of the state transition matrix. Since A is a 2 × 2 matrix. e At = a0 I + a1 A (5.( a 0 + a 1 λ 1 + a 2 λ 2 + … + a n – 1 λ n – 1 ) = ------. a0 + a1 λ1 = e λ1 t dd. we obtain 5−36 Numerical Analysis Using MATLAB® and Excel®.λ t -------.( a 0 + a 1 λ 1 ) = -------.( a 0 + a 1 λ 1 + a 2 λ 2 + … + a n – 1 λ n – 1 ) = -------------. For this example. State Variables. that is.e 1 1 1 dλ 1 dλ 1 d . 2.

and we will briefly discuss eigenvectors on the next section. we obtain e At –t –t = ( e + te ) 1 0 0 0 + te – t – 1 0 = e At = e –t –t 2 –1 1 2te e –t (5.154) 4. We will first use MATLAB to verify the values of the eigenvalues found in Examples 5. Third Edition Copyright © Orchard Publications 5−37 . we invoke the help eig command.18: C = [−1 0. To find out how it is used. 0 4 −1.0000 For Example 5. lambda=eig(C) lambda = -1 -1 Numerical Analysis Using MATLAB® and Excel®.17: B = [5 7 −5.154) into (5. lambda=eig(B) lambda = 1.155) We can use the MATLAB eig(x) function to find the eigenvalues of an n × n matrix.18.16 through 5.0000 2.0000 3. 0 −1]. lambda=eig(A) lambda = -2 -1 For Example 5.Computation of the State Transition Matrix a0 – a1 = e –t –t a 1 = te Simultaneous solution of the last two equations yields a 0 = e + te a 1 = te –t –t –t (5. For Example 5.16: A= [−2 1. 2 8 −3].153). By substitution of (5. 2 −1].

We can express this relation in matrix form as a 11 a 12 … a 1n x 1 a 21 a 22 … a 2n x 2 … … … … … a n1 a n2 … a nn x n = λ x1 x2 … xn (5.157) as or ( a 11 – λ )x 1 a 21 x 1 … an 1 x1 ( A – λI )X = 0 a 12 x 2 … an2 x2 … a1 n xn a2 n xn = 0 (5. We can express (5.156) where A is an n × n matrix.159) will have non−trivial solutions if and only if its determinant is zero*. and corresponding to each eigenvalue λ . if ( a 11 – λ ) det a 21 … an 1 a 12 … an2 … a1n a2n = 0 ( a 22 – λ ) … … … … ( a nn – λ ) (5. and λ is a scalar number. and it is called the characteristic equation. Third Edition Copyright © Orchard Publications .159) The equations of (5.160) Expansion of the determinant of (5. 5−38 Numerical Analysis Using MATLAB® and Excel®.160) results in a polynomial equation of degree n in λ . there is a non−trivial solution of the column vector X . This is because we want the vector X in (5.158) ( a 22 – λ )x 2 … … … … ( a nn – λ )x n (5. and State Equations 5.160) in a compact form as det ( A – λI ) = 0 (5. *.161) As we know.. State Variables. the roots λ of the characteristic equation are the eigenvalues of the matrix A . i.e. X is a column vector.Chapter 5 Differential Equations.157) We write (5.158) to be a non−zero vector and the product ( A – λI )X to be zero. that is.11 Eigenvectors Consider the relation AX = λX (5.

We begin with and we let Then. Form a set of unit eigenvectors using the eigenvectors of part (b). and I is the identity matrix.19 Given the matrix 5 A = 0 2 7 –5 4 –1 8 –3 a. it is discussed in Chapter 14. Eigenvectors are generally expressed as unit eigenvectors. they are normalized to unit length. Third Edition Copyright © Orchard Publications 5−39 . Obviously. A set of eigenvectors constitutes an orthonormal basis if the set is normalized (expressed as unit eigenvectors) and these vector are mutually orthogonal. there is a different eigenvector for each Two vectors X and Y are said to be orthogonal if their inner (dot) product is zero. its eigenvalues. This is done by dividing each component of the eigenvector by the square root of the sum of the squares of their components. so that the sum of the squares of their components is equal to unity. Find the eigenvalues of A b. In many engineering applications the unit eigenvectors are chosen such that X ⋅ X = I where X is the transpose of the eigenvector X . illustrates the relationships between a matrix A . that is. Numerical Analysis Using MATLAB® and Excel®. An orthonormal basis can be formed with the Gram− Schmidt Orthogonalization Procedure. Solution: a.17. T T X ≠ 0 . Example 5. where we found the eigenvalues to be λ1 = 1 λ2 = 2 AX = λX x1 X = x2 x3 λ3 = 3 b. This vector X is called eigenvector. Find eigenvectors corresponding to each eigenvalue of A c. This is the same matrix as in Example 5. The example which follows.Eigenvectors eigenvalue. and eigenvectors.

Third Edition Copyright © Orchard Publications . and x 3 = 2x 2 . an eigenvector for λ = 2 is 5−40 Numerical Analysis Using MATLAB® and Excel®. or MATLAB. and x 3 are scalars. we obtain x 1 = 2x 2 . Then. we can assume that one of these.167).164) reduces to 4x 1 + 7x 2 – 5x 3 = 0 3x 2 – x 3 = 0 2x 1 + 8x 2 – 4x 3 = 0 (5. an eigenvector for λ = 1 is x1 Xλ = 1 = x2 = x3 2x 2 x2 3x 2 2 2 = x2 1 = 1 3 3 (5.163) Equating corresponding rows and rearranging. State Variables.167) since any eigenvector is a scalar multiple of the last vector in (5.165) By Crame’s rule. and x 3 = 3x 2 . for λ = 2 . we obtain x 1 = x 2 . (5. say x 2 . and State Equations 5 0 2 x1 7 –5 x1 4 –1 x2 = λ x2 8 –3 x3 x3 7x 2 – 5x 3 4x 2 –x3 8x 2 – 3x 3 λx 1 = λx 2 λx 3 (5. Similarly.Chapter 5 Differential Equations. x 2. is known.164) For λ = 1 . Then. we obtain ( 5 – λ )x 1 0 2x 1 7x 2 ( 4 – λ )x 2 8x 2 – 5x 3 –x3 – ( 3 – λ )x 3 0 = 0 0 (5.162) or 5x 1 0 2x 1 (5. we obtain the indeterminate values x1 = 0 ⁄ 0 x2 = 0 ⁄ 0 x3 = 0 ⁄ 0 (5. Therefore. and solve x 1 and x 3 in terms of x 2 .166) Since the unknowns x 1.

⎞ 2 = ----. for λ = 3 .Eigenvectors x1 Xλ = 2 = x2 = x3 x2 x2 2x 2 1 1 = x2 1 = 1 2 2 (5.+ ----. we obtain x 1 = – x 2 . an eigenvector for λ = 3 is x1 Xλ = 3 = x2 = x3 –x2 x2 x2 = x2 –1 –1 = 1 1 1 1 (5. Third Edition Copyright © Orchard Publications 5−41 .171) and the same is true for the other two unit eigenvectors in (5. and x 3 = x 2 .⎞ 2 + ⎛ --------.169) c.= 1 ⎝ 14 ⎠ ⎝ 14 ⎠ ⎝ 14 ⎠ 14 14 14 (5. Then. These are: 2 +1 +3 = 1 +1 +2 = ( –1 ) + 1 + 1 = 2 2 2 2 2 2 2 2 2 14 6 3 The unit eigenvectors are 2--------14 1Unit X λ = 1 = --------14 3--------14 1-----6 1Unit X λ = 2 = -----6 2-----6 –1 -----3 1Unit X λ = 3 = -----3 1-----3 (5. Numerical Analysis Using MATLAB® and Excel®.170) We observe that for the first unit eigenvector the sum of the squares is unity. that is.168) Finally.170).⎞ 2 + ⎛ --------. We find the unit eigenvectors by dividing the components of each vector by the square root of the sum of the squares of the components.+ ----. 2 1 3 4 1 9 ⎛ --------.

k n are arbitrary constants. the differential equation which relates y and x is said to be an ordinary differential equation and it is abbreviated as ODE.+ … + a 1 ----. If the forcing function is zero. in engineering the solution of the homogeneous ODE. Third Edition Copyright © Orchard Publications . the differential equation that relates y .12 Summary • Differential equations are classified by: Type − Ordinary or Partial Order − The highest order derivative which is included in the differential equation Degree − The exponent of the highest power of the highest order derivative after the differential equation has been cleared of any fractions or radicals in the dependent variable and its derivatives • If the dependent variable y is a function of only a single variable x . • The ODE d y d y dy d x d x dx a n -------. and is denoted as y F ( t ) or simply y F . Also. where x and t are independent variables. and t is said to be a partial differential equation and it is abbreviated as PDE.+ … + b 1 ----. • Generally.+ a n – 1 --------------. also known as the complementary solution. The particular solution of a non−homogeneous ODE is be referred to as the forced response. …. known as forcing function. 5−42 Numerical Analysis Using MATLAB® and Excel®. t ) .+ b m – 1 ---------------. that is.Chapter 5 Differential Equations. the differential equation is referred to as homogeneous differential equation. x . • If the dependent variable y is a function of two or more variables such as y = f ( x.+ a 0 y = b m --------. State Variables. is referred to as the natural response. • The most general solution of an homogeneous ODE is the linear combination yH ( t ) = k1 y1 ( t ) + k2 y2 ( t ) + k3 y3 ( t ) + … + kn yn ( t ) where the subscript H is used to denote homogeneous and k 1. k 2. is not zero. • A function y = f ( x) is a solution of a differential equation if the latter is satisfied when y and its derivatives are replaced throughout by f ( x) and its corresponding derivatives. if y = f ( x) . that is.+ b 0 x n n–1 m n–1 dt dt dt dt dt dt n n–1 m m–1 is a non−homogeneous differential equation if the right side. the initial conditions must be satisfied. k 3. and State Equations 5. The total solution of the non−homogeneous ODE is the summation of the natural and forces responses. and is denoted as y N ( t ) or simply y N .

for two complex conjugate roots we evaluate the constants from the expressions k1 e s1 t + k2 e s2 t = e – αt ( k 3 cos βt + k 4 sin β t ) = e – αt k 5 cos ( βt + ϕ ) • The forced response of a non−homogeneous ODE can be found by the method of undetermined coefficients or the method of variation of parameters. a n – 1. It is imperative to remember that the arbitrary constants of the natural response must be evaluated from the total response. these occur as complex conjugate pairs. y 2 = k 2 e . y 3 = k 3 e . • In certain non−homogeneous ODEs. contains no arbitrary constants. Third Edition Copyright © Orchard Publications 5−43 . s 2. a 1. Then.1. s n are the solutions of the characteristic equation an s + an – 1 s n n–1 + … + a1 s + a0 = 0 and a n. • With the method of undetermined coefficients. the most general solution has the form: yN = ( k1 + k2 t + … + km t m–1 )e s1 t + kn – i e s2 t + … + kn e sn t • If the characteristic equation contains complex roots. Thus. • For an nth order homogeneous differential equation the solutions are y 1 = k 1 e . then another root is s 2 = – α – j β .Summary y( t) = y Natural Response +y Forced Response = yN + yF The natural response y N contains arbitrary constants and these can be evaluated from the given initial conditions. a 0 are the constant coefficients of the ODE • If the roots of the characteristic equation are distinct. if one root is s 1 = – α + jβ where α and β are real numbers. …. The forced response y F . …. the n solutions of the natural response are independent and the most general solution is: yN = k1 e s1 t + k2 e s2 t + … + kn e sn t • If the solution of the characteristic equation contains m equal roots. y n = k n e s1 t s2 t s3 t sn t where s 1. For these ODEs we must use the method of variation of parameNumerical Analysis Using MATLAB® and Excel®. the right side f ( t ) cannot be determined by the method of undetermined coefficients. The form of the forced response for second order non−homogeneous ODEs is given in Table 5. the forced response is a function similar to the right side of the non−homogeneous ODE. …. however.

the method of variation of parameters replaces the constants k 1 and k 2 by two variables u 1 and u 2 that satisfy the following three relations: y = u1 y1 + u2 y2 du2 du1 -----.Chapter 5 Differential Equations. State Variables. the solution of the first state equation above is x( t) = e α ( t – t0 ) t x0 + e αt ∫t e 0 – ατ β u ( τ ) dτ • In a system of state equations of the form · x = Ax + bu y = Cx + du 5−44 Numerical Analysis Using MATLAB® and Excel®. • An nth−order differential equation can be resolved to n first−order simultaneous differential equations with a set of auxiliary variables called state variables. The resulting first−order differential equations are called state space equations. if non−zero is denoted as x 0 = x ( t 0 ) . β . or simply state equations.y2 = 0 dt dt du1 dy1 du 2 dy 2 ------. Third Edition Copyright © Orchard Publications . • For second order ODEs with constant coefficients.⋅ ------. then. This method will work with all linear equations including those with variable coefficients provided that the general form of the natural response is known.⋅ ------.y1 + ------. and State Equations ters. k 1 .= f ( t ) dt dt dt dt Simultaneous solution of last two expressions above will yield the values of du1 ⁄ dt and du 2 ⁄ dt .+ ------. and the initial condition. and k 2 are scalar constants. integration of these will produce u 1 and u 2 . which when substituted into the first will yield the total solution. • The state representation of a system can be described by the pair of the of the state space equations · x = Ax + bu y = Cx + du • In a system of state equations of the form · x = αx + βu y = k1 x + k2 u where α .

A t + ---. λ m + 1 . This theorem states that a matrix can be expressed as an ( n – 1 )th degree polynomial in terms of the matrix A as e At At = a0 I + a1 A + a2 A + … + an – 1 A 2 n–1 where the coefficients a i are functions of the eigenvalues λ . the coefficients a i are found from the simultaneous solution of the following system of equations: a0 + a1 λ1 + a2 λ1 + … + an – 1 λ1 a0 + a1 λ2 + a2 λ2 + … + an – 1 λ2 … a0 + a1 λn + a2 λn + … + an – 1 λn 2 n–1 2 2 n–1 n–1 λ1 t λ2 t = e = e = e λn t • If the polynomial of det [ A – λI ] = 0 has n roots. that is.Summary where for two or more simultaneous differential equations A and C are 2 × 2 or higher order matrices.A t 2! n! 3! and I is the n × n identity matrix. n of A are the roots of the nth order polynomial det [ A – λI ] = 0 • Evaluation of the state transition matrix e is based on the Cayley−Hamilton theorem. if all eigenvalues of a given matrix A are distinct. the eigenvalues λ i . λ n . i = 1. and m of these roots are equal. and I be the n × n identity matrix. the solution of the matrix · differential equation x = Ax + bu with initial conditions x ( t 0 ) = x 0 is obtained from the relation x( t) = e A ( t – t0 ) x0 + e At ∫t e 0 t –A τ bu ( τ ) dτ where the state transition matrix e ϕ(t) ≡ e At At is defined as the matrix power series 1 22 1 33 1 nn = I + At + ---. if λ 1 = λ 2 = λ 3 … = λ m . ….A t + … + ---. 2. that is. Third Edition Copyright © Orchard Publications 5−45 . • If A is an n × n matrix. and b and d are column vectors with two or more rows. the coefficients a i of the state transition matrix e At = a0 I + a1 A + a2 A + … + an – 1 A 2 n–1 Numerical Analysis Using MATLAB® and Excel®. • If λ 1 ≠ λ 2 ≠ λ 3 ≠ … ≠ λ n .

the vector X is called eigenvector. X is a non−zero column vector. Third Edition Copyright © Orchard Publications .( a 0 + a 1 λ 1 + a 2 λ 2 + … + a n – 1 λ n – 1 ) = -------------. a0 + a1 λ1 + a2 λ1 + … + an – 1 λ1 2 n–1 = e λ1 t dd. 5−46 Numerical Analysis Using MATLAB® and Excel®.( a 0 + a 1 λ 1 + a 2 λ 2 + … + a n – 1 λ n – 1 ) = ------. and State Equations are found from the simultaneous solution of the system of equations below.λ t -------.Chapter 5 Differential Equations. and λ is a scalar number. so that the sum of the squares of their components is equal to unity. Obviously. there is a different eigenvector for each eigenvalue. Eigenvectors are generally expressed as unit eigenvectors.e 1 1 1 m–1 m–1 dλ 1 dλ 1 m–1 m–1 2 2 a0 + a1 λm + 1 + a2 λm + 1 + … + an – 1 λm + 1 = e a 0 + a 1 λn + a 2 λ n + … + a n – 1 λ n 2 n–1 2 n–1 λ m + 1t … = e λn t • We can use the MATLAB eig(x) function to find the eigenvalues of an n × n matrix. State Variables. that is.e 1 1 1 dλ 1 dλ 1 d λt d -------2 ( a 0 + a 1 λ 1 + a 2 λ 2 + … + a n – 1 λ n – 1 ) = -------2 e 1 1 1 dλ 1 dλ 1 … λ t d d -------------. they are normalized to unit length. This is done by dividing each component of the eigenvector by the square root of the sum of the squares of their components. • If A is an n × n matrix.

2 dv dv ------.+ 3y = t – 1 ------2 dt 2 2 dt dy –t 2. and let x(y) = y(t) . d y + y = sec t ------2 dt 2 5 Express the integro−differential equation below as a matrix of state equations where k 1.+ 2 ----. · x1 · x2 · x3 · x4 x1 0 1 0 0 0 x = 0 0 1 0 ⋅ 2 + 0 u(t) x3 0 0 0 1 0 –1 –2 –3 –4 1 x4 7. Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications 5−47 . and C below.+ 3y = 4e ------2 dt dt 2 dy 1 2 2 d y 3. and k 3 are constants.13 Exercises Solve the following ODEs by any method and verify your answers with MATLAB.+ k 2 v + k 1 2 dt dt ∫0 v dt t = sin 3t + cos 3t 6.Exercises 5.( cos 2t + 1 ) 2 dt dt 2 4. Express the matrix of the state equations below as a single differential equation. B . -------. Compute the eigenvalues of the matrices A . d y + 4 ----. k 2. A = 1 2 3 –1 B = a 0 –a b 0 1 0 C = 0 0 1 – 6 – 11 – 6 Hint: One of the eigenvalues of matrix C is – 1 . dy 1. d y + 4 ----.+ y = cos t Hint: Use cos t = -.+ k 3 ----.

and State Equations 8. Compute e At given that A = 0 1 0 0 0 1 – 6 – 11 – 6 5−48 Numerical Analysis Using MATLAB® and Excel®.Chapter 5 Differential Equations. Third Edition Copyright © Orchard Publications . State Variables.

y = k1 e + k2 e –t – 3t 1 . By substitution of this assumed solution into the given ODE and using MATLAB to find the first and second derivatives we obtain: y = k1 e + k2 e –t – 3t + k 3 te –t Numerical Analysis Using MATLAB® and Excel®. y=simple(y) y = -7/9+1/3*t+C1/exp(t)+C2/exp(t)^3 2.Solutions to End−of−Chapter Exercises 5. For the forced response. Therefore.-+ -. The characteristic equation of the homogeneous part is s + 4s + 3 = 0 from which s 1 = – 1 and s 2 = – 3 . Third Edition Copyright © Orchard Publications 5−49 .1 and we assume a solution of –t –t –t the form y F = k 3 te where we multiplied e by t to avoid the duplication with k 1 e . For the forced response.t – 7 3 9 Check with MATLAB: y=dsolve('D2y+4*Dy+3*y=t−1’). The characteristic equation of the homogeneous part is the same as for Exercise 1 and thus yN = k1 e + k2 e –t – 3t . we refer to Table 5.14 Solutions to End−of−Chapter Exercises 1. Thus y N = k 1 e + k 2 e –t – 3t 2 . we refer to Table 5.1 and we assume a solution of the form y F = k 3 t + k 4 and the total solution is y = k1 e + k2 e –t – 3t + k3 t + k4 The first and second derivatives of y are dy ⁄ dt = – k 1 e – 3k 2 e 2 2 –t –t – 3t + k3 – 3t d y ⁄ dt = k 1 e + 9k 2 e and by substitution into the given ODE k 1 e + 9k 2 e –t – 3t + 4 ( – k 1 e – 3k 2 e –t – 3t + k3 ) + 3 ( k1 e + k2 e –t – 3t + k3 t + k4 ) = t – 1 Equating like terms we obtain 4k 3 + 3k 3 t + 3k 4 = t – 1 3k 3 t = t 4k 3 + 3k 4 = – 1 and simultaneous solution of the last two yields k 3 = 1 ⁄ 3 and k 4 = – 7 ⁄ 9 .

3. f=simple(f) 2 2 –t –t % Form and simplify the left side of the given ODE f = 2*k3/exp(t) and by substitution into the given ODE 2k 3 e –t = 4e – 3t –t or k 3 = 2 . f1=simple(y1) % Define symbolic variables % Assumed form of total solution % Compute and simplify first derivative f1 = -k3*exp(-t)*(-1+t) Thus. f2=simple(y2) –t –t % Compute and simplify second derivative f2 = k3*exp(-t)*(-2+t) and the second derivative of y is d yF ⁄ dt = – 2k 3 e + k 3 te f=y2+4*y1+3*y0. y=simple(y) 2*t/exp(t)-1/exp(t)+C1/exp(t)+C2/exp(t)^3 We observe that the second and third terms of the displayed expression above have the same form and thus they can be combined to form a single term C3/exp(t). y1=diff(y0). The characteristic equation yields two equal roots s 1 = s 2 = – 1 and thus the natural response has the form y N = k 1 e + k 2 te –t –t For the forced response we assume a solution of the form y F = k 3 cos 2t + k 4 sin 2t + k5 5−50 Numerical Analysis Using MATLAB® and Excel®. State Variables. and State Equations We will use MATLAB to find the first and second derivatives of this expression. y = k1 e + k2 e –t + 2te –t Check with MATLAB: y=dsolve('D2y+4*Dy+3*y=4*exp(−t)'). Therefore.Chapter 5 Differential Equations. the first derivative of y F is dyF ⁄ dt = k 3 e – k 3 te y2=diff(y0. Third Edition Copyright © Orchard Publications .2). syms t k3 y0=k3*t*exp(−t).

Therefore.2). the forced response is y F = ( – 3 ⁄ 50 ) cos 2t + ( 4 ⁄ 50 ) sin 2t + 1 ⁄ 2 and the total response is –t – t 1 3 cos 2t – 4 sin 2t y = k 1 e + k 2 te + -. f2=simple(y2) % Compute and simplify second derivative f2 = -4*k3*cos(2*t)-4*k4*sin(2*t) and the second derivative of y is d yF ⁄ dt = – 4k 3 cos 2t – 4k 4 sin 2t f=y2+2*y1+y0.– -------------------------------------2 50 Check with MATLAB: Numerical Analysis Using MATLAB® and Excel®. f1=simple(y1) % Define symbolic variables % Assumed form of total solution % Compute and simplify first derivative f1 = -2*k3*sin(2*t)+2*k4*cos(2*t) Thus.Solutions to End−of−Chapter Exercises We will use MATLAB to find the first and second derivatives of this expression.+ 1 2 2 Equating like terms and solving for the k terms we obtain – 3k 3 + 4k 4 = 1 ⁄ 2 – 4k 3 – 3k 4 = 0 k5 = 1 ⁄ 2 Simultaneous solution of the first two equations above yields k 3 = – 3 ⁄ 50 and k 4 = 4 ⁄ 50 . the first derivative of y F is dyF ⁄ dt = – 2k 3 sin 2t + 2k 4 cos 2t y2=diff(y0. f=simple(f) % Form and simplify the left side of the given ODE 2 2 f = -3*k3*cos(2*t)-3*k4*sin(2*t)-4*k3*sin(2*t)+4*k4*cos(2*t)+k5 Simplifying this expression and equating with the right side of the given ODE we obtain: cos 2t -( – 3k 3 + 4k 4 ) cos 2t – ( 4k 3 + 3k 4 ) sin 2t + k 5 = ------------. syms t k1 k2 k3 k4 k5 y0=k3*cos(2*t)+k4*sin(2*t)+k5. Third Edition Copyright © Orchard Publications 5−51 . y1=diff(y0).

⋅ ------.⋅ ------.Chapter 5 Differential Equations.= ---------------------------------------.= ---------------------------------------.( cos t ) = sec t dt dt dt dt dt dt Next. by (5. Third Edition Copyright © Orchard Publications .sin t = 0 dt dt and from (5. f=simple(y) f = -3/50*cos(2*t)+2/25*sin(2*t)+1/2+C1*exp(-t)+C2*exp(-t)*t 4. and State Equations y=dsolve('D2y+2*Dy+y=cos(2*t)/2+1/2'). to assume a solution for the forced response of this ODE. if not impossible.= 1 dt 1 1 (3) Integration of (2) and (3) above and substitution into (1) yields u1 = ∫ ( – tan t ) dt = – ( – ln cos t ) + k 1 = ln cos t + k 1 u2 = ∫ dt = t + k2 5−52 Numerical Analysis Using MATLAB® and Excel®. The characteristic equation is s + 1 = 0 from which s = ± j and thus the natural response is yN = k1 e + k2 e jt –j t 2 We let y 1 = cos t and y 2 = sin t Then.70).= -----------------------------. It is very difficult.= – tan t (2) 2 2 cos t sin t dt 1 cos t + sin t – sin t cos t 0 sin t and cos t 0 du 2 – sin t sec t 1 ------. we find du1 ⁄ dt and du 2 ⁄ dt by Cramer’s rule as follows: sin t – --------du1 sec t cos t cos t – tan t ------.69).68) the solution is y = u1 y 1 + u 2 y 2 = u1 cos t + u 2 sin t (1) Also. we will use the method of variation of parameters.= -.y1 + ------. du1 du 2 ------. du1 dy1 du 2 dy 2 du 2 du1 ------.( – sin t ) + ------. Therefore. State Variables.= -----------.cos t + ------.+ ------.= f ( t ) = ------.y 2 = 0 dt dt or du 2 du1 ------. from (5.

= x 3 3 dt 2 · dv ------. and by substitution into (1) · x 3 = – k 1 x 1 – k 2 x 2 – k 3 x 3 + 3 ( cos 3t – sin 3t ) Thus.= x 2 = x 1 dt 3 · dv ------.+ k dv + k v = 3 cos 3t – 3 sin 3t = 3 ( cos 3t – sin 3t ) ------3 ------2 ----1 2 3 dt dt dt 2 or 3 dv dv dv ------.= – k 3 ------.– k 2 ----. Differentiating the given integro−differential equation with respect to t we obtain 3 dv .+ k dv . f=simple(y) f = sin(t)*t+log(cos(t))*cos(t)+C1*sin(t)+C2*cos(t) 5.Solutions to End−of−Chapter Exercises y = u1 y 1 + u 2 y 2 = ( ln cos t + k 1 ) cos t + ( t + k 2 ) sin t = k 1 cos t + k 2 sin t + t sin t + cos t ( ln cos t ) Check with MATLAB: y=dsolve('D2y+y=sec(t)').= x 3 = x 2 2 dt Then.– k 1 v + 3 ( cos 3t – sin 3t ) (1) 2 3 dt dt dt 2 We let v = x1 · dv ----. Third Edition Copyright © Orchard Publications 5−53 . the state equations are · x1 = x2 · x2 = x3 · x 3 = – k 1 x 1 – k 2 x 2 – k 3 x 3 + 3 ( cos 3t – sin 3t ) and in matrix form · x1 x1 0 1 0 0 · = 0 0 1 ⋅ x + 0 ⋅ 3 ( cos 3t – sin 3t ) x2 2 –k1 –k2 –k3 · 1 x3 x3 Numerical Analysis Using MATLAB® and Excel®.

2 λ + 6λ + 11λ + 6 --------------------------------------------. a.Chapter 5 Differential Equations. Matrix A is the same as Matrix C in Exercise 7. λ = 7 . Third Edition Copyright © Orchard Publications . Expansion of the given matrix yields · x1 = x2 · x2 = x3 · x3 = x2 3 · x 4 = – x 1 – 2x 2 – 3x 3 – 4x 4 + u ( t ) 2 Letting x = y we obtain 4 dy dy dy dy ------. – 1 – λ + λ + λ – 6 = 0 . Then.+ y = u ( t ) 3 2 4 dt dt dt dt 7. 0 1 0 C = 0 0 1 – 6 – 11 – 6 ⎛ 0 1 0 1 0 0⎞ ⎜ ⎟ det ( C – λI ) = det ⎜ 0 0 1 –λ 0 1 0 ⎟ ⎜ ⎟ 0 0 1⎠ ⎝ – 6 – 11 – 6 = det –λ 1 0 0 –λ 1 =0 – 6 – 11 – 6 – λ λ ( – 6 – λ ) – 6 – ( – 11 ) ( – λ ) = λ + 6λ + 11λ + 6 = 0 and it is given that λ 1 = – 1 .+ 3 ------. State Variables. B = a 0 –a b ⎛ ⎞ det ( B – λI ) = det ⎜ a 0 – λ 1 0 ⎟ = det a – λ 0 = 0 ⎝ –a b 0 1⎠ –a b – λ ( a – λ ) ( b – λ ) = 0 . and State Equations 6. λ2 = –2 λ1 = –3 a. A = 1 2 3 –1 ⎛ ⎞ 2 det ( A – λI ) = det ⎜ 1 2 – λ 1 0 ⎟ = det 1 – λ = 0 ⎝ 3 –1 0 1⎠ 3 –1 –λ 2 2 ( 1 – λ ) ( – 1 – λ ) – 6 = 0 .+ 2 ----.+ 4 ------.= λ + 5λ + 6 ⇒ ( λ + 1 ) ( λ + 2 ) ( λ + 3 ) = 0 (λ + 1) 3 2 2 3 2 and thus λ 1 = – 1 8. and thus λ 1 = a λ2 = b c. Then. and thus λ 1 = 7 λ2 = – 7 b. λ1 = –1 λ2 = –2 λ1 = –3 5−54 Numerical Analysis Using MATLAB® and Excel®.

5/2*exp(-t)-16*exp(2*t)+27/2*exp(-3*t).. x=A\a.. a0=3*exp(−t)−3*exp(−2*t)+exp(−3*t). a1=5/2*exp(−t)−4*exp(−2*t)+3/2*exp(−3*t). fprintf(' \n'). -1/2*exp(-t)+2*exp(-2*t)-3/2*exp(-3*t)] [3*exp(-t)-12*exp(-2*t)+9*exp(-3*t).. disp(x(2)). fprintf(' \n'). A=[0 1 0. a 0 = 3e – 3e –t –t –t – 2t + 3e – 3t – 3t a 1 = 2.... disp('a2 = '). 0 0 1.5e – 2t + 0. disp('a1 = '). eAt=a0*eye(3)+a1*A+a2*A^2 eAt = [3*exp(-t)-3*exp(-2*t)+exp(-3*t). exp(−2*t). 5/2*exp(-t)-4*exp(-2*t)+3/ 2*exp(-3*t). we compute e At of (1) with the following MATLAB code: syms t.. a=sym('[exp(−t). −6 −11 −6]. disp(x(3)) a0 = 3*exp(-t)-3*exp(-2*t)+exp(-3*t) a1 = 5/2*exp(-t)-4*exp(-2*t)+3/2*exp(-3*t) a2 = 1/2*exp(-t)-exp(-2*t)+1/2*exp(-3*t) Thus.. A=[1 −1 1. 1 −3 9]. 1 −2 4. a0 + a1 λ1 + a2 λ1 = e a0 + a1 λ2 + a2 λ2 = e a0 + a1 λ3 + a2 λ3 = e ⇒ a0 – a1 + a2 = e ⇒ a 0 – 2a 1 + 4a 2 = e ⇒ a 0 – 3a 1 + 9a 2 = e syms t.. exp(−3*t)]').. disp('a0 = '). a2=1/2*exp(−t)−exp(−2*t)+1/2*exp(−3*t).5e – 3t Now.. Numerical Analysis Using MATLAB® and Excel®.5e – e – 2t + 1. disp(x(1)). 1/2*exp(-t)-4*exp(-2*t)+9/2*exp(3*t)] Then.. -5/2*exp(-t)+8*exp(2*t)-9/2*exp(-3*t). Third Edition Copyright © Orchard Publications 5−55 .5e – 4e a 2 = 0.Solutions to End−of−Chapter Exercises and since A is a 3 × 3 matrix the state transition matrix is e At = a0 I + a1 A + a2 A 2 2 2 λ1 t λ2 t λ3 t 2 (1) –t – 2t – 3t Then. 1/2*exp(-t)-exp(-2*t)+1/2*exp(-3*t)] [-3*exp(-t)+6*exp(-2*t)-3*exp(-3*t).

5 e + 8e 2.5e – 16e –t – 2t – 4.5 e + 2e 0.Chapter 5 Differential Equations. Third Edition Copyright © Orchard Publications .5e – 3t 5−56 Numerical Analysis Using MATLAB® and Excel®.5e – 3t – 3t = – 3 e – t + 6e – 2t – 3e –3t – 2t – 2.5e + 9e – 3t – 2t + 13.5e – 4e –t –t – 2t + 1.5e – 3t – 3t – 3t 0.5e – 2t + 4.5e – e –t –t –t – 2t + 0.5e – 4e – 2t – 1. and State Equations 3e – 3e 3e – 12e –t –t – 2t e At +e – 3t 2. State Variables.5e – 0.

that is. a waveform that repeats itself after some time. 3 MHz . Then. and so on. if f ( t ) represents some voltage v ( t ) .e. any periodic waveform f ( t ) can be expressed as 1 f ( t ) = -. Third Edition Copyright © Orchard Publications 6−1 . Taylor. and so on. and Maclaurin Series T his chapter is an introduction to Fourier and power series. or current i ( t ) .a 0 + a 1 cos ωt + a 2 cos 2ωt + a 3 cos 3ωt + a 4 cos 4ωt + … 2 + b 1 sin ωt + b 2 sin 2ωt + b 3 sin 3ωt + b 4 sin 4ωt + … (6. a series of sinusoids with frequencies 1 MHz . i. represent the fundamental frequency component ω *. Thus.a 0 + 2 n=1 ∑ ( a cos nωt + b sin nωt ) n n ∞ (6. 6. Several examples are presented to illustrate the approach. Likewise. The terms with the coefficients a 1 and b 1 together.. represent the second harmonic component 2ω . 2 MHz . a third harmonic of 3 MHz . the terms with the coefficients a 2 and b 2 together. can be expressed as a series of harmonically related sinusoids. contains the fundamental frequency of 1 MHz . a second harmonic of 2 MHz . and represents the DC (average) component of f ( t ) . The alternate trigonometric and the exponential forms are also presented.1 Wave Analysis The French mathematician Fourier found that any periodic waveform. We conclude with a discussion on power series expansion with the Taylor and Maclaurin series. and so on. the term a 0 ⁄ 2 is the average value of v ( t ) or i ( t ) . We begin with the definition of sinusoids that are harmonically related and the procedure for determining the coefficients of the trigonometric form of the series. sinusoids whose frequencies are multiples of a fundamental frequency (or first harmonic). For example.Chapter 6 Fourier. Numerical Analysis Using MATLAB® and Excel®. we discuss the different types of symmetry and how they can be used to predict the terms that may be present. In general. * We recall that k 1 cos ωt + k2 sin ωt = k cos ( ωt + θ ) where θ is a constant.2) where the first term a 0 ⁄ 2 is a constant.1) or 1 f ( t ) = -.

Chapter 6 Fourier. Summation of a fundamental.4) (6. the product of the sine and cosine functions under the integral evaluated from 0 to 2π is zero. Generally. 2nd Harmonic Total 3 2 1 0 -1 -2 -3 0 2 4 6 8 10 12 Fundamental 3rd Harmonic Figure 6. the sum of two or more sinusoids of different frequencies produce a waveform that is not a sinusoid as shown in Figure 6. Let us consider the functions sin mt and cos m t where m and n are any integers.3) and (6.4) are zero since the net area over the 0 to 2π area is zero. Taylor.1) is not a difficult task because the sine and cosine are orthogonal functions.1. and Maclaurin Series Since any periodic waveform f ( t ) can be expressed as a Fourier series. we have assumed that ω = 1 .1. that is. Third Edition Copyright © Orchard Publications .5) 2π cos m t dt = 0 ( sin mt ) ( cos nt ) dt = 0 The integrals of (6. it follows that the sum of the DC . the fundamental. and for convenience.5) is also is zero since 2π 2π sin mt dt = 0 (6. the second harmonic.3) (6. must produce the waveform f ( t ) . This will be shown shortly. Then. ∫0 ∫0 ∫0 gral of (6. and so on. second and third harmonic 6.2 Evaluation of the Coefficients Evaluations of a i and b i coefficients of (6. The inte- 6−2 Numerical Analysis Using MATLAB® and Excel®.

then.6) 1 ( sin x ) ( sin y ) = -. if m and n are different integers.3. We observe that the net shaded area above and below the time axis is zero. Third Edition Copyright © Orchard Publications 6−3 . where we observe that the net shaded area above and below the time axis is zero.[ sin ( x + y ) + sin ( x – y ) ] 2 This is also obvious from the plot of Figure 6.2. sin 2x sin 3x sin 2x ⋅ sin 3x Numerical Analysis Using MATLAB® and Excel®. sin x sin x ⋅ cos x cos x Figure 6. ∫0 since 2π ( sin mt ) ( sin nt ) dt = 0 (6.6) can also be confirmed graphically as shown in Figure 6.2. Graphical proof of ∫0 2π ( sin mt ) ( cos nt ) dt = 0 Moreover.Evaluation of the Coefficients 1 sin x cos y = -.[ cos ( x – y ) – cos ( x – y ) ] 2 The integral of (6. where m = 2 and n = 3 .

9) The integrals of (6. Graphical proof of ∫0 2π ( sin mt ) ( sin nt ) dt = 0 for m = 2 and n = 3 Also. Taylor.7) can also be confirmed graphically as shown in Figure 6.6. We observe that the net shaded area above and below the time axis is zero.7) 1 ( cos x ) ( cos y ) = -. Graphical proof of ∫0 2π ( cos m t ) ( cos nt ) dt = 0 for m = 2 and n = 3 However.4. ∫0 since 2π ( cos m t ) ( cos nt ) dt = 0 (6. m = n . if m and n are different integers. cos 3x cos 2x cos 2x ⋅ cos 3x Figure 6. ∫0 and 2π ( sin mt ) dt = π 2 (6.6) and (6.9) can also be seen to be true graphically with the plots of Figures 6.4. then. It was stated earlier that the sine and cosine functions are orthogonal* to each other. The simpli* We will discuss orthogonal functions in Chapter 14 6−4 Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications . then.5 and 6.Chapter 6 Fourier. if in (6.8) ∫0 2π ( cos m t ) dt = π 2 (6.[ cos ( x + y ) + cos ( x – y ) ] 2 The integral of (6. and Maclaurin Series Figure 6.8) and (6. where m = 2 and n = 3 .7).3.

10) To evaluate any coefficient.a 0 + a 1 cos t + a 2 cos 2t + a 3 cos 3t + a 4 cos 4t + … 2 + b 1 sin t + b 2 sin 2t + b 3 sin 3t + b 4 sin 4t + … (6. Third Edition Copyright © Orchard Publications 6−5 .Evaluation of the Coefficients fication obtained by application of the orthogonality properties of the sine and cosine functions.5.6. sin x sin x 2 Figure 6. for simplicity. Then. say b 2 . we multiply both sides of (6. 1 f ( t ) sin 2t = -. Graphical proof of ∫0 2π ( cos m t ) dt = π 2 In (6. Graphical proof of ∫0 2π ( sin mt ) dt = π 2 cos x cos x 2 Figure 6.1). Then.10) by sin 2t .a 0 sin 2t + a 1 cos t sin 2t + a 2 cos 2t sin 2t + a 3 cos 3t sin 2t + a 4 cos 4t sin 2t + … 2 b 1 sin t sin 2t + b 2 ( sin 2t ) + b 3 sin 3t sin 2t + b 4 sin 4t sin 2t + … 2 Numerical Analysis Using MATLAB® and Excel®. 1 f ( t ) = -. becomes apparent in the discussion that follows. we let ω = 1 .

∫0 2π 1 f ( t ) sin 2t dt = -.Chapter 6 Fourier.11) reduces to ∫0 or 2π f ( t ) sin 2t dt = b 2 ∫0 2π ( sin 2t ) dt = b 2 π 2 1 b 2 = -π ∫0 2π f ( t ) sin 2t dt and thus we can evaluate this integral for any given function f ( t ) .7). Taylor.13) 1 b n = -π ∫0 2π f ( t ) sin nt dt (6. (6.11) except the term b2 ∫0 2π ( sin 2t ) dt 2 is zero as we found in (6.12) ∫0 f ( t ) cos nt dt (6. Then.a 0 2 ∫0 2π sin 2t dt + a 1 ∫0 2π cos t sin 2t dt + a 2 ∫0 2π cos 2t sin 2t dt + a3 + b1 + b4 ∫0 2π cos 3t sin 2t dt + a 4 sin t sin 2t dt + b 2 ∫0 2π cos 4t sin 2t dt + … 2 ∫0 ∫0 2π ∫0 2π ( sin 2t ) dt + b 3 ∫0 2π (6.11) sin 3t sin 2t dt 2π sin 4t sin 2t dt + … We observe that every term on the right side of (6.6) and (6. and we integrate over the period 0 to 2π .a 0 = ----2 2π 1 a n = -π 2π ∫0 2π f ( t ) dt (6. Therefore. and Maclaurin Series Next.14) 6−6 Numerical Analysis Using MATLAB® and Excel®. and b n are found from the following relations. we multiply both sides of the above expression by dt . Third Edition Copyright © Orchard Publications . The coefficients a 0 . 1 1-. a n . The remaining coefficients can be evaluated similarly.

all the b i coefficients will be zero. if f ( t ) is an odd function. A function f ( t ) is an even function of time if the following relation holds. and odd functions have nothing to do with odd harmonics. polynomials with even exponents only. while others have sine terms only. do not have the average. that is.Symmetry The integral of (6.6. that is. all even (even cosine and even sine) harmonics will be zero. f ( –t ) = f ( t ) (6. These are: 1. it is possible to predict which terms will be present in the trigonometric Fourier series. will be zero. all the a i coefficients including a 0 . Some waveforms have cosine terms only. if it is an odd function. the most common waveforms used in science and engineering. In other words. Half−wave symmetry − If a waveform has half−wave symmetry (to be defined shortly).15) that is. For instance. only odd (odd cosine and odd sine) harmonics will be present. cosine. and sine terms all present. and a 0 may or may not be zero. Fortunately. 2. Odd symmetry − If a waveform has odd symmetry. 3.t. Still other waveforms have or have not DC components. the series will consist of sine terms only.12) yields the average ( DC ) value of f ( t ) . Numerical Analysis Using MATLAB® and Excel®. * We will discuss power series later in this chapter. In other words. 6. by observing whether or not the given waveform possesses some kind of symmetry. Even symmetry − If a waveform has even symmetry. the cosine function is an even function because it can be written as the power series* t.+ ---.tcos t = 1 – ---.7.+ … 2! 4! 6! 2 4 6 Other examples of even functions are shown in Figure 6. In other words. and with or without constants. if in an even function we replace t with – t . the series will consist of cosine terms only. We will discuss three types of symmetry that can be used to facilitate the computation of the trigonometric Fourier series form. Thus. the function f ( t ) does not change. We will now define even and odd functions and we should remember that even functions have nothing to do with even harmonics.3 Symmetry With a few exceptions such as the waveform of Example 6. if it is an even function. if f ( t ) is an even function.– ---. are even functions. Third Edition Copyright © Orchard Publications 6−7 .

– ---. is an odd function. f e ( t ) and f o ( t ) will be used to represent even and odd functions of time respectively. and the product of an even function times an odd function. we will denote an even function with the subscript e .8. ∫– T 6−8 T f e ( t ) dt = 2 ∫0 T f e ( t ) dt (6. –f ( –t ) = f ( t ) (6.17) Numerical Analysis Using MATLAB® and Excel®. the reverse is not always true.+ … 3! 5! 7! 3 5 7 Other examples of odd functions are shown in Figure 6. Henceforth.16) that is. we obtain the negative of the function f ( t ) . Taylor. However. and no constants are odd functions. polynomials with odd exponents only. Third Edition Copyright © Orchard Publications .8. 2 The product of two even or two odd functions is an even function. f(t) mt 0 f(t) t3 t 0 f(t) t 0 t Figure 6. we should not conclude that f ( t ) is an odd function. and Maclaurin Series f(t) t2 0 f(t) k t 0 t2 + k t f(t) 0 t Figure 6. if f ( 0 ) = 0 . For instance. Thus.Chapter 6 Fourier. An example of this is the function f ( t ) = t in Figure 6. and an odd function with the subscript o .+ ---. Thus. Examples of even functions A function f ( t ) is an odd function of time if the following relation holds. f ( 0 ) = 0 .7. if in an odd function we replace t with – t . Also. the sine function is an odd function because it can be written as the power series t t t sin t = t – ---. Examples of odd functions We observe that for odd functions.7. that is.

17). a 0 = 0 .[ f ( t ) + f ( – t ) ] 2 (6.21) that is. the function with value f ( t ) at any time t . will have the same value again at a later time t + T. the average value over one period T is zero.[ f ( t ) – f ( – t ) ] 2 (6. 1. but inverted.Symmetry and T ∫– T f o ( t ) dt = 0 (6.9. we get f ( t ) = fe ( t ) + fo ( t ) (6. We will test the waveforms of Figures 6. the shape of the negative half−cycle of the waveform is the same as that of the positive half−cycle.20) By addition of (6. It is also an odd function and has half − wave symmetry since – f ( – t ) = f ( t ) and –f ( t + T ⁄ 2 ) = f ( t ) . To understand half−wave symmetry.22) that is. we recall that any periodic function with period T . Square waveform For the waveform of Figure 6. has half−wave symmetry if –f ( t + T ⁄ 2 ) = f ( t ) (6. Third Edition Copyright © Orchard Publications 6−9 . is expressed as f(t) = f(t + T) (6.16) with (6.19) or as 1 f o ( t ) = -.9 through 6. and therefore.18) A function f ( t ) that is neither even nor odd can be expressed as 1 f e ( t ) = -. any function of time can be expressed as the sum of an even and an odd function. A periodic waveform with period T . Numerical Analysis Using MATLAB® and Excel®.23) that is.13 for any of the three types of symmetry.

11. we see that the square waveform now becomes an even function and has half−wave symmetry since f ( – t ) = f ( t ) and – f ( t + T ⁄ 2 ) = f ( t ) . Third Edition Copyright © Orchard Publications .Chapter 6 Fourier. the waveform will have neither odd nor even symmetry. and Maclaurin Series T A T/2 f(b) π 2π 0 f(a) T/2 ωt −A Figure 6. Also. and observe the values of f ( t ) at the left and right points on the time axis. 3.9. a 0 = 0 . Sawtooth waveform For the sawtooth waveform of Figure 6.10. Square waveform with ordinate axis shifted If we shift the ordinate axis π ⁄ 2 radians to the right. 2. such as f ( a ) and f ( b ) . a 0 = 0 . It is also an odd function because – f ( – t ) = f ( t ) . T A −π/2 π/2 2π π −2π −π 0 ωt T/2 −A T/2 Figure 6. but has no half−wave symmetry 6−10 Numerical Analysis Using MATLAB® and Excel®. these will always be equal but will have opposite signs as we slide the half−period T ⁄ 2 length to the left or to the right on the time axis at non−zero values of f ( t ) . if the ordinate axis is shifted by any other value other than an odd multiple of π ⁄ 2 .10.9. If there is half−wave symmetry. the average value over one period T is zero and therefore. Taylor. as shown in Figure 6. Square waveform with ordinate shifted by π ⁄ 2 Obviously. Square waveform test for symmetry An easy method to test for half−wave symmetry is to choose any half−period T ⁄ 2 length on the time axis as shown in Figure 6.

all three waveforms have zero average value unless the abscissa axis is shifted up or down. The third harmonic has half−wave symmetry since the c and – c values. Also. Triangular waveform For this triangular waveform of Figure 6. Moreover.11. This is necessary in order to test the fundamental. there are not opposite in sign. second. when separated by T ⁄ 2 are equal and opposite. Triangular waveform test for symmetry 5.12. and third harmonics for half−wave symmetry. although are equal. are equal and opposite. a 0 = 0 . Sawtooth waveform test for symmetry 4.Symmetry since – f ( t + T ⁄ 2 ) ≠ f ( t ) T A −2π −π 0 T/2 π T/2 2π ωt −A Figure 6. The fundamental has half−wave symmetry since the a and – a values. it has half−wave symmetry because – f ( t + T ⁄ 2 ) = f ( t ) T A −2π −π T/2 0 π T/2 2π ωt −A Figure 6. Numerical Analysis Using MATLAB® and Excel®. is chosen as the half period of the period of the fundamental frequency. when separated by T ⁄ 2 . Second and Third Harmonics of a Sinusoid Figure 6. It is also an odd function since – f ( – t ) = f ( t ) . The second harmonic has no half−wave symmetry because the ordinates b on the left and b on the right. Fundamental. Third Edition Copyright © Orchard Publications 6−11 .13 shows a fundamental. second. and third harmonic of a typical sinewave where the half period T ⁄ 2 . These waveforms can be either odd or even depending on the position of the ordinate.12. the average value over one period T is zero and therefore.

However. Fundamental.14. we can choose the limits of integration as – π to +π . Of course. and third harmonic test for symmetry In the expressions of the integrals in (6. Moreover. or an even function. the limits of integration for the coefficients a n and b n are given as 0 to 2π . 6−12 Numerical Analysis Using MATLAB® and Excel®.2. we can compute the non−zero coefficients a n and b n by integrating from 0 to π only. if the waveform has half− wave symmetry and is also an odd or an even function. we can choose the limits of integration from 0 to π ⁄ 2 and multiply the integral by 4 .1 Compute the trigonometric Fourier series of the square waveform of Figure 6.14).5 0 -0. and also that the product of two odd functions results also in an even function.5 -1 c a b −a 0 b T/2 (for fundamental) 2 4 T/2 6 (for 2nd harmonic) 8 T/2 10 (for 3rd harmonic) −c 12 Figure 6. one period T . Also. that is. 6. we must evaluate the coefficients a n and b n for the integer values of n that will result in non−zero coefficients.Chapter 6 Fourier. Taylor. if the given waveform is an odd function. Example 6.12) through (6. the product of two even functions is another even function. or has half−wave symmetry.4 Waveforms in Trigonometric Form of Fourier Series We will now derive the trigonometric Fourier series of the most common periodic waveforms. Third Edition Copyright © Orchard Publications . The proof is based on the fact that. and Maclaurin Series 3rd harmonic 2nd harmonic Fundamental 1 0. This point will be illustrated in Example 6.13. Page 6−6. and multiply the integral by 2 . second. it is important to remember that when using these shortcuts.

Also. we will get the indeterminate form 0 ⁄ 0 . Then. but if we attempt to verify this using (6.1 Solution: The trigonometric series will consist of sine terms only because. To work around this problem. only odd harmonics will be present since this waveform has half−wave symmetry.( sin nπ – 0 – sin n2π + sin nπ ) = ----. we will evaluate a 0 directly from (6. 1 b n = -π ∫0 2π 1 f ( t ) sin nt dt = -π ∫0 π A sin nt dt + ∫π 2π Aπ ( – A ) sin nt dt = ----. as we already know.12).( 1 – 2 cos nπ + cos 2nπ ) nπ nπ (6. that is.( – cos nπ + 1 + cos 2nπ – cos nπ ) = ----. The a i coefficients are found from 1 a n = -π ∫0 2π 1 f ( t ) cos nt dt = -π ∫0 π A cos nt dt + ∫π 2π A π ( – A ) cos nt dt = ----.24). However. Moreover.14. Third Edition Copyright © Orchard Publications 6−13 . Square waveform for Example 6. Also. this waveform is an odd function.( π – 0 – 2π + π ) = 0 π (6. (6.24) are zero and therefore. by inspection. since the square waveform has odd symmetry. the average ( DC ) value is zero. we will compute all coefficients to verify this.26) For n = even .26) yields Numerical Analysis Using MATLAB® and Excel®. as expected.24) and since n is an integer (positive or negative) or zero. 1 a 0 = -π ∫0 π A dt + ∫π 2π A ( – A ) dt = --.( 2 sin nπ – sin n2π ) nπ nπ (6.( – cos n t 0 + cos nt nπ 2π ) π AA= ----.14). the terms inside the parentheses on the second line of (6.25) The b i coefficients are found from (6. for brevity.( sin nt 0 – sin nt nπ 2π ) π A A = ----. we will assume that ω = 1 . all a i coefficients are zero.Waveforms in Trigonometric Form of Fourier Series T A π 0 −A 2π ωt Figure 6.

and it is also an odd or an even function. For n = odd . (6. we are only concerned with the odd b n coefficients. 1 b n = 4 -π ∫0 π⁄2 4A f ( t ) sin nt dt = -----.( 1 + 2 + 1 ) = 4A nπ nπ and thus 4A b 1 = -----π 4A b 3 = -----3π 4A b 5 = -----5π and so on. Example 6.27) It was stated above that. We will apply this property to the following example. if the given waveform has half−wave symmetry.sin 3ωt + -. the trigonometric Fourier series for the square waveform with odd symmetry is 4A 1 1 4A f ( t ) = -----.Chapter 6 Fourier. Third Edition Copyright © Orchard Publications .2 Compute the trigonometric Fourier series of the square waveform of Example 1 by integrating from 0 to π ⁄ 2 .sin nωt n (6. since the square waveform has half−wave symmetry. Solution: Since the waveform is an odd function and has half−wave symmetry.⎛ sin ωt + -. and multiplying the result by 4 . (6. we can integrate from 0 to π ⁄ 2 .sin 5ωt + …⎞ = -----⎠ π 5 3 π ⎝ n = odd ∑ 1 -. Taylor.28) becomes 6−14 Numerical Analysis Using MATLAB® and Excel®.( – cos n t nπ π⁄2 0 π 4A ) = -----. and multiply the integral by 4 .21) reduces to A-----b n = ----. Therefore.28) For n = odd .⎛ – cos n -.( 1 – 2 + 1 ) = 0 nπ as expected. and Maclaurin Series A b n = ----.+ 1⎞ ⎠ 2 nπ ⎝ (6. Then.

except that the ordinate has been shifted to the right by π ⁄ 2 radians.31) For n = 1.( – 0 + 1 ) = 4A nπ nπ (6. Also.3 Compute the trigonometric Fourier series of the square waveform of Figure 6.15.30) becomes Numerical Analysis Using MATLAB® and Excel®. For n = odd .⎞ 2⎠ nπ ⎝ (6.29) as before.30) We observe that for n = even .Waveforms in Trigonometric Form of Fourier Series 4A -----b n = -----. by inspection. and has become an even function. 4A a n = ± -----nπ (6. 9. and thus the series is the same as in Example 1. The a n coefficients are found from 1 a n = 4 -π ∫0 π⁄2 4 f ( t ) cos nt dt = -π ∫0 π⁄2 4A A cos nt dt = -----. and thus all even harmonics are zero as expected.⎛ sin n -. (6. will alternate between +1 and – 1 depending π 2 on the odd integer assigned to n . 5. Solution: This is the same waveform as in Example 6. Thus. 13 . Therefore. A T π/2 0 π 3π / 2 2π ωt −A Figure 6. and so on. the average ( DC ) value is zero. Waveform for Example 6. Example 6. it will suffice to integrate from 0 to π ⁄ 2 . the trigonometric Fourier series will consist of odd cosine terms only.3 Since the waveform has half−wave symmetry and is an even function.1. Third Edition Copyright © Orchard Publications 6−15 . all a n coefficients are zero. it still has half−wave symmetry. However. we observe from (6. and multiply the integral by 4 .30) that sin n -..15.( sin nt nπ π⁄2 ) 0 π 4A = -----.

cos 3ωτ + -. sin ( x + 3π ⁄ 2 ) = – cos x .cos 5ωt – …⎞ = -----⎠ 5 π π ⎝ 3 n = odd ∑ ( –1 ) (n – 1 ) ---------------2 1 -.e.sin 3 ⎛ ωτ + -.34) and using the identities sin ( x + π ⁄ 2 ) = cos x ..⎞ + -.sin ⎛ ωτ + -.3 is the same as of Example 6. that is. Therefore.⎞ + -. 4A 1 1 f ( t ) = -----. i. we can use the above procedure to save time. we rewrite (6.⎞ + -.27).sin ⎛ 5ωτ + ----.33) and substitute ωt with ωt + π ⁄ 2 . 15 . we can use the result of Example 6.sin 5 ⎛ ωτ + -. 7.sin 5ωt + …⎞ ⎝ ⎠ π 3 5 (6. relation (6.⎞ + -. if we compute the trigonometric Fourier series with reference to one ordinate. the trigonometric Fourier series for the square waveform with even symmetry is 1 4A 4A -f ( t ) = -----. and so on. Third Edition Copyright © Orchard Publications . and so on.⎛ cos ω t – 1 cos 3ωt + -. 11. we let ωt = ωτ + π ⁄ 2 .cos 5ωτ – … 5 3 π (6. it becomes – 4A a n = ---------nπ Then.⎛ sin ωt + -.35) and this is the same as (6.1.32) Alternate Solution: Since the waveform of Example 6. and afterwards we want to recompute the series with reference to a different ordinate.⎞ + … ⎝ π 2⎠ 2⎠ 5 ⎝ 2⎠ 3 ⎝ (6.sin ⎛ 3ωτ + ----.cos n ωt n (6. Taylor.sin 3ωt + -.33) becomes 1 1 4A π π π f ( τ ) = -----.1. and Maclaurin Series 4A a n = -----nπ and for n = 3.Chapter 6 Fourier. 6−16 Numerical Analysis Using MATLAB® and Excel®.34) as 1 1 4A f ( τ ) = -----. but shifted to the right by π ⁄ 2 radians.sin ⎛ ωτ + -.cos ωτ – -.⎞ + … ⎝ ⎝ ⎠ 5 ⎝ ⎠ 3 π 2⎠ 2 2 4A 1 1 π 5π 3π = -----. With this substitution.

∫ x sin ax dx Then.4 Compute the trigonometric Fourier series of the sawtooth waveform of Figure 6. therefore.t π ⎪ f(t) = ⎨ ⎪ A t – 2A --⎩π 0<t<π π < t < 2π However. we only need to evaluate the b n coefficients.cos ax 2 a a (6. we can choose the limits from – π to +π . 1 x = ---. it contains sine terms only with both odd and even harmonics.Waveforms in Trigonometric Form of Fourier Series Example 6.36) Numerical Analysis Using MATLAB® and Excel®. we will assume that ω = 1 .sin a x – -. Accordingly. As before. T A − 2π −π π 0 −A 2π ωt Figure 6. since the waveform is an odd function. and multiply the integral by 2 . this is what we will do. If we choose the limits of integration from 0 to 2π we will need to perform two integrations since A ⎧ --. Sawtooth waveform Solution: This waveform is an odd function but has no half−wave symmetry.16.t π –π < t < π Better yet. Third Edition Copyright © Orchard Publications 6−17 . From tables of integrals.16. and thus we will only need one integration since A f ( t ) = --. we can integrate from 0 to π . By inspection. the DC component is zero.

Then.( sin nπ – nπ cos nπ ) n2 π2 We observe that: 1.( nπ ) = -----n2 π2 nπ that is.5 Find the trigonometric Fourier series of the triangular waveform of Figure 6. Then. we only need to evaluate the b n coefficients. Taylor. Triangular waveform for Example 6. Thus. 2. Accordingly. the trigonometric Fourier series will contain sine terms only with odd harmonics. We will choose the limits of integration from 0 to π ⁄ 2 . and will multiply the 6−18 Numerical Analysis Using MATLAB® and Excel®. the trigonometric Fourier series for the sawtooth waveform with odd symmetry is 2A 1 1 1 2A f ( t ) = -----.sin 3ωt – -.t sin nt dt = 2A -----π π2 ∫0 π t 2A 1t sin nt dt = -----. the odd harmonics have positive coefficients. (6. 2A 2A b n = ---------.sin 2ωt + -. then. sin nπ = 0 . Assume ω = 1 .sin nωt n (6.17.sin nt – -.( – nπ ) = – -----n2 π2 nπ that is. and Maclaurin Series 2 b n = -π ∫0 π A --.5 Solution: This waveform is an odd function and has half−wave symmetry.37) reduces to 2A 2A b n = ---------. If n = even . the even harmonics have negative coefficients. A −2π −π −A T ωt 0 π/2 π 2π Figure 6.17.Chapter 6 Fourier. cos nπ = – 1 . If n = odd .sin 4ωt + …⎞ = -----⎠ π 4 3 2 π ⎝ ∑ ( –1 ) n–1 1 -.( sin nt – nt cos nt ) n2 π2 π 0 2A = ---------.⎛ ---. Third Edition Copyright © Orchard Publications .cos nt⎞ ⎠ n π2 ⎝ n2 π 0 (6.⎛ sin ωt – -. sin nπ = 0 and cos nπ = 1 .37) 2A = ---------.38) Example 6.

From tables of integrals.40) We are only interested in the odd integers of n . 9. b = – ---------n ⎪ 2 2 n π ⎩ Thus.t sin nt dt = 8A -----2 π π π⁄2 0 ∫0 t 8A 1t sin nt dt = -----. the trigonometric Fourier series for the triangular waveform with odd symmetry is 8A 1 1 8A 1 ( –1 ) f ( t ) = -----.sin n ωt (6.42) Express f ( t ) as a trigonometric Fourier series.sin 7ωt + …⎞ = -----2 ⎝ 2 ⎠ 49 25 9 π n = odd π ∑ (n – 1) ---------------2 1 ---. Assume ω = 1 .cos nt⎞ 2 ⎝ 2 ⎠ n n π 8A = ---------.Waveforms in Trigonometric Form of Fourier Series integral by 4 .⎞ 2 2 ⎝ 2⎠ 2 2 n π (6. Numerical Analysis Using MATLAB® and Excel®.⎛ ---.sin nt – -. b = ---------n ⎪ 2 2 n π ⎪ π sin n -.6 A half−wave rectification waveform is defined as ⎧ sin ωt f (t) = ⎨ ⎩ 0 0 < ωt < π π < ωt < 2π (6. 5. Third Edition Copyright © Orchard Publications 6−19 . 11.– n -.39) π⁄2 0 ∫0 π⁄2 2A -----. By inspection. 7.= 0 2 For odd integers of n .( sin nt – nt cos nt ) 2 2 n π π π π 8A = ---------.41) 2 n Example 6.⎛ sin ω t – -.sin 5ωt – ----.sin 3ωt + ----.cos ax a a π⁄2 (6. Solution: The waveform for this example is shown in Figure 6. 4 b n = -π 1x = ---2 sin a x – -.cos n -. the sine term yields 8A⎧ 1 for n = 1. ∫ x sin ax dx Then. … then. … then. the DC component is zero.18.⎛ sin n -. and we observe that: π cos n -.= ⎨ 2 8A ⎪ – 1 for n = 3.

⎧ cos nπ cos nπ 2 ⎫ A ⎧ – cos nπ – cos nπ 2 ⎫ a n = – ----. 2 2 cos ( m – n )x cos ( m + n )x = – -----------------------------.⎬ 2 2 2π ⎩ 1 – n 1+n 2π ⎩ 1 – n 1+n 1–n ⎭ 1–n ⎭ A cos nπ + 1 A cos nπ + n cos nπ + cos nπ – n cos nπ 2 = ----.+ -----------------.43) Using the trigonometric identities and we obtain and cos ( x – y ) = cos x cos y + sin xsiny cos ( x + y ) = cos x cos y – sin x sin y cos ( π – nπ ) = cos π cos nπ + sin π sin nπ = – cos nπ cos ( π + nπ ) = cos π cos nπ – sin π sin nπ = – cos nπ Then. Third Edition Copyright © Orchard Publications .43). The a n coefficients are found from 1 a n = -π ∫0 2π f ( t ) cos nt dt For this example. we expect all terms to be present. f ( t ) for Example 6.⎬ = ----. Taylor.– -----------------------------.+ ------------.⎨ – -. the average is a non−zero value. and Maclaurin Series –2 π –π 0 π 2π 3π Figure 6.⎞ n ≠ 1 2 2⎠ π ⎝ ( 1 – n2 ) ⎠ 2π ⎝ 1–n 1–n (6.( m ≠ n ) 2( m + n) 2(m – n) π A ⎧ 1 cos ( 1 – n )t cos ( 1 + n )t a n = --.Chapter 6 Fourier. Therefore. by substitution into (6.⎨ -----------------.6 By inspection.⎛ --------------------------------------------------------------------------------------. and the waveform has neither odd nor even symmetry.+ -------------.⎬ 2π ⎩ 1–n 1+n 1–n n+1 ⎭ (6.⎨ ---------------------------.+ ----------------------------. and from tables of integrals A a n = --π ∫0 π A sin t cos nt dt + --π ∫π 2π 0 cos nt dt ∫ ( sin mx ) ( cos nx ) dx Then.⎛ -----------------------.18.– ----------.44) 6−20 Numerical Analysis Using MATLAB® and Excel®.+ ----------.+ -------------⎞ = --. A.– ------------.+ --------------------------π ⎩ 2 1+n 1–n ⎫ ⎬ 0⎭ A ⎧ cos ( π – nπ ) cos ( π + nπ ) 1 1 ⎫ = – ----.--------------------------.⎨ -------------.

First.50) (6. and thus.⎞ = – 2A π ⎝ ( 1 – 22 ) ⎠ 3π A ( cos 3π + 1 ) a 3 = --------------------------------. therefore.46) From (6.= 0 2 π(1 – 3 ) (6.47) (6. However.44). By substitution of n = 0 . 5.⎛ -----------------------. For this example. Third Edition Copyright © Orchard Publications 6−21 . we will evaluate the integral A a 1 = --π ∫0 sin t cos t dt 12 = ----. we can evaluate all the a n coefficients. Now. 4.= – -------2 15π π(1 – 4 ) 2AA ( cos 6π + 1 ) a 6 = --------------------------------.51) and so on.a 0 = A --2 π (6.44) to obtain the value of a 1 . we need to evaluate the b n coefficients. we get 2AA ( cos 4π + 1 ) a 4 = --------------------------------. the DC value is 1 -.= – -------2 35π π(1 – 6 ) 2AA ( cos 8π + 1 ) a 8 = --------------------------------. we get A cos 2π + 1 -----a 2 = --. from (6.44) with n = 2. 1 b n = A -π ∫0 2π A f ( t ) sin nt dt = --π ∫0 π A sin t sin nt dt + --π ∫π 2π 0 sin nt dt Numerical Analysis Using MATLAB® and Excel®.Waveforms in Trigonometric Form of Fourier Series Next. ∫ ( sin ax ) ( cos ax ) dx A 2 a 1 = ----. for n = even . we get a 0 = 2A ⁄ π Therefore. a n = 0 . 3.( sin ax ) 2a = 0 0 π From tables of integrals.45) We cannot use (6. except a 1 . we will evaluate a 0 to obtain the DC value.48) We see that for odd integers of n .( sin t ) 2π π (6. … .= – -------2 63π π(1 – 8 ) (6.49) (6.

53) Example 6.54) Express f ( t ) as a trigonometric Fourier series. 7 0 .( m ≠ n ) 2(m + n) 2( m – n) π A 1 ⎧ sin ( 1 – n )t sin ( 1 + n )t .+ ------------. 3 0 . 6 A 0 .– -----------π 2 4 π 0 A π sin 2π A . A b 1 = --π ∫0 π A t sin 2t 2 . ∫ ( sin mx ) ( sin nx ) dx Therefore. all the b n coefficients.– 0 + 0 = 0 ( n ≠ 1 ) 2π 1–n 1+n that is. 2 0 . except b 1 . Taylor.14) for n = 1 .19. Thus.+ … .– ------------.+ --.– ---------------------------.-.= --π 2 4 2 (6. 4 0 .47) through (6.– ----------------------------.19 where the ordinate was arbitrarily chosen as shown. Assume ω = 1 . are zero.45) and (6.7 A full−wave rectification waveform is defined as f ( t ) = A sin ωt (6. and Maclaurin Series and from tables of integrals. 8 0 .– -------------------------π 2⎩ 1+n 1–n ⎫ ⎬ 0⎭ A sin ( 1 – n )π sin ( 1 + n )π = ----.Chapter 6 Fourier.b n = --.------------.= --.π 2 63 3 15 35 π (6. 5 0 . 2 2 sin ( m – n )x sin ( m + n )x = ----------------------------. 1 0 – 2π 0 2 –π 4 6 0 8 π 1 0 1 2 2π Figure 6.⎨ -------------------------. we find that the trigonometric Fourier series for the half−wave rectification waveform with no symmetry is A cos 2t cos 4t cos 6t cos 8t A A f ( t ) = --.( sin t ) dt = --.52) Combining (6. Third Edition Copyright © Orchard Publications . 9 0 .+ ------------.52). Solution: The waveform is shown in Figure 6.+ ------------.-. We will find b 1 by direct substitution into (6.⋅ -. Full−wave rectified waveform with even symmetry 6−22 Numerical Analysis Using MATLAB® and Excel®.sin t – --.--------------------------. 1 0 .

The a n coefficients are found from 1 a n = -π ∫0 2π f ( t ) cos nt dt where for this example.+ ------------------------------------π n+1 n–1 (6.– ----------------------------. the average is a non−zero value. ∫ ( sin mx ) ( cos nx ) dx Since we express (6.57).-----------------------a n = --. We choose the period of the input sinusoid so that the output will be expressed in terms of the fundamental frequency.– -----------------------------.n ≠ 1 2 π(n – 1) (6.57) Now. from (6.56). Therefore.( m ≠ n ) 2(m + n) 2(n – m) cos ( x – y ) = cos ( y – x ) = cos x cos y + sin xsiny π 2A 1 ⎧ cos ( n – 1 )t cos ( n + 1 )t . we observe that the waveform has even symmetry. First. We also choose the limits of integration as – π and +π .-------------------------------------. (6.– ----------.------------------------------------------------------------------------------------2 π π n–1 n+1 n –1 – 2A ( cos nπ + 1 ) = ---------------------------------------.a n = -----.56) simplifies to A – 2 + ( n – 1 ) cos nπ – ( n + 1 ) cos nπ A .55) as 2 2 cos ( m – n )x cos ( m + n )x = -----------------------------.⎨ ---------------------------.56) To simplify the last expression in (6. 1 a n = -π ∫ 2A A sin t cos nt dt = -----π –π π ∫0 π sin t cos nt dt (6.Waveforms in Trigonometric Form of Fourier Series By inspection. Third Edition Copyright © Orchard Publications 6−23 .⎨ --------------------------. we will evaluate a 0 to Numerical Analysis Using MATLAB® and Excel®.⎬ π⎩ n–1 n+1 n–1 n+1 ⎭ A 1 – cos ( nπ + π ) cos ( nπ – π ) – 1 = --. we expect only cosine terms to be present.-----------------------.1 + cos nπ – 1 + cos nπ = --.55) and from tables of integrals. we make use of the trigonometric identities and cos ( nπ + π ) = cos nπ cos π – sin nπsinπ = – cos nπ cos ( nπ – π ) = cos nπ cos π + sin nπsinπ = – cos nπ Then.– --------------------------π 2⎩ n–1 n+1 ⎫ ⎬ 0⎭ A ⎧ cos ( n – 1 )π cos ( n + 1 )π 1 1 ⎫ = --.– ----------. except a 1 . we can evaluate all the a n coefficients.⋅ -.

+ ----------------.= – -------2 35π π(6 – 1) – 2A ( cos 8π + 1 ) 4A a 8 = ---------------------------------------.57) we observe that for all n = odd . the DC value is 1 -.Chapter 6 Fourier.61) (6.( sin ax ) 2a From tables of integrals.a 0 = 2A -----2 π (6.57) we get -----a 2 = – 2A ( cos 2π + 1 ) = – 4A ---------------------------------------2 3π π(2 – 1) 4A– 2A ( cos 4π + 1 ) a 4 = ---------------------------------------. Third Edition Copyright © Orchard Publications . a n = 0 . 12 a 1 = ----. Taylor.63) we get ⎫ 4A ⎧ cos 2ωt cos 4ωt cos 6ωt cos 8ωt -----f ( t ) = 2A – -----.+ … ⎬ π ⎩ 3 63 35 15 π ⎭ (6.= – -------2 63π π(8 – 1) (6.58) From (6. other than n = 1 . we must evaluate the integral 1 a 1 = -π π ∫0 sin t cos t dt 1 2 = ----. the trigonometric form of the Fourier series for the full−wave rectification waveform with even symmetry is 6−24 Numerical Analysis Using MATLAB® and Excel®. To obtain the value of a 1 .60) (6.= – -------2 15π π(4 – 1) – 2A ( cos 6π + 1 ) 4A a 6 = ---------------------------------------. Then.60) through (6.62) (6.+ ----------------. from (6.( sin t ) 2π π = 0 0 (6. combining the terms of (6. ∫ ( sin ax ) ( cos ax ) dx and thus.59) For n = even . By substitution of n = 0 .+ ----------------. we get -----a 0 = 4A π Therefore.63) and so on.⎨ ----------------.64) Therefore.58) and (6. and Maclaurin Series obtain the DC value.

Derivation of the alternate form of the trigonometric Fourier series cos θ n = sin ϕ n We assume ω = 1 . However.20. ϕn cn = bn an + bn bn bn sin θ n = --------------------.66) If a given waveform does not have any kind of symmetry. Third Edition Copyright © Orchard Publications 6−25 .Alternate Forms of the Trigonometric Fourier Series 2A 4A f ( t ) = -----. In any waveform where the period is chosen appropriately. We use the triangle shown in Figure 6.20 for the derivation of the alternate forms. we rewrite (6. 6.66) as Numerical Analysis Using MATLAB® and Excel®. it is very unlikely that a Fourier series will consist of even harmonic terms only. the period is defined as the shortest period of repetition. This is because we chose the period to be from – π and +π . 2. and the sum is combined to a single term. we still need to compute the a n and b n coefficients separately.– -----π π 1 -----------------.cos nωt 2 (n – 1) n = 2.65) shows that there is no component of the fundamental frequency.65) This series of (6. 6. 3. either cosine or sine.5 Alternate Forms of the Trigonometric Fourier Series We recall that the trigonometric Fourier series is expressed as 1 f ( t ) = -.= ----cn an + bn an bn ϕ n = atan ----θ n = atan ----bn an Figure 6. … . it may be advantageous of using the alternate form of the trigonometric Fourier series where the cosine and sine terms of the same frequency are grouped together. 4. Generally.= ----cn an + bn cn θn an an an cos θ n = --------------------. and for n = 1. … ∑ ∞ (6.a 0 + a 1 cos ωt + a 2 cos 2ωt + a 3 cos 3ωt + a 4 cos 4ωt + … 2 + b 1 sin ωt + b 2 sin 2ωt + b 3 sin 3ωt + b 4 sin 4ωt + … (6.

in general.cos t + ---.68) can be expressed as phasors.a 0 + 2 n=1 ∑ cn sin ⎛ nωt + atan ----n⎞ ⎝ b⎠ ∞ (6. we get 1 f ( t ) = -. Third Edition Copyright © Orchard Publications .a 0 + c 1 ⎛ 2 ⎝ ⎠ sin ( t + ϕ 1 ) ⎧ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎩ c2 ⎛ ⎝ ⎧ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎩ sin ( 2t + ϕ 2 ) ⎧ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎩ sin ( nt + ϕ n ) an sin ϕ 2 cos 2t + cos ϕ 2 sin 2t ⎞ + … + cn ⎛ ⎠ ⎝ sin ϕ n cos nt + cos ϕ n sin nt ⎞ ⎠ and.Chapter 6 Fourier.a 0 + 2 n=1 ∑ ∞ 1 c n sin ( nωt + ϕ n ) = -.cos 2t + ---. 1 -. in general.a 0 + c 1 ⎛ 2 ⎝ + cn ⎛ ⎝ ⎧ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎩ cos ( t – θ 1 ) ⎧ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎩ cos ( 2t – θ 2 ) bn cos θ 1 cos t + sin θ 1 sin t ⎞ + c2 ⎛ ⎠ ⎝ cos θ 2 cos 2t + sin θ 2 sin 2t ⎞ +… ⎠ and.67) Similarly.a 0 + ⎝ ⎠ 2 an n=1 ∑ cn ∠– atan ----na ∞ bn (6. and Maclaurin Series a1 a2 b1 b2 1 f ( t ) = -.68) The series of (6.cos nt + ---.⎞ ⇔ -.67) and (6.21.a 0 + 2 ⎧ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎩ cos ( nt – θ n ) ∞ cos θ n cos nt + sin θ n sin nt ⎞ ⎠ n=1 ∑ 1 c n cos ( nωt – θ n ) = -.8 Find the first 5 terms of the alternate form of the trigonometric Fourier series for the waveform of Figure 6.a 0 + 2 n=1 ∑ ∞ bn 1 c n cos ⎛ nωt – atan ---. we choose to use the transformation of (6. Since it is customary to use the cosine function in the time domain to phasor transformation. sin ϕ 1 cos t + cos ϕ 1 sin t 1 ⎞ f ( t ) = -.a 0 + c 1 ⎛ ---.63) below.69) Example 6. Taylor. for ω ≠ 1 .sin 2t⎞ + … ⎝ c1 ⎠ ⎝ c2 ⎠ 2 c1 c2 bn an + c n ⎛ ---. 6−26 Numerical Analysis Using MATLAB® and Excel®.a 0 + 2 n=1 ∑ cn cos ⎛ nωt – atan ----n-⎞ ⎝ a ⎠ ∞ (6. we get 1 f ( t ) = -. where ω ≠ 1 .sin t⎞ + c 2 ⎛ ---.sin nt⎞ ⎝ cn ⎠ cn 1 = -.

sin nt nπ π⁄2 π⁄2 0 1 + ----. we expect both cosine and sine functions with odd and even terms present. thus.= ----. a n = 0 .( π + 2π ) = 3 ------⎝2 ⎠ 2π 2 2 (6.sin n -.73) The b n coefficients are Numerical Analysis Using MATLAB® and Excel®.sin n -2 2 nπ nπ 2 nπ nπ (6.8 The given waveform has no symmetry. 1 a n = -π ∫0 π⁄2 1 ( 3 ) cos nt dt + -π ∫ 2π 3 ( 1 ) cos nt dt = ----.sin n -.71) and (6. 2 a 1 = -π 2a 3 = – ----3π (6. the DC value. For n = odd . Third Edition Copyright © Orchard Publications 6−27 .Alternate Forms of the Trigonometric Fourier Series f( t) 3 2 1 ω = 1 t π/2 π 3π/2 2π Solution: Figure 6.+ ----. Also.( 3t 2π π⁄2 0 +t 2π ) π⁄2 1 ⎛ 3π + 2π – π⎞ = ----. and we will combine them to get an expression in the form of (6.72) The DC value is 1 1 -.a 0 = ----2 2π 1 = ----2π ∫0 π⁄2 1 ( 3 ) dt + ----2π ∫ π ⁄ 2 ( 1 ) dt 2π 1 = ----. We will compute the a n and b n coefficients.70) We observe that for n = even . by inspection the DC value is not zero. Then.sin nt nπ 2π π⁄2 π 2 π 1 π 1 3 = ----. Waveform for Example 6.63).sin n2π – ----.21.

∠– 90° ⇔ -.cos ( 3ωt – 135° ) 3π 3π 3π 3π (6.cos ( 2ωt – 90° ) π π π 2 2 2 2 2 2 a 3 – jb 3 = – ----.⎞ ∠– 45° ⎝ π⎠ ⎝ π⎠ 2 2 Similarly.cos n2π + ----. for n = 1.83) Combining the terms of (6.∠– 90° ⇔ ----.81) (6.a 0 + ⎝ ⎠ 2 an bn 2 2 a n + b n ∠– atan ---.77) (6.∠– 45° = --------.( 3 – cos n2π ) = ----2 nπ nπ 2 nπ nπ nπ nπ (6.= ----.+ ----. and Maclaurin Series 1 b n = -π ∫0 π⁄2 1 ( 3 ) sin nt dt + -π ∫ 2π –3 ( 1 ) sin nt dt = ----.79) ∞ bn bn c n ∠– atan ---.a 0 + 2 where n=1 ∑ ∞ bn 1 c n cos ⎛ nωt – atan ---.cos n -.76) (6.74) Then. we get: 2 2 a 1 – jb 1 = -.80) through (6.⎞ + ⎛ -.Chapter 6 Fourier.83).= an a n + b n ∠– θ n = a n – jb n Thus.= -.∠– 135° ⇔ --------. Third Edition Copyright © Orchard Publications .= an 2 2 n=1 ∑ cn ∠– atan ----na (6.cos nt nπ 2π π⁄2 1π 1π 3 –1 –3 2= ----.∠– 45° ⇔ --------.cos n -. 1 -. we find that the alternate form of the trigonometric Fourier series representing the waveform of this example is 6−28 Numerical Analysis Using MATLAB® and Excel®.78) From (6.cos nt nπ π⁄2 π⁄2 0 –1 + ----. and 4 .a 2 – jb 2 = 0 – j -.= --------.69).75) (6.82) and 111a 4 – jb 4 = 0 – j ----. Taylor.cos ( 4ωt – 90° ) 2π 2π 2π (6. 3.+ ----.– j ----.⎞ ⇔ -. 2.80) 1 1 1 .73) and (6. 2 2 2 2 8 ----.– j -. b1 = 2 ⁄ π b2 = 1 ⁄ π b 3 = 2 ⁄ 3π b 4 = 1 ⁄ 2π (6.cos ( ωt – 45° ) π π 2 π (6.= ----.= π π = 2 2 ⎛ -.

a 0 + ⎛ ---.The Exponential Form of the Fourier Series 1 -.+ ----⎞ e + ⎛ ---2 + ----⎞ e ⎝ 2 j2 ⎠ ⎝ 2 j2 ⎠ ⎝ 2 j2⎠ ⎝ 2 j2⎠ 2 (6.⎞ = -.⎛ a n – ---.f ( t ) = 3 + -2 π [2 2 cos ( ωt – 45° ) + cos ( 2ωt – 90° ) 1 2 2 + --------. 1 e +e e +e f ( t ) = -.88) in parentheses are usually denoted as bn 1 1 C – n = -.⎞ e + ---. in most cases the integration is simpler.cos ( 4ωt – 90° ) + … 2 3 ] (6.⎞ = -. Moreover.e + -.⎞ + ⎝ ⎠ ⎝ ⎠ 2 2 2 jωt – jωt j2ωt – j2ωt e –e e –e … + b 1 ⎛ -------------------------. The exponential form is derived from the trigonometric form by substitution of +e --------------------------cos ωt = e 2 jωt – jωt (6.a 0 2 (6.84) 6.6 The Exponential Form of the Fourier Series The Fourier series are often expressed in exponential form.90) (6.cos ( 3ωt – 135° ) + -.⎞ + … ⎝ ⎠ ⎝ ⎠ j2 j2 jωt – jωt j2ωt – j2ωt (6.91) Numerical Analysis Using MATLAB® and Excel®. one for the a n .⎛ a n + ---.⎞ + a 2 ⎛ -------------------------------.– ---. and another for the b n coefficients in the trigonometric form of the series.87) and grouping terms with same exponents. we get a b 2 – j2ωt ⎛ a 1 b 1 ⎞ – jωt 1 a 1 b 1 jωt a b 2 j2ωt f ( t ) = … + ⎛ ---2 – ---.85) and e –e sin ωt = -------------------------j2 jωt – jωt (6.86) into f ( t ) .( a n – j b n ) ⎠ 2 2⎝ j 1 C 0 = -. Third Edition Copyright © Orchard Publications 6−29 . Thus.( a n + jb n ) ⎠ 2 2⎝ j bn 1 1 C n = -. The advantage of the exponential form is that we only need to perform one integration rather than two.89) (6.⎞ + b 2 ⎛ ------------------------------.a 0 + a 1 ⎛ --------------------------.88) The terms of (6.

∫0 2π f ( t )e – jnt dt = … + + + ∫0 C –2 e C0 e C2 e – j2t – jnt e dt + 2π ∫0 ∫0 2π ∫0 C–1 e e dt – jt – jnt dt (6.92) by e – jnωt and integrating over one period.92) We must remember that the C i coefficients. that is.97) are zero except the last. C – n = C n∗ (6.90). ∫0 or 2π f ( t )e – jnt dt = ∫0 2π Cn e jnt – jnt e dt = 2π C n dt = 2πC n 1C n = ----2π ∫0 2π f ( t )e – jnt dt and.89) and (6. by multiplying both sides of (6.88) is written as f ( t ) = … + C –2 e – j2ωt + C –1 e – jωt + C0 + C1 e jωt + C2 e j2ωt +… (6. from (6. Therefore.Chapter 6 Fourier. except C 0 .95) or 1 C n = -T T f ( t )e – jnωt d( ωt ) (6. in general.( a n – jb n + a n + jb n ) 2 6−30 Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications . as we did in the derivation of the a n and b n 2π 2π coefficients of the trigonometric form.94) – jnt dt + 2π ∫0 C1 e e jt – jnt 2π j2t – jnt e dt + … + ∫0 ∫0 Cn e jnt – jnt e dt We observe that all the integrals on the right side of (6.93) We can derive a general expression for the complex coefficients C n .96) We can derive the trigonometric Fourier series from the exponential series by addition and subtraction of the exponential form coefficients C n and C –n . Then. Taylor. 1 C n = ----2π ∫0 ∫0 2π f ( t )e – jnωt d( ωt ) (6. are complex and occur in complex conjugate pairs. and Maclaurin Series Then. 1 C n + C – n = -. Thus. with ω = 1 . for ω ≠ 1 . (6.

all even harmonics are zero. Therefore. all coefficients C i are imaginary Since odd functions have no cosine terms.101) are zero. 1 C n – C – n = -.100) and (6. For even functions. If there is half−wave symmetry.⎛ a n + ---. the b n coefficients in (6.97) (6.100) and (6.( a n + jb n ) ⎝ ⎠ 2 2 j (6.100) and bn 1 1 C n = -. For odd functions. C –n = C n∗ always This can be seen in (6.89) and (6. If there is no symmetry.90) that bn 1 1 C – n = -.( a n – j b n ) ⎝ ⎠ 2 2 j (6.( a n – jb n – a n – j b n ) 2 or bn = j ( Cn – C–n ) (6. 3.The Exponential Form of the Fourier Series or an = Cn + C–n (6.99) Symmetry in Exponential Series 1. Third Edition Copyright © Orchard Publications 6−31 . 5. C n = 0 for n = even We recall from the trigonometric Fourier series that if there is half−wave symmetry.101) the coefficients a n and b n are both zero for n = even . all coefficients C i are real We recall from (6. both C –n and C n are also zero for n = even . 2.⎛ a n – ---. both C –n and C n are imaginary. Therefore.101) Since even functions have no sine terms.100) and (6.98) Similarly. in (6. 4. both C –n and C n are real. the a n coefficients in (6.101) Numerical Analysis Using MATLAB® and Excel®. f ( t ) is complex.100) and (6.101) are zero.⎞ = -.⎞ = -. and thus. Therefore.

( 1 + e – 2e ) = ----------. Therefore.( 1 – 1 ) 2 = 0 = ----------. C n = 0 for n = even .( π – 2π + π ) = 0 2π ∫0 π Ae – jnt dt + ∫π 2π –A e – jnt 1.9 Solution: This is the same waveform as in Example 6. the C n coefficients will be imaginary. For n ≠ 0 . we get 1C n = ----2π ∫0 2π f ( t )e – jnt 1dt = ----2π 2π ∫0 π Ae – jnt 1dt + ----2π ∫π 2π –A e – jnt dt and for n = 0 . n = even Cn 2 A A .------.e – jn 2π π A – jn2π – jnπ A 1 A –jnπ – jnπ – jn2π – jnπ = ----.– jnπ – 1 ) = ----------.------.A. it is an odd function. Waveform for Example 6.– jnt dt = ----. and as we know.( e 2jπn 2jπn (6. Third Edition Copyright © Orchard Publications .22 below. and Maclaurin Series Example 6. Taylor.( e – 1 ) + ---. 1C n = ----2π ∫π A –0 ( – A )e dt = ----.( e –e ) = ----------. e – jnπ = 1 .102) For n = even .1. has half− wave symmetry. and C 0 = 0 .( e 2jπn 2jπn (6.9 Compute the exponential Fourier series for the square waveform of Figure 6. T A π 0 2π ωt −A Figure 6.103) 6−32 Numerical Analysis Using MATLAB® and Excel®.e 2π – jn π 0 – A – jnt + ------.Chapter 6 Fourier. then. Using (6.22.( 1 – e +e –e ) jn 2jπn 2π – jn 2 A A – jn2π – jnπ .–jnπ – 1 ) = ----------. Assume that ω = 1 .95) with ω = 1 . and its DC component is zero. 1 C 0 = ----2π ∫0 π Ae dt + –0 as expected.

Line spectrum for square waveform of Example 6. we group the two terms for which n = 3 . and the higher harmonics times the amplitude of the fundamental.1 * An instrument that displays the spectral lines of a waveform.22) are the same. bn 4/π 0 1 3 5 7 9 nωt Figure 6.( – 1 – 1 ) = ----------. f ( t ) = … + C–2 e – j2ωt + C–1 e – jωt + C0 + C1 e jωt + C2 e j2ωt +… we obtain the exponential Fourier series for the square waveform with odd symmetry as 1 – j3ωt – jωt 2A jωt 1 f ( t ) = -----.23.105) for which n = 1 .– jnπ AA2 2 2A = ----------. For instance. we group the two terms inside the parentheses of (6.105) The minus (−) sign of the first two terms within the parentheses results from the fact that C –n = C n∗ . Numerical Analysis Using MATLAB® and Excel®. To prove that (6. it is useful to plot the amplitudes of the harmonics on a frequency scale that shows the first (fundamental frequency) harmonic. We observe that f ( t ) is purely imaginary. 6. as expected.7 Line Spectra When the Fourier series are known.e –e +e + -. Third Edition Copyright © Orchard Publications 6−33 . since the waveform is an odd function.105) and (6. For n = odd .92). this will produce the fundamental frequency sin ωt .e 3 jπ ⎝ 3 j3ωt ⎞ ⎠ 2A = -----jπ n = odd ∑ 1 -. since C 3 = 2A ⁄ j3π .23 shows the line spectrum of the square waveform of Example 6. Figure 6.e n jnωt (6. Therefore. and this will produce the third harmonic sin 3ωt . it follows that C –3 = C 3∗ = – 2A ⁄ j3π . Such a plot is known as line spectrum and shows the spectral lines that would be displayed by a spectrum analyzer*.( e – 1 ) = ----------.⎛ … – -.( – 2 ) = ------2jπn 2jπn 2jπn jπn n = odd Cn (6. Then. e – jnπ = – 1 . that is. 2 A .1.Line Spectra as expected. and so on.104) Using (6.

106) we get 6−34 Numerical Analysis Using MATLAB® and Excel®. is k times the pulse duration. Example 6. the components of the exponential Fourier series are found from 1C n = ----2π Figure 6.25.6. As shown in Figure 6. from (6.25. it is necessary to know the frequency components. Then. and plot its line spectra. and Maclaurin Series Figure 6. A/ 2 A/π DC 2 4 6 8 nωt 0 1 Figure 6.10 Compute the exponential Fourier series for the waveform of Figure 6. Waveform for Example 6.6 The line spectra of other waveforms can be easily constructed from the Fourier series. A T T /κ −2π −π −π/κ 0 π/κ π 2π ωt Solution: This recurrent rectangular pulse is used extensively in digital communications systems. the recurrence interval (period) T . To determine how faithfully such pulses will be transmitted. Thus. k is the ratio of the pulse repetition time to the duration of each pulse. Third Edition Copyright © Orchard Publications . For this example.24. In other words.Chapter 6 Fourier.24 shows the line spectrum for the half−wave rectification waveform of Example 6. Taylor.25. the pulse duration is T ⁄ k .11 ∫– π π Ae – jnt Adt = ----2π ∫– π ⁄ k e π⁄k – jnt dt (6. Line spectrum for half−wave rectifier of Example 6.106) The value of the average ( DC component) is found by letting n = 0 . Assume ω = 1 .

Line spectrum of (6.π π A = ----.4 1.t 2π π⁄k –π ⁄ k A.4 0. k = 5 and k = 10 respectively by using the MATLAB scripts below.26./(5.2π ⎝ k k ⎠ k (6.⋅ ------------------------k nπ ⁄ k (6.⋅ -----------------------------------.+ -.4 -4 -3 -2 -1 0 1 2 3 4 K=2 Figure 6.*x)'. Third Edition Copyright © Orchard Publications 6−35 .28.2 1 0.= --.109) has the sin x ⁄ x form.8 0.[−4 4 −0. fplot('sin(2.6 0. sin ( nπ ⁄ k ) A sin ( nπ ⁄ k ) = A ------------------------.= ----.26 through 6.⎞ ⎝ k⎠ nπ nπ j2 jnπ ⁄ k – jnπ ⁄ k and thus./(10.[−4 4 −0. integration of (6.4 1.*x)'.– jnt C n = -------------.107) For the values for n ≠ 0 .2 -0.2]) fplot('sin(5.108) f(t) = ∑ n = –∞ ∞ A sin ( nπ ⁄ k ) --.2]) 1.2]) fplot('sin(10.*x).e – jn2 π π⁄k –π ⁄ k nπ AA.⋅ ------------------------nπ k nπ ⁄ k (6.⎛ -.*x)'.*x).e –e = ----. and the line spectrum is shown in Figures 6.4 1.109) for k = 2 Numerical Analysis Using MATLAB® and Excel®./(2.109) The relation of (6.*x). for k = 2 .[−4 4 −0.106) yields A .Line Spectra AC 0 = ----.⋅ sin ⎛ ----.⎞ = --.2 0 -0.

2 1 0. Line spectrum of (6. it is necessary to construct the Fourier expansion of a function based on observed values instead of an analytic expression.112) for k = 10 The spectral lines are separated by the distance 1 ⁄ k and thus.27.6 0.8 0.Chapter 6 Fourier.4 -4 -3 -2 -1 0 1 2 3 4 K=10 Figure 6.2 -0.6 0. Third Edition Copyright © Orchard Publications .4 -4 -3 -2 -1 0 1 2 3 4 K=5 Figure 6. the lines get closer together while the lines are further apart as k gets smaller.28.2 -0.109) for k = 5 1. Examples are meteorological or economic quantities 6−36 Numerical Analysis Using MATLAB® and Excel®.4 0.4 0.2 1 0. Line spectrum of (6. 6. as k gets larger.2 0 -0.8 Numerical Evaluation of Fourier Coefficients Quite often. Taylor.8 0.2 0 -0. and Maclaurin Series 1.

In Column C we enter the corresponding values of y = f ( x ) as measured from the waveform. Third Edition Copyright © Orchard Publications 6−37 . we multiply degrees by π (3. y sin 3x . and Figure 6. and we enter these in subsequent columns of the spreadsheet. The complete tables extend to the seventh harmonic to the right and to 360° down.5° intervals. If the time axis is in degrees.1459. the more pulses we use. a week. the better the approximation. f(x) x Figure 6. a month or even a year. we can choose Δx to be 2.Numerical Evaluation of Fourier Coefficients whose period may be a day. The procedure presented here. will work for both the waveforms that have an analytical solution and those that do not. we can divide the period 0° to 360° in 2. Waveform whose analytical expression is unknown Since the arguments of the sine and the cosine are in radians. we need to evaluate the integral(s) using numerical integration. Then. y sin 2x . were we have divided it into small pulses of width Δx .) and divide by 180 to perform the conversion.29. We enter these in Column B and we denote them as x . we can use this procedure to check our results.30 is a partial table showing the computation of the coefficients of the square waveform. we form the sums of y cos x and y sin x . Numerical Analysis Using MATLAB® and Excel®. such as Microsoft Excel. Even though we may already know the Fourier series from analytical methods. using a spreadsheet.31 is a partial table showing the computation of the coefficients of a clipped sine waveform. Obviously. In these situations. Consider the waveform of f ( x ) shown in Figure 6. we enter the values of sin x and y sin x in Columns F and G respectively. and so on. y cos 3x .. To compute the coefficients of the higher order harmonics. and enter these values in Column A of the spreadsheet.. Next.29. we form the products y cos 2x . In Columns D and E we enter the values of cos x and the product y cos x respectively. Similarly. and we divide by π to obtain the coefficients a 1 and b 1 . Figure 6. we multiply these by Δx .5° and it is convenient to start at the zero point of the waveform.

087 0.966 0.574 0.966 0.0 -1.707 0.866 0.537 0.) Numerical: Average= 1.044 0.5 0.000 1.273 0.000 0.259 0.500 0.131 0.044 0.707 0.954 0.0 7.000 0.985 0.954 0.480 0.174 0.873 .000 0.819 0.000 0.087 0.707 0.087 -0.000 0.180 0.737 0.000 1.174 0.383 -0.000 0.262 0.996 1.259 0.793 0.6−38 Analytical: 1.218 0.819 0.383 0.609 0.5 30.349 0.000 0.000 1.044 0.866 0.643 0.000 -0.567 0.991 0.000 0.000 1.966 0.259 0.000 1.574 0.500 0.301 0.174 0.000 0.5 -1.044 0.707 0.985 0.000 0.5 10.044 0.843 0. Third Edition Copyright © Orchard Publications 0.500 0.676 0.707 0.866 0.766 0.707 0.766 0.924 0.991 1.940 0.707 0.940 0.940 0.424 0.383 0.305 0.707 0.766 0. Numerical computation of the coefficients of the square waveform (partial listing) y=f(x) 0.966 0.676 0.819 0.500 -0.793 0.000 0.259 0.500 0.500 0.999 0.044 0.383 0.906 0.259 -0.976 0.698 0.609 -0.609 0.866 0.500 ysin3x 0.436 0.5 35.5 40.5 20.609 0.5 0.044 0.044 0.924 0.131 0.044 0.707 0.000 1.940 0.423 0.044 0.996 0.259 0.462 0.131 0.423 0.000 0.500 0.000 0.044 0.766 1.000 0.0 2.996 0.131 0.866 0.342 0.131 -0.793 0.423 0.843 0.044 0.174 0.866 0.044 0.676 0.000 0.000 0.000 1.044 0.985 0.044 0.0 32.707 0.0 0.342 0.966 0.383 0.0 8.044 0.643 0.643 0.0 6.866 0.906 0.643 0.996 0.174 0.866 0.906 0.044 0.000 -0.537 0.0 -0.0 27.000 1.131 -0.087 0.966 0.609 0.044 1. Taylor.609 -0.5 15.887 0.087 0.966 0.654 0.676 0.996 0.000 0.966 0.643 0.5*a0 0.742 0.819 0.574 0.737 0.500 0.500 -0.707 0.500 0.131 0.342 0.216 0.301 0.866 0.000 0.500 0.996 0.131 0.707 -0.0 22.423 0.383 -0.342 0.000 0.259 0.044 0.707 0.966 0.866 0.0 4.000 0.000 0.991 1.991 0.000 1.866 0.000 1.766 0.087 0.5 50.174 0.5 45.574 0.643 0.000 1.991 0.737 0.000 1.0 0.000 -0.611 0.000 1.999 0.174 0.259 0.000 Chapter 6 Fourier.609 0.254 0.829 0.423 0.609 0.524 0.000 1.707 0.087 -0.976 0.0 DC= a1= a2= a3= a4= a5= a6= a7= b1= b2= b3= b4= b5= b6= b7= 1.785 0.000 1.000 0.906 0.0 37.087 0.000 0.985 cos3x ycos3x 1.462 0.793 0.906 0.000 0.423 0.5 25.000 0.887 0.966 0.0 47.000 0.087 0.766 0.766 0.393 0.924 0.793 -0.866 0.985 0.044 0.175 0.000 0.866 0.991 0.985 0.924 0.500 x(deg) x(rad) Numerical Analysis Using MATLAB® and Excel®.707 0.707 -0.000 0.259 0.0 12.342 0.924 0.737 0.216 0.643 0.000 1.174 0.000 -0.940 0.819 0.574 0.0 17.259 -0.044 0.866 sin3x 0.766 0.793 0.924 0.342 0.383 0.131 0.924 0.5 5.000 1.259 0.906 0.793 -0.5 Square waveform f(t)=4(sinwt/p+sin3wt/3p+sin5wt/5p+ ….383 0.259 0.793 0.819 0.044 0.0 2.000 0.985 0.996 1.000 1.000 1.924 0.30.991 0.0 42.044 0.966 0.574 0.793 0. and Maclaurin Series Figure 6.643 0.991 0.793 0.996 0.966 0.940 0.609 0.000 1.985 cosx ycosx sinx ysinx cos2x ycox2x sin2x ysin2x 0.500 0.609 0.

006 0.985 0.000 b3= 0.000 -0.0 22.383 -0.654 0.171 0.022 0.5 50.737 0.015 0.022 0.011 0.0 0.044 0.172 0.707 0.216 0.022 0.574 0.500 0.906 0.5*a0 ysin2x 0.453 0.211 0.397 -0. Third Edition Copyright © Orchard Publications y=f(x) cosx 1.146 0.433 0.866 0.321 0.707 0.272 0.028 b6= 0.966 0.410 0.0 2.022 0.150 0.132 0.059 0.383 0.423 0.262 0.0 37.008 0.0 -0.643 0.000 0.271 0.5 20.0 12.002 0.793 0.496 0.342 0.250 Figure 6.611 0.924 0.707 0.354 0.259 0.793 -0.301 0.500 0.940 0.224 0.819 0.966 0.0 8.0 7.423 0.138 b4= 0.008 0.991 0.574 0.0 6.259 0.044 0.609 b2= 0.500 0.500 0.086 0.183 0.676 0.866 0.000 0.500 0.301 0.492 cos3x ycos3x 1.246 0.383 0.043 0.000 -0.737 0.000 0.0 42.211 0.216 0.087 0.044 0.017 0.250 0.044 0.873 6−39 .087 0.954 0.498 0.383 1.354 0.470 0.383 0.084 0.022 0.321 0.480 0.017 0.265 0.220 0.5 0.5 25.321 0.643 0.766 0.5 30.940 0.034 0.065 -0.259 0.609 0.000 -0.087 0.567 0.354 -0.174 0.338 0.000 0.000 0.0 32.609 0.131 -0.009 0.999 0.000 0.5 5.0 17.996 0.050 0.000 Numerical Analysis Using MATLAB® and Excel®.342 0.171 0.087 0.163 0.985 0.174 0.924 0.259 0.304 0.609 -0.218 0.996 0.742 0.5 45.483 0.433 0.819 0.766 0.458 0.707 0.324 0.354 0.423 0.000 0.129 0.271 0.643 0.500 0.121 0.126 0.131 0.785 0.397 0.239 0.5 40.006 0.436 0.819 0.044 0.000 0.500 0.213 0.537 0.0 27.000 0.643 0.5 -1.304 0.131 0.462 0.000 0.966 0.004 0.707 0.129 0.183 0.462 0.383 0.966 0.866 0.500 -0.030 0.000 -0.866 0.000 0.5 10.091 0.707 0.707 -0.174 0.000 0.966 0.004 0.259 -0.179 0.410 0.500 0.000 b5= 0.146 0.940 0.383 0.829 0.183 0.129 -0.924 0.433 0.397 0.000 0.131 0.000 0.087 0.354 0.342 0.500 0.090 0.342 0.500 0.022 0.866 0.250 -0.966 0.5 35.433 sin3x 0.354 0. Numerical computation of the coefficients of a clipped sine waveform (partial listing) x(deg) x(rad) Numerical Evaluation of Fourier Coefficients 0.500 0.985 0.524 0.000 0.483 0.976 0.766 0.172 0.109 0.866 0.000 0.296 0.393 0.991 0.259 0.196 0.287 0.250 0.793 0.305 0.31.259 0.015 0.0 0.887 0.043 0.044 -0.0 4.262 0.000 0.000 0.338 0.304 -0.0 47.500 0.117 0.087 0.174 0.492 0.676 0.991 0.087 0.866 0.423 0.906 0.Analytical: Sine wave clipped at π/6.129 0.047 0.5 1.574 0.500 0.766 0.462 0.793 0.843 0.010 0.349 0.000 b7= -0.500 0.175 0.000 0.500 ysin3x 0.087 -0.498 0.087 0.022 0.698 0.369 0.191 -0.793 0.174 0.500 0.067 0.013 0.131 0.609 0.500 0.996 1.000 0.924 0. Numerical: f(t)=unknown 1.000 0.991 1.408 0.0 0.996 0.000 0.060 0.369 0.378 0.5 2.383 0.707 0.000 0.0 DC= a1= a2= a3= a4= a5= a6= a7= b1= 0.171 0.287 0.002 0.250 0.018 0.022 0.023 0.131 0.985 ycosx sinx ysinx cos2x ycox2x sin2x 0.422 0.022 0. 5π/6 etc.000 0.020 0.5 15.609 0.906 0.0 -1.087 0.269 0.

115) into (6.116) Substitution of (6.111) (6.– ---.Chapter 6 Fourier.-----------. v = V max cos ω t (6.+ … 2! 3! 4! 2 3 4 (6. the current i in a semiconductor diode can be approximated by the relation i = a(e kv – 1) (6. Example 6.113) x x x sin x = x – ---.+ … 2! 4! 6! 2 4 6 3 5 7 The following example illustrates the fact that a power series expansion can lead us to a Fourier Series. that is.111). 6−40 Numerical Analysis Using MATLAB® and Excel®.110) Some familiar power series expansions for real values of x are x x x x e = 1 + x + ---.116) yields.+ ---.+ … 3! 5! 7! x x x cos x = 1 – ---.+ ( kv ) . and the input voltage is a sinusoid.+ ---.( kv ) .114) as ( kv ) . and Maclaurin Series 6. we rewrite (6.– ---.115) Express the current i in (6.+ …⎞ ⎝ ⎠ ⎝ ⎠ 2! 3! 4! 2! 3! 4! 2 3 4 2 3 4 kv (6.11 If the applied voltage v is small (no greater than 5 volts).+ ---.9 Power Series Expansion of Functions A power series has the form ∞ ∑ ak x k=0 k = a0 + a1 x + a2 x + … 2 (6.+ -----------.+ ( kv ) .-----------i = a ⎛ 1 + kv + -----------.114) suggests the power series expansion of (6.114) where a and k are arbitrary constants. Taylor.112) (6.( kv ) -----------.+ ---. Solution: The term e inside the parentheses of (6. Accordingly. Third Edition Copyright © Orchard Publications .114) as a power series.+ -----------.+ … – 1⎞ = a ⎛ kv + ( kv ) .

+ …⎞ ⎝ ⎠ 2! 3! 4! 2 3 4 (6.119) We recall that the series of (6.+ -. we will consider the plot of Figure 6. and has the form of power series of (6. 6.x + … + ---------------.+ ------------------------------. substitution of (6.120) reduces to f (0) n f'' ( 0 ) 2 f ( x ) = f ( 0 ) + f' ( 0 )x + ----------. we obtain a series of the following form: i = A 0 + A 1 cos ωt + A 2 cos 2ωt + A 3 cos 3ωt + A 4 cos 4ωt + … (6.118) Then.+ -.119) is the trigonometric series form of the Fourier series.121) is known as Maclaurin series.10 Taylor and Maclaurin Series A function f ( x ) which possesses all derivatives up to order n at a point x = x 0 can be expanded in a Taylor series as f'' ( x 0 ) f ( x0 ) 2 n f ( x ) = f ( x 0 ) + f' ( x 0 ) ( x – x 0 ) + ------------.cos 3x 4 4 1 4 3 1 cos x = -. that is.( x – x 0 ) + … + ------------------. and terms of all harmonic frequencies.32. To appreciate the usefulness and application of the Taylor series.x 2! n! (n) (6.+ ------------------------------.Taylor and Maclaurin Series ( kV p cos ω t ) ( kV p cos ω t ) ( kV p cos ω t ) i = a ⎛kV max cos ω t + ------------------------------. higher frequencies which are multiples of the fundamental frequency. a term of the fundamental frequency.120) If x 0 = 0 . (6.121) Relation (6.( x – x 0 ) 2! n! (n) (6.cos x + -.cos 2x .8 8 2 (6.cos 2x + -.cos 4x . where i ( v ) represents some experimental data for the current−voltage ( i – v ) characteristics of a semiconductor diode operating at the 0 ≤ v ≤ 5 volts region.117) This expression can be simplified with the use of the following trigonometric identities: 2 1 1 cos x = -.110) with an = f (n) ( 0 ) ⁄ n! . We observe that it consists of a constant term.117) and after simplification. Third Edition Copyright © Orchard Publications 6−41 .2 2 1 3 3 cos x = -. Numerical Analysis Using MATLAB® and Excel®.118) into (6.

32. i 0 ) i0 0 v0 v Figure 6. Current-voltage (i-v) characteristics for a typical semiconductor diode Now. and we denote this first approximation as a 0 shown in Figure 6. we are seeking a constant that it will be the best approximation to the given curve in the vicinity of point P . i 0 ) shown in Figure 6.33. Obviously. Taylor. i i(v) P ( v 0.110).34.33. Third Edition Copyright © Orchard Publications . in the neighborhood of some arbitrary point P ( v 0. suppose that we want to approximate the function i ( v ) by a power series. the horizontal line i 0 passes through point P . We begin by referring to the power series of (6. Therefore. Approximation of the function i ( v ) by a power series 6−42 Numerical Analysis Using MATLAB® and Excel®. We assume that the first n derivatives of the function i ( v ) exist at this point. where we observe that the first term on the right side is a constant.Chapter 6 Fourier. and Maclaurin Series i i(v) 0 v Figure 6.

we express the desired power series as f ( v ) = a0 + a1 ( v – v0 ) + a2 ( v – v 0 ) + a3 ( v – v0 ) + a4 ( v – v0 ) + … 2 3 4 (6. the linear term a 0 + a 1 ( v – v 0 ) can be expressed as i ( v 0 ) + i' ( v 0 ) ( v – v 0 ) . i i( v) P ( v 0. we want the linear term a 0 + a 1 ( v – v 0 ) to be the best approximation to the function i ( v ) in the vicinity of point P .122) Now.35.Taylor and Maclaurin Series i i(v) P ( v 0. Numerical Analysis Using MATLAB® and Excel®.35.34. we seek a linear term of the form a 0 + a 1 x . i 0 ) i0 a0 + a0 ( v – v0 ) a0 a0 ( v – v0 ) v 0 v0 Figure 6. we are interested in the difference v – v 0 . i 0 ) i0 a0 0 v0 Figure 6. But since we want the power series to be a good approximation to the given function for some distance on either side of point P . Accordingly. This will be accomplished if the linear term has the same slope as the given function as shown in Figure 6. Second approximation of i ( v ) It is evident that the slope of i ( v ) at v 0 is i' ( v 0 ) = a 1 and therefore. First approximation of i ( v ) v The next term in the power series is the linear term a 1 x . Third Edition Copyright © Orchard Publications 6−43 . Thus.

( x – a ) + … 3! 2! (6. Example 6. and Maclaurin Series The third term in (6.( v – v 0 ) + -------------. a 4. 6−44 Numerical Analysis Using MATLAB® and Excel®. When this is done.122). by a Taylor series as illustrated by the following example. we choose a 2 such that it matches the second derivative of the function i ( v ) in the vicinity of point P as shown in Figure 6. Taylor.123) We can also describe any function that has an analytical expression.Chapter 6 Fourier. fourth.124) at a = π ⁄ 4 . we must find the first and second derivatives of f ( x ) = tan x .( x – a ) + -----------. and so on of (6.36.122) are found by matching the third. fifth. a 2 ( v – v 0 ) is a quadratic and therefore. Third approximation of i ( v ) Then. Third Edition Copyright © Orchard Publications . a 5 . The remaining coefficients a 3. i 0 ) a0 + a1 ( v – v0 ) a0 a1 ( v – v0 ) a2 ( v – v0 ) i0 2 0 v0 v Figure 6. 2a 2 = i'' ( v 0 ) or a 2 = i'' ( v 0 ) ⁄ 2 .125) and since we are asked to compute the first three terms. i i( v) a0 + a1 ( v – v0 ) + a2 ( v – v0 ) 2 2 P ( v 0. that is.( v – v 0 ) + … 2! 3! (6. i'' ( v 0 ) 2 i''' ( v 0 ) 3 i ( v ) = i ( v 0 ) + i' ( v 0 ) ( v – v 0 ) + ------------.12 Compute the first three terms of the Taylor series expansion for the function y = f ( x ) = tan x (6. and higher order derivatives of the given function with these coefficients. Solution: The Taylor series expansion about point a is given by f'' ( a ) 2 f''' ( a ) 3 f n ( x ) = f ( a ) + f' ( a ) ( x – a ) + ----------.36. we obtain the following Taylor series.

⎞ = 1 ⎝4⎠ ⎝4⎠ f' ( a ) = f' ⎛ -. we get dx d 2 dz ----. Then. and a defines the Taylor approximation about point a . we get.⎞ = 2 ( 1 + 1 )1 = 4 ⎝4⎠ π 2 (6. For example. using ----.(x .8.sec x = sec x ⋅ tan x .130) We can also obtain a Taylor series expansion with the MATLAB taylor(f. 2 dz ----.128) Now.129) and by substitution into (6.1/4 pi) + 8/3(x .n. d tan x = sec x .126).125).(x .126) Next.1/2 pi + 2(x . z=taylor(y. pretty(z) 2 3 4 1 + 2x . To find f'' ( x ) we need to find the first dx d 2 2 derivative of sec x .= f'' ( x ) = 2 ( tan x + 1 ) tan x dx (6. A detailed description can be displayed with the help taylor command.1/4 pi) + ---.127) into (6.(x . the following MATLAB script computes the first 8 terms of the Taylor series expansion of y = f ( x ) = tan x about a = π ⁄ 4 .pi/4). n produces the first n terms in the series.1/4 pi) 64 5 244 6 2176 7 + -.= 2 sec x ----. 2 --fn ( x ) = 1 + 2 ⎛ x – π ⎞ + 2 ⎛ x – π ⎞ + … ⎝ ⎠ ⎝ ⎠ 4 4 (6. y=tan(x). using the trigonometric identity sec x = tan x + 1 2 2 (6.⎞ = tan ⎛ -.1/4 pi) 15 45 315 Numerical Analysis Using MATLAB® and Excel®.1/4 pi) + 10/3(x . at point a = π ⁄ 4 we have: π π f ( a ) = f ⎛ -.127) and by substitution of (6. so f ′ ( x ) = sec x .1/4 pi) + --.a) function where f is a symbolic expression. Third Edition Copyright © Orchard Publications 6−45 .sec x = 2 sec x ( sec x ⋅ tan x ) = 2 sec x ⋅ tan x dx dx (6. so we let z = sec x .⎞ = 1 + 1 = 2 ⎝4⎠ π f'' ( a ) = f'' ⎛ -. x=sym('x').Taylor and Maclaurin Series 2 2 From math tables.

and V T is the thermal voltage which depends on the temperature. we can use the following Maclaurin’s series. the instantaneous current i D and voltage v D are related as iD ( vD ) = ID e v D ⁄ nV T (6.2 ) f ( x ) = f ( 0 ) + f' ( 0 )x + ----------. and its value at room temperature is approximately 25 mV . pretty(fn) 2 3 4 5 1 + t + 1/2 t + 1/6 t + 1/24 t + 1/120 t Example 6. we have f ( t ) = e and thus f ( 0 ) = 1 . 6−46 Numerical Analysis Using MATLAB® and Excel®.14 In a semiconductor diode D . Taylor. t t f n ( t ) = 1 + t + ---. that is. ) f (0.+ … 2! 3! 2 3 (6.132). Expand this relation into a power series that can be used to compute the current when the voltage is small and varies about v D = 0 . t=sym('t'). fn=taylor(exp(t)).134) where I D is the DC (average) component of the current. Solution: Since the voltage is small and varies about v D = 0 .132) For this function.x + … + ---------------.x n! 2! t t y = f (t) = e t (6. Since all derivatives are e .131) (n) (6. Solution: A Maclaurin’s series has the form of (6. the constant n has a value between 1 and 2 depending on the material and physical structure of the diode. and Maclaurin Series Example 6.Chapter 6 Fourier.13 Express the function in a Maclaurin’s series. f' ( 0 ) = f'' ( 0 ) = f''' ( 0 ) = … = 1 and therefore.+ ---. Third Edition Copyright © Orchard Publications .133) MATLAB displays the same result.n f'' ( 0 . then.

134).136) To compute the second and third terms of (6.138) into (6.135).v D + -----------. by substitution of (6.135) we get ⎛ ⎞ 1 .⋅ I D i' D ( v D ) = -------.2 1i D ( v D ) = I D ⎜1 + --------.137) (6.138) Then.v D + --------------.135) The first term i D ( 0 ) on the right side of (6.⋅ I D e dv D nV T nV T v D ⁄ nV T 1 d 1 i'' D ( v D ) = -----------. Then.i D = --------.139) Numerical Analysis Using MATLAB® and Excel®. we must find the first and second derivatives of (6. These are: v D ⁄ nV T d 1 1 and i' D ( 0 ) = --------.136). iD ( 0 ) = ID (6.135) is found by letting v D = 0 in (6.v D + … 2! 3! (6.i D = -----------. Third Edition Copyright © Orchard Publications 6−47 .⋅ I D 2 2 2 2 2 n VT n VT d vD 2 (6. (6.v D + …⎟ 2 2 ⎝ nV T ⎠ n VT (6.⋅ I D e and i''D ( 0 ) = -----------.134). and (6.Taylor and Maclaurin Series i'' D ( 0 ) 2 i''' D ( 0 ) 3 i D ( v D ) = i D ( 0 ) + i' D ( 0 )v D + -------------.137).

sin nωt n 6−48 Numerical Analysis Using MATLAB® and Excel®. The coefficients a 0 . represent the fundamental frequency component ω . but inverted. and a 0 may or may not be zero. the terms with the coefficients a 2 and b 2 together.sin 3ωt + -. the shape of the negative half−cycle of the waveform is the same as that of the positive half−cycle. the series will consist of cosine terms only. If a waveform has half−wave symmetry only odd (odd cosine and odd sine) harmonics will be present. Third Edition Copyright © Orchard Publications . if it is an odd function. Likewise.sin 5ωt + …⎞ = -----⎠ π 5 3 π ⎝ n = odd ∑ 1 -.a 0 + 2 ∞ n=1 ∑ ( a cos nωt + b sin nωt ) n n where the first term a 0 ⁄ 2 is a constant.⎛ sin ωt + -. and represents the DC (average) component of f ( t ) . that is.Chapter 6 Fourier. • The trigonometric Fourier series for the square waveform with odd symmetry is 4A 1 1 4A f ( t ) = -----. Taylor. if it is an even function. In other words. a n . Odd functions are those for which – f ( – t ) = f ( t ) .11 Summary • Any periodic waveform f ( t ) can be expressed as 1 f ( t ) = -. and b n are found from the following relations: 1 1 -. • If a waveform has even symmetry.a 0 = ----2 2π 1 a n = -π ∫0 2π f ( t ) dt ∫0 2π f ( t ) cos nt dt 1 b n = -π ∫0 2π f ( t ) sin nt dt • If a waveform has odd symmetry. and so on. all even (even cosine and even sine) harmonics will be zero. the series will consist of sine terms only. represent the second harmonic component 2ω . Even functions are those for which f( –t ) = f( t ) • A periodic waveform with period T . and Maclaurin Series 6. The terms with the coefficients a 1 and b 1 together. that is. has half−wave symmetry if –f ( t + T ⁄ 2 ) = f ( t ) that is.

( a n + jb n ) 2 2⎝ j⎠ bn 1 1 C n = -. except C 0 . Third Edition Copyright © Orchard Publications 6−49 .⎞ = -.f ( t ) = A + --.Summary • The trigonometric Fourier series for the square waveform with even symmetry is 4A 1 4A 1 f ( t ) = -----.cos 3ωt + -.sin 5ωt – ----.sin 2ωt + -.a 0 2 • The C i coefficients.cos nωt 2 (n – 1) n = 2.⎞ = -. … ∑ ∞ • The Fourier series are often expressed in exponential form as f ( t ) = … + C –2 e – j2 ω t + C –1 e –j ω t + C0 + C1 e jωt + C2 e j2 ω t +… where the C i coefficients are related to the trigonometric form coefficients as bn 1 1 C – n = -.cos n ωt n • The trigonometric Fourier series for the sawtooth waveform with odd symmetry is 2A 1 1 1 2A f ( t ) = -----.sin n ωt 2 n • The trigonometric Fourier series for the half−wave rectification waveform with no symmetry is A cos 2t cos 4t cos 6t cos 8t A --.sin 3ωt + ----.sin 4ωt + …⎞ = -----⎝ ⎠ π 4 3 2 π ∑ ( –1 ) n–1 1 -.+ ------------.⎛ cos ω t – -.+ ------------.⎛ sin ω t – -. C – n = C n∗ Numerical Analysis Using MATLAB® and Excel®.⎛ a n – ---. that is.( a n – j b n ) ⎠ 2 2⎝ j 1 C 0 = -. 4.⎛ sin ωt – -. 6.sin nωt n • The trigonometric Fourier series for the triangular waveform with odd symmetry is 8A 1 8A 1 1 f ( t ) = -----.+ ------------.cos 5ωt – …⎞ = -----⎠ π 5 π ⎝ 3 n = odd ∑ ( –1 ) (n – 1) ---------------2 1 -.– -----π π 1 -----------------.sin 7ωt + …⎞ = -----( –1 ) 2 ⎝ 2 ⎠ 49 25 9 π n = odd π ∑ (n – 1) ---------------2 1 ---.sin t – --. are complex. and appear as complex conjugate pairs.⎛ a n + ---.sin 3ωt – -.+ … π 2 63 35 15 3 π • The trigonometric Fourier series for the full−wave rectification waveform with even symmetry is 2A 4A f ( t ) = -----.------------.

**Chapter 6 Fourier, Taylor, and Maclaurin Series
**

• In general, for ω ≠ 1 , 1 C n = -T

∫0

T

f ( t )e

– jn ω t

1 d( ωt ) = ----2π

∫0

2π

f ( t )e

– jn ω t

d( ωt )

• We can derive the trigonometric Fourier series from the exponential series from the relations a n = Cn + C–n

and

b n = j ( Cn – C–n )

• For even functions, all coefficients C i are real • For odd functions, all coefficients C i are imaginary • If there is half−wave symmetry, C n = 0 for n = even • C –n = C n∗ always • A line spectrum is a plot that shows the amplitudes of the harmonics on a frequency scale. • The frequency components of a recurrent rectangular pulse follow a sin x ⁄ x form. • We can evaluate the Fourier coefficients of a function based on observed values instead of an

analytic expression using numerical evaluations with the aid of a spreadsheet.

• A power series has the form

∑ ak x k=0

in a Taylor series as

∞

k

= a0 + a1 x + a2 x + …

2

**• A function f ( x ) that possesses all derivatives up to order n at a point x = x 0 can be expanded f'' ( x 0 ) f ( x0 ) 2 n f ( x ) = f ( x 0 ) + f' ( x 0 ) ( x – x 0 ) + ------------- ( x – x 0 ) + … + ------------------- ( x – x 0 ) 2! n!
**

(n)

**If x 0 = 0 , the series above reduces to
**

f (0) n f'' ( 0 ) 2 f ( x ) = f ( 0 ) + f' ( 0 )x + ----------- x + … + ---------------- x 2! n!

(n)

**and this relation is known as Maclaurin series
**

• We can also obtain a Taylor series expansion with the MATLAB taylor(f,n,a) function where f is a symbolic expression, n produces the first n terms in the series, and a defines the Taylor approximation about point a .

6−50

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

Exercises 6.12 Exercises

1. Compute the first 5 components of the trigonometric Fourier series for the waveform below. Assume ω = 1 .

f( t) A

0

ωt

**2. Compute the first 5 components of the trigonometric Fourier series for the waveform below. Assume ω = 1 .
**

f( t) A 0 ωt

**3. Compute the first 5 components of the exponential Fourier series for the waveform below. Assume ω = 1 .
**

f(t)

A

0

ωt

**4. Compute the first 5 components of the exponential Fourier series for the waveform below. Assume ω = 1 .
**

f( t) A⁄2 0 –A ⁄ 2 ωt

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

6−51

**Chapter 6 Fourier, Taylor, and Maclaurin Series
**

5. Compute the first 5 components of the exponential Fourier series for the waveform below. Assume ω = 1 .

f(t)

A

0

ωt

**6. Compute the first 5 components of the exponential Fourier series for the waveform below. Assume ω = 1 .
**

f(t)

A ωt

0 −A Figure 6.37. Waveform for Exercise 6

**7. Compute the first 4 terms of the Maclaurin series for each of the following functions. a. f ( x ) = e
**

–x

b. f ( x ) = sin x

c. f ( x ) = sinh x

Confirm your answers with MATLAB. 8. Compute the first 4 terms of the Taylor series for each of the following functions.

1 a. f ( x ) = -- about a = – 1 x -b. f ( x ) = sin x about a = – π 4

**Confirm your answers with MATLAB. 9. In a non−linear device, the voltage and current are related as
**

v 1.5 i ( v ) = k ⎛ 1 + --- ⎞ ⎝ V⎠

where k is a constant and V is the DC component of the instantaneous voltage v . Expand this function into a power series that can be used to compute the current i , when the voltage v is small, and varies about v = 0 .

6−52

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Solutions to End−of−Chapter Exercises 6.13 Solutions to End−of−Chapter Exercises
**

1.

f(t) A A --- t π

– 2π

–π

0

π

2π

ωt

This is an even function; therefore, the series consists of cosine terms only. There is no half− wave symmetry and the average ( DC component) is not zero. We will integrate from 0 to π and multiply by 2 . Then,

2 a n = -π

∫0

π

From tables of integrals,

A --- t cos nt dt = 2A -----2 π π

∫0 t cos nt dt

π

(1)

∫ x cos ax dx

and thus (1) becomes

t 2A 1 - a n = ------ ⎛ ---- cos nt + -- sin nt ⎞ 2⎝ 2 ⎠ n π n

x 1= ---- cos ax + -- sin a x 2 a a

π

0

t 2A 1 1 - = ------ ⎛ ---- cos nπ + -- sin ntπ – ---- – 0 ⎞ 2⎝ 2 ⎠ 2 n π n n

**and since sin ntπ = 0 for all integer n ,
**

2A 2A 1 1 - a n = ------ ⎛ ---- cos nπ – ---- ⎞ = ---------- ( cos nπ – 1 ) (2) 2⎝ 2 2⎠ 2 2 π n n n π

**We cannot evaluate the average ( 1 ⁄ 2 ) ⁄ a 0 from (2); we must use (1). Then, for n = 0 ,
**

1 2A -- a 0 = -------2 2 2π

∫0

π

A t - t dt = ---- ⋅ --2 π 2

2 π 0

A π - = ---- ⋅ ---2 π 2

2

or

( 1 ⁄ 2 ) ⁄ a0 = A ⁄ 2

**We observe from (2) that for n = even , a n = even = 0 . Then,
**

– 4A 4A– 4A -----for n = 1, a 1 = – 4A, for n = 3, a 3 = ---------- , for n = 5, a5 = – ---------- , for n = 7, a 3 = ---------2 2 2 2 2 2 2 π 3 π 5 π 7 π

and so on. Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

6−53

**Chapter 6 Fourier, Taylor, and Maclaurin Series
**

Therefore,

4A 111 4A 1 --f ( t ) = -- a 0 – ------ ⎛ cos t + -- cos 3t + ----- cos 5t + ----- cos 7t + …⎞ = A – -----2⎝ ⎠ π 49 25 9 2 2 π

∑

n = odd

∞

1---- cos nt 2 n

2.

f( t) A 2A ------ t π 0 π⁄2 π 3π ⁄ 2 π

ωt

This is an even function; therefore, the series consists of cosine terms only. There is no half− wave symmetry and the average ( DC component) is not zero.

1 Area 2 × [ ( A ⁄ 2 ) ⋅ ( π ⁄ 2 ) ] + Aπ 3A ⋅ ( π ⁄ 2 ) 3A Average = -- a 0 = ---------------- = --------------------------------------------------------------- = -------------------------- = -----2 Period 2π 2π 4 2 a n = -π

∫0

π⁄2

2A 2 ------ t cos nt dt + -π π

and with

∫π ⁄ 2 A cos nt dt

π

(1)

∫ x cos ax dx

(1) simplifies to

**1x 1= ---- cos ax + -- sin a x = ---- ( cos ax + ax sin ax ) 2 2 a a a
**

π⁄2

0

4A 1 - a n = ------ ---- ( cos nt + nt sin nt ) 2 2 π n

2A + ------ sin nt nπ

π π⁄2

2A nπ 4A - ----= ---------- ⎛ cos nπ + ----- sin nπ – 1 – 0⎞ + ------ ⎛ sin nπ – sin nπ⎞ --------⎠ nπ ⎝ 2 2⎝ 2 2⎠ 2 2 n π

**and since sin ntπ = 0 for all integer n ,
**

4A 4A nπ 2A nπ 4A 2A nπ nπ a n = ---------- cos ----- + ------ sin ----- – ---------- – ------ sin ----- = ---------- ⎛ cos ----- – 1⎞ ⎠ 2 2 2 2 2⎝ nπ 2 2 2 2 nπ 2 n π n π n π 4A 4A 4A 2A for n = 1, a 1 = ------ ( 0 – 1 ) = – ------ , for n = 2, a 2 = -------- ( – 1 – 1 ) = – -----2 2 2 2 π 4π π π 4A – 4A 4A for n = 3, a 3 = -------- ( 0 – 1 ) = – -------- , for n = 4, a 4 = ---------- ( 1 – 1 ) = 0 2 2 2 2 9π 9π 7 π

We observe that the fourth harmonic and all its multiples are zero. Therefore,

6−54

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Solutions to End−of−Chapter Exercises
**

1 4A 1 -----f ( t ) = 3A – ------ ⎛ cos t + -- cos 2t + -- cos 3t + …⎞ 2⎝ ⎠ 9 2 4 π f(t)

A

3.

0

π

2π

ωt

This is neither an even nor an odd function and has no half−wave symmetry; therefore, the series consists of both cosine and sine terms. The average ( DC component) is not zero. Then,

1 C n = ----2π

∫0

π

2π

f ( t )e

– jn ω t

d( ωt )

and with ω = 1

1C n = ----2π

∫0

2π

f ( t )e

– jnt

1dt = ----2π

∫0

Ae

– jnt

dt +

∫π

π

0

2π

0e

– jnt

Adt = ----2π

∫0 e

π

– jnt

dt

The DC value is

A C 0 = ----2π

∫0

π

A 0 e dt = ----- t 2π

π

0

A = --2

For n ≠ 0

A C n = ----2π

∫0

π

e

– jnt

A – jnt dt = -------------- e – j2 nπ

A – jn π = ----------- ( 1 – e ) j2nπ

Recalling that

e

– jn π

= cos nπ – j sin nπ

– jn π

for n = even , e

– jn π

= 1 and for n = odd , e

= – 1 . Then,

A C n = even = ----------- ( 1 – 1 ) = 0 j2nπ

and

A A C n = odd = ----------- [ 1 – ( – 1 ) ] = ------j2nπ jnπ

**By substitution into the expression
**

f ( t ) = … + C –2 e

– j2 ω t

+ C –1 e

–j ω t

+ C0 + C1 e

jωt

+ C2 e

j2 ω t

+…

we find that Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

6−55

**Chapter 6 Fourier, Taylor, and Maclaurin Series
**

A 1 –j3 ω t –j ω t j ω t 1 j3 ω t --f ( t ) = A + ---- ⎛ … – -- e –e + e + -- e + …⎞ ⎠ 3 3 2 jπ ⎝

The minus (−) sign of the first two terms within the parentheses results from the fact that C – n = C n∗ . For instance, since C 1 = 2A ⁄ jπ , it follows that C –1 = C 1∗ = – 2A ⁄ jπ . We observe that f ( t ) is complex, as expected, since there is no symmetry. 4.

f( t) A⁄2 0 –A ⁄ 2 ωt

**This is the same waveform as in Exercise 3 where the DC component has been removed. Then,
**

1 – j3 ω t – j ω t A j ω t 1 j3 ω t f ( t ) = ---- ⎛ … – -- e –e + e + -- e + …⎞ ⎠ 3 jπ ⎝ 3

It is also the same waveform as in Example 6.9, Page 6−32, except that the amplitude is halved. This waveform is an odd function and thus the expression for f ( t ) is imaginary. 5.

f(t)

A

–π –π ⁄ 2

0 π⁄2

π

ωt

This is the same waveform as in Exercise 3 where the vertical axis has been shifted to make the waveform an even function. Therefore, for this waveform C n is real. Then,

1C n = ----2π

∫– π

π

f ( t )e

– jnt

Adt = ----2π

∫– π ⁄ 2 e

π⁄2

– jnt

dt

The DC value is

AC 0 = ----- t 2π

π⁄2

–π ⁄ 2

A- π π A = ----- ⎛ -- + -- ⎞ = --- 2π ⎝ 2 2⎠ 2

For n ≠ 0

6−56

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Solutions to End−of−Chapter Exercises
**

AC n = ----2π

∫– π ⁄ 2

π⁄2

e

– jnt

A - – jnt dt = -------------- e – j2 nπ

π⁄2

–π ⁄ 2

A - – jn π ⁄ 2 jn π ⁄ 2 = -------------- ( e –e ) – j2 nπ

– jn π ⁄ 2

–e A A e A - ----- jn π ⁄ 2 – e – jn π ⁄ 2 ) = ----- ⎛ ------------------------------------- ⎞ = ----- sin nπ = ----------- ( e ⎠ nπ j2 nπ ⎝ j2nπ 2

jn π ⁄ 2

**and we observe that for n = even , C n = 0 For n = odd , C n alternates in plus (+) and minus (−) signs, that is,
**

AC n = ----- if n = 1, 5, 9, … nπ A C n = – ----- if n = 3, 7, 11, … nπ

Thus,

A f ( t ) = --- + 2

n = odd

∑

A⎛ ± ----- e jn ω t⎞ ⎝ nπ ⎠

where the plus (+) sign is used with n = 1, 5, 9, … and the minus (−) sign is used with n = 3, 7, 11, … . We can express f ( t ) in a more compact form as

A f ( t ) = --- + 2

6.

n = odd

∑

( –1 )

(n – 1) ⁄ 2

A ----- e jn ω t nπ

f(t) –π ⁄ 2 –π −A

A

2A ------ t – 1 π π

ωt

π⁄2 0

**We will find the exponential form coefficients C n from
**

1C n = ----2π

From tables of integrals

∫–π f ( t )e

ax

π

– jnt

dt

∫

Then,

e xe dx = ------ ( ax – 1 ) 2 a

ax

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

6−57

**Chapter 6 Fourier, Taylor, and Maclaurin Series
**

1C n = ----2π

∫

⎛ – 2A t – 1⎞ e – jnt dt + -----⎝ π ⎠ –π

0

∫0 ⎛ ------- t – 1⎞ e ⎝ π ⎠

π

2A

– jnt

dt

**Integrating and rearranging terms we get
**

jn π – jn π 2A e e 1- 4A 4A –e –e +e --------------------------- ⎞ – ------ ⋅ --------------------------C n = ----- – -------- + -------- ⎛ nπ ⋅ --------------------------- + e ⎠ n 2π n 2 π n 2 π ⎝ j2 j2 2 jn π – jn π jn π – jn π

4A nπ = -------------- ⎛ – 1 + nπ sin nπ + cos nπ – ----- sin nπ⎞ 2 2⎝ ⎠ 2 2n π

**and since sin nπ = 0 for all integer n ,
**

2A C n = ---------- ( cos nπ – 1 ) 2 2 n π –4 A For n = even , C n = 0 and for n = odd , cos nπ = – 1 , and C n = ---------2 2 n π

**Also, by inspection, the DC component C 0 = 0 . Then,
**

1 – j3 ω t –j ω t j ω t 1 j3 ω t 4A +e + e + -- e + …⎞ f ( t ) = – ------ ⎛ … + -- e ⎠ 2⎝ 9 9 π

The coefficients of the terms e

– j3 ω t

and e

–j ω t

are positive because all coefficients of C n are

real. This is to be expected since f ( t ) is an even function. It also has half−wave symmetry and thus C n = 0 for n = even as we’ve found. 7.

f (0) n f'' ( 0 ) 2 f ( x ) = f ( 0 ) + f' ( 0 )x + ----------- x + … + ---------------- x 2! n!

(n)

a. f ( x ) = e , f ( 0 ) = 1 , f' ( x ) = – e , f' ( 0 ) = – 1 , f'' ( x ) = e , f'' ( 0 ) = 1 , f''' ( x ) = – e f''' ( 0 ) = – 1 , and so on. Therefore,

x x f n ( x ) = 1 – x + ---- – ---- + … 2! 3!

2 3

–x

–x

–x

–x

,

**MATLAB displays the same result.
**

x=sym('x'); fn=taylor(exp(−x)); pretty(fn) 2 1 - x + 1/2 x - 1/6 x 3 + 1/24 x 4 - 1/120 x 5

6−58

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Solutions to End−of−Chapter Exercises
**

b. f ( x ) = sin x ,

f (0) = 0 , f' ( x ) = cos x , f' ( 0 ) = 1 , f'' ( x ) = – sin x , f'' ( 0 ) = 0 , f''' ( x ) = – cos x , f''' ( 0 ) = – 1 , and so on. Therefore, x x x f n ( x ) = x – ---- + ---- – ---- + … 3! 5! 7!

3 5 7

**MATLAB displays the same result.
**

x=sym('x'); fn=taylor(sin(x)); pretty(fn) 3 x - 1/6 x + 1/120 x f'' ( x ) = sin hx , f'' ( 0 ) = 0 , 5

c. f ( x ) = sin hx ,

**f ( 0 ) = 0 , f' ( x ) = cos hx , f' ( 0 ) = 1 , f''' ( x ) = cos hx , f''' ( 0 ) = 1 , and so on. Therefore, x x x f n ( x ) = x + ---- + ---- + ---- + … 3! 5! 7!
**

3 5 7

**MATLAB displays the same result.
**

x=sym('x'); fn=taylor(sinh(x)); pretty(fn) 3 x + 1/6 x + 1/120 x 5

8.

f'' ( a ) 2 f''' ( a ) 3 f n ( x ) = f ( a ) + f' ( a ) ( x – a ) + ----------- ( x – a ) + ------------ ( x – a ) + … 2! 3!

a. f ( x ) = 1 ⁄ x , f ( a ) = f ( – 1 ) = – 1 , f' ( x ) = – 1 ⁄ x , f' ( a ) = f' ( – 1 ) = – 1 , f'' ( x ) = 2 ⁄ x ,

f'' ( a ) = f'' ( – 1 ) = – 2 , f''' ( x ) = – 6 ⁄ x , f''' ( a ) = f''' ( – 1 ) = – 6 , and so on. Therefore, fn ( x ) = –1 –( x + 1 ) – ( x + 1 ) – ( x + 1 ) + …

2 3 4

2

3

or

fn ( x ) = –2 –x – ( x + 1 ) – ( x + 1 ) + …

2

3

**MATLAB displays the same result.
**

x=sym('x'); y=1/x; z=taylor(y,4,−1); pretty(z) 2 -2 - x - (x + 1) - (x + 1) f' ( x ) = cos x , f' ( a ) = f' ( – π ⁄ 4 ) = 2 ⁄2, 3

b. f ( x ) = sin x ,

f ( a ) = f ( –π ⁄ 4 ) = – 2 ⁄ 2 ,

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

6−59

**Chapter 6 Fourier, Taylor, and Maclaurin Series
**

f'' ( x ) = – sin x , f'' ( a ) = f'' ( – π ⁄ 4 ) = 2 ⁄ 2, f''' ( x ) = – cos x ,

f''' ( a ) = f''' ( – π ⁄ 4 ) = – 2 ⁄ 2 , and so on. Therefore, f n ( x ) = – 2 ⁄ 2 + ( 2 ⁄ 2 ) ( x + π ⁄ 4 ) + ( 2 ⁄ 4 ) ( x + π ⁄ 4 ) – ( 2 ⁄ 12 ) ( x + π ⁄ 4 ) + …

2 3

**MATLAB displays the same result.
**

x=sym('x'); y=sin(x); z=taylor(y,4,−pi/4); pretty(z) 1/2 - 1/2 2 1/2 - 1/12 2 (x + 1/4 pi) v 1.5 i ( v ) = k ⎛ 1 + --- ⎞ ⎝ V⎠ + 1/2 2 1/2 (x + 1/4 pi) + 1/4 2 3 1/2 (x + 1/4 pi) 2

9.

**The Taylor series for this relation is
**

i'' ( v 0 ) 2 i''' ( v 0 ) 3 i ( v ) = i ( v 0 ) + i' ( v 0 ) ( v – v 0 ) + ------------- ( v – v 0 ) + -------------- ( v – v 0 ) + … 2! 3!

Since the voltage v is small, and varies about v = 0 , we expand this relation about v = 0 and the series reduces to the Maclaurin series below.

i'' ( 0 ) 2 i ( v ) = i ( 0 ) + i' ( 0 )v + ----------- v + … 2!

(1)

**By substitution of v = 0 into the given relation we get
**

i(0) = k

**The first and second derivatives of i are
**

3k v 1⁄2 i' ( v ) = ------ ⎛ 1 + --- ⎞ 2V ⎝ V⎠ 3k v –1 ⁄ 2 i'' ( v ) = --------- ⎛ 1 + --- ⎞ 2⎝ V⎠ 4V 3k i' ( 0 ) = -----2V 3k i'' ( 0 ) = --------2 4V

**and by substitution into (1)
**

3k 2 3 2 3k 3 i ( v ) = k + ------ v + --------- v + … = k ⎛ 1 + ------ v + --------- v + …⎞ 2 2 ⎝ ⎠ 2V 2V 8V 8V

6−60

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Solutions to End−of−Chapter Exercises
**

MATLAB displays the same result.

x=sym('x'); i=sym(‘i’); v=sym(‘v’); k=sym(‘k’); V=sym(‘V’);... i=k*(1+v/V)^1.5; z=taylor(i,4,0); pretty(z) 2 3 k v k v k v k + 3/2 --- + 3/8 ---- - 1/16 ---V 2 3 V V

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

6−61

x j ) = ---------------------------xi – xj (7. the second divided difference is defined as: f ( x i. x j. not necessarily consecutive values of x . TABLE 7. Finite Differences form the basis of numerical analysis as applied to other numerical methods such as curve fitting. x n – 1. the first divided difference is defined as: f ( xi ) – f ( xj ) f ( x i. and its corre- sponding values of y = f ( x ) in tabular form as in Table 7. Then. numerical differentiation. These applications are discussed in this and the next three chapters. x 1. x k ) f ( x i. and numerical integration. data smoothing. It is customary to show the independent variable x . T 7. x k ) = --------------------------------------------xi – xk (7. x j ) – f ( x j.1 Divided Differences Consider the continuous function y = f ( x ) and let x 0. Third Edition Copyright © Orchard Publications 7−1 .1 The variable x and y = f ( x ) in tabular form x x0 x1 x2 f (x) f ( x0 ) f ( x1 ) f ( x2 ) … xn – 1 xn … f ( xn – 1 ) f ( xn ) Let x i and x j be any two. ….2) Numerical Analysis Using MATLAB® and Excel®. x n be some values of x in the interval x 0 ≤ x ≤ x n . within this interval.1. x 2.Chapter 7 Finite Differences and Interpolation his chapter begins with finite differences and interpolation which is one of its most important applications.1) Likewise.

2 Conventional presentation of divided differences x x0 f (x) f ( x0 ) f ( x 0. (7. the values of f ( x ) corresponding to y = f ( x ) = x . x 1.= 13 1–3 and third value on the second divided difference is found from (7. and so on divided differences. 7. for the third divided difference we have 7−2 Numerical Analysis Using MATLAB® and Excel®.2. x 1. These differences are computed from (7.= 14 3–7 Likewise. The divided differences are indicated in a difference table where each difference is placed between the values of the column immediately to the left of it as shown in Table 7.1) as 1 – 27 -------------. x 1 ) x1 f ( x1 ) f ( x 1. and the third through the sixth contain the values of the first through the fourth divided differences.2) as 37 – 93 ----------------. The first column contains the given values of x . are defined similarly. the second the values of f ( x ) .2). and 9 . x 3 ) x3 f ( x3 ) f ( x 1. 4. TABLE 7. x 2 ) x2 f ( x2 ) f ( x 2. fourth.3 with six columns.1 Form a difference table showing the values of x given as 0. x 3 ) f ( x 0.Chapter 7 Finite Differences and Interpolation The third. 2. x 2 ) f ( x 0. and other relations for higher order divided differences. For instance. x 2. 3 Solution: We construct Table 7. x 3 ) Example 7. x 2. 1. the second value on the first divided difference is found from (7.1). and the first through the fourth divided differences. Third Edition Copyright © Orchard Publications . 3.

the typical value of x k is x k = x 0 + kh for k = … . In this case. If the constant difference between successive values of x is h . … (7. they can be omitted.3 Divided differences for Example 7. 1. These values are referred to as just the differences of the function. – 1.Divided Differences TABLE 7.1 Function x 0 1 3 4 7 9 Divided Differences 3 f( x) = x 0 First 1 Second Third Fourth 1 13 27 37 64 93 343 193 729 4 1 8 1 14 1 20 0 0 4–8 = 1 ----------0–4 and for the fourth 1–1 ----------. as in the fifth column (third divided differences for this example).= 0 0–4 We observe that. the values of x in a table are equally spaced. In most cases.3) We can now express the first differences in terms of the difference operator Δ as Δf k = f k + 1 – f k (7. the denominators are all the same. all subsequent differences will be equal to zero. Moreover. if the values of the nth divided difference are the same. therefore. 2. the differences are sets of consecutive values. the second differences are Δ f k = Δ ( Δf k ) = Δf k + 1 – Δf k 2 (7.4) Likewise.– 2.5) Numerical Analysis Using MATLAB® and Excel®. 0. Third Edition Copyright © Orchard Publications 7−3 .

4 Divided differences table in terms of the difference operator Δ Function x f First Second Differences Third Fourth … x0 f0 Δf 0 x1 f1 Δf 1 Δ f0 Δ f0 Δ f1 Δf 2 Δ f1 Δ f2 Δf 3 2 3 2 3 2 x2 f2 Δ f0 4 x3 f3 x4 … xn f4 fn Example 7. and the first through the fourth differences. 6. Δ ( Δ fk ) = Δ m n m+n fk (7.4.7) We construct the difference table in terms of the difference operator Δ as shown in Table 7.Chapter 7 Finite Differences and Interpolation and. 5. 2. 4. TABLE 7.6) The difference operator Δ obeys the law of exponents. 7 and 8 . for positive integer values of n Δ fk = Δ ( Δ n n–1 fk ) = Δ n–1 fk + 1 – Δ n–1 fk (7. that is.2 Construct a difference table showing the values of x given as 1. in general. 3 7−4 Numerical Analysis Using MATLAB® and Excel®. 3. the values of f ( x ) corresponding to y = f ( x ) = x . Third Edition Copyright © Orchard Publications .

Using the binomial expansion we can show that n! ⎛ n⎞ = -------------------⎝ j⎠ j! ( n – j )! (7. relation (7.5 Difference table for Example 7.Divided Differences Solution: Following the same procedure as in the previous example.5. as expected. Third Edition Copyright © Orchard Publications 7−5 . we construct Table 7.8) n n–1 n n(n – 1) Δ f k = f k + n – nf k + n – 1 + ------------------. 2. 3 and 4 .2 Function k 1 2 3 4 5 6 7 8 xk 1 2 3 4 5 6 7 8 fk 1 7 8 19 27 37 64 61 125 91 216 127 343 169 512 4 Differences Δf k Δ fk 2 Δ fk 3 Δ fk 4 … 12 6 18 6 24 6 30 6 36 6 42 0 0 0 0 We observe that the fourth differences Δ f k are zero. n = 1.f k + n – 2 + … + ( – 1 ) nf k + 1 + ( – 1 ) f k 2! (7.9) reduces to Δf 0 = f 2 – f 1 Δ f 0 = f 2 – 2f 1 + f 0 Δ f 0 = f 3 – 3f 2 + 3f 1 – f 0 Δ f 0 = f 4 – 4f 3 + 6f 2 – 4 f 1 + f 0 4 3 2 (7. TABLE 7.10) Numerical Analysis Using MATLAB® and Excel®.9) For k = 0 .

Third Edition Copyright © Orchard Publications .18) and letting x = 0 .16). Using the difference operator Δ with (7.10).14) we obtain Δp n ( x ) = 1x a 1 + 2a 2 ( x ) 0 (1) + 3a 3 ( x ) (2) + … + na n ( x ) (n – 1) (7.15) are very similar to differentiation of x and x . we take the first difference of p n ( x ) in (7.Chapter 7 Finite Differences and Interpolation It is interesting to observe that the first difference in (7.12) and (7. relation (7.15) n –n –( n ) = –n ( x ) –( n – 1 ) We observe that (7.13) (x) –( n ) These expressions resemble the power functions x and x in elementary algebra.14) (7.11) As with derivatives.14) and (7.2 Factorial Polynomials The factorial polynomials are defined as and (x) (n) = x ( x – 1 ) ( x – 2 )… ( x – n + 1 ) 1 = --------------------------------------------------------( x – 1 ) ( x – 2 )… ( x + n ) n –n (7. we can express that polynomial as pn ( x ) = a0 + a1 ( x ) (1) + a2 ( x ) (2) + … + an ( x ) (n) (7. in analogy with Maclaurin power series. is the difference quotient whose limit defines the derivative of a continuous function that is defined as Δx → 0 lim f ( x 1 + Δx ) – f ( x 1 ) Δy -----. For x = 0 .17) To compute the coefficient a 1 .= lim ------------------------------------------Δx Δx Δx → 0 (7.16) reduces to a0 = pn ( 0 ) (7.16) and now our task is to compute the coefficients a k .12) (7. we find that 7−6 Numerical Analysis Using MATLAB® and Excel®. it is desirable to express a polynomial p n ( x ) as a factorial polynomial. Occasionally. the nth differences of a polynomial of degree n are constant.13) we obtain and Δ(x) Δ(x) (n) = n(x) (n – 1) (7. Then. 7. Using (7.

(7.21) In general. Then.20) and for x = 0 .25). Then. n j! j 2 (7.16) by x to obtain a quotient q 0 ( x ) and a remainder r 0 which turns out to be the constant term a 0 . With this method we perform the following steps: 1.22) Factorial polynomials provide an easier method of constructing a difference table. 1.16). …. we express (7.Factorial Polynomials a 1 = Δp n ( 0 ) (7. Third Edition Copyright © Orchard Publications 7−7 .23).25) 3.27) Numerical Analysis Using MATLAB® and Excel®. we obtain p n ( x ) = r 0 + x [ r 1 + ( x – 1 )q 1 ( x ) ] = r 0 + r 1 ( x ) (1) + x ( x – 1 )q 1 ( x ) (7. We divide p n ( x ) in (7.for j = 0. Δ pn ( 0 ) Δ pn ( 0 ) a 2 = ------------------. We divide q 1 ( x ) in (7. q 0 ( x ) = r 1 + ( x – 1 )q 1 ( x ) (7. and thus q 1 ( x ) = r 2 + ( x – 2 )q 2 ( x ) (7. We divide q 0 ( x ) in (7.19) (n – 2) Differencing again we obtain Δ p n ( x ) = 2 ⋅ 1a 2 + 3 ⋅ 2a 3 ( x ) 2 (1) + … + n ( n – 1 )a n ( x ) 2 (7.25) by ( x – 2 ) to obtain a quotient q 2 ( x ) and a remainder r 2 which turns out to be the constant term a 2 .24) By substitution of (7.23) 2. and using the form of relation (7.23) by ( x – 1 ) to obtain a quotient q 1 ( x ) and a remainder r 1 which turns out to be the constant term a 1 .16) as p n ( x ) = r 0 + xq 0 ( x ) (7. 2.26) into (7.= ------------------2⋅1 2! Δ pn ( 0 ) a j = -----------------.24) into (7.26) By substitution of (7. we obtain pn ( x ) = r0 + r1 ( x ) = r0 + r1 ( x ) (1) (1) + x ( x – 1 ) [ r 2 + ( x – 2 )q 2 ( x ) ] + r2 ( x ) (2) + x ( x – 1 ) ( x – 2 )q 2 ( x ) (7.

Third Edition Copyright © Orchard Publications . r 2.d1) d2=[1 −2]. we must evaluate the remainders r 0. [q3.29) (7. The general form of a factorial polynomial is pn ( x ) = r0 + r1 ( x ) (1) + r2 ( x ) (2) + … + rn – 1 ( x ) j (n – 1) + rn ( x ) (n) (7. x−4 % Computation of fifth (last) quotient and remainder q0 = 7−8 Numerical Analysis Using MATLAB® and Excel®. Δ pn ( 0 ) r j = a j = -----------------j! (7. construct the difference table with h = 1 . i. [q4. The MATLAB script is as follows: px=[1 −5 0 3 4]. i.16) and (7.e.30) or Δ p n ( 0 ) = j!r j j Example 7. Then. x % Computation of first quotient and remainder % Coefficients of second divisor. x−2 % Computation of third quotient and remainder % Coefficients of fourth divisor.r0]=deconv(px.28) and from (7.r4]=deconv(q3. x−3 % Computation of fourth quotient and remainder % Coefficients of fifth (last) divisor.d4) % Coefficients of given polynomial % Coefficients of first divisor.22).e.d3) d4=[1 −4]. we obtain a new quotient whose degree is one less than preceding quotient and therefore.e.d0) d1=[1 −1]. r 1. [q0.28) to determine p n ( x ) . i.3 Express the algebraic polynomial p ( x ) = x – 5x + 3x + 4 4 3 (7. [q2. i.r3]=deconv(q2. x−1 % Computation of second quotient and remainder % Coefficients of third divisor. Solution: Since the highest power of the given polynomial p ( x ) is 4 .r2]=deconv(q1. i. r 3 and r 4 . we will use the MATLAB deconv(p.31) as a factorial polynomial. the process of finding new quotients and remainders terminates after ( n + 1 ) steps.e. then. We can compute the remainders by long division. but for convenience.Chapter 7 Finite Differences and Interpolation Continuing with the above procedure.d2) d3=[1 −3]. we will use (7.r1]=deconv(q0.q) function which divides the polynomial p by q. d0=[1 0].e. [q1.

32) We can verify that (7. For this example.31). the factorial polynomial is pn ( x ) = 4 – ( x ) (1) (2) (3) (4) -5 0 -4 0 -2 0 0 0 -4 0 3 0 4 -1 -8 1 – 8(x) + (x) + (x) (7.32).32) is the same polynomial as (7. We will now compute the leading entries for the difference table using (7. with reference to (7. where ‘s_expr’ is a symbolic expression. the MATLAB script is syms x.28). This can be easily done with the MATLAB collect(‘s_expr’) function. px=collect((x*(x−1)*(x−2)*(x−3))+(x*(x−1)*(x−2))−(8*x*(x−1))−x+4) px = x^4-5*x^3+3*x+4 We observe that this is the same algebraic polynomial as in (7.30) and (7.Factorial Polynomials 1 r0 = 0 q1 = 1 r1 = 0 q2 = 1 r2 = 0 q3 = 1 r3 = 0 q4 = 0 r4 = 1 Therefore.31). by expansion of the factorials using (7. Third Edition Copyright © Orchard Publications 7−9 . Numerical Analysis Using MATLAB® and Excel®.12). Then.

2.Chapter 7 Finite Differences and Interpolation Δ p ( 0 ) = 0! ⋅ 4 = 4 Δ p ( 0 ) = 1! ⋅ ( – 1 ) = – 1 Δ p ( 0 ) = 2! ⋅ ( – 8 ) = – 16 Δ p ( 0 ) = 3! ⋅ 1 = 6 Δ p ( 0 ) = 4! ⋅ 1 = 24 Δ p ( 0 ) = 5! ⋅ 0 = 0 5 4 3 2 1 0 (7. We obtain the next set of values by crisscross addition as shown in Table 7.33) in table form x p(x) 4 Δ −1 Δ 2 Δ 3 Δ 4 Δ 5 −16 6 24 0 TABLE 7. TABLE 7.33) 1. Third Edition Copyright © Orchard Publications .8. 3.6 Leading entries of (7. We enter the values of (7. The second crisscross addition extends the difference table as shown in Table 7.33) in the appropriate spaces as shown in Table 7.7.6.7 Crisscross addition to find second set of values x p(x) 4 Δ Δ 2 Δ 3 Δ 4 Δ 5 −1 3 −16 −17 −10 30 24 6 24 0 7−10 Numerical Analysis Using MATLAB® and Excel®.

Continuation of this procedure produces the complete difference table. TABLE 7.8 Second crisscross addition to find third set of values x p(x) 4 Δ Δ 2 Δ 3 Δ 4 Δ 5 −1 3 −16 −17 6 −14 −27 −10 30 20 54 24 0 24 4. This is shown in Table 7.9.3 x p(x) 4 Δ Δ 2 Δ 3 Δ 4 Δ 5 −1 3 −16 −17 6 −14 −27 −41 −7 −48 67 19 −10 30 20 54 74 24 0 24 Numerical Analysis Using MATLAB® and Excel®.Factorial Polynomials TABLE 7. Third Edition Copyright © Orchard Publications 7−11 .9 Complete difference table for Example 7.

3 Antidifferences We recall from elementary calculus that when we know the first derivative of a function. we can find the antidifference of a factorial polynomial. in finite differences we have the definite sum of p n ( x ) which for the interval a ≤ x ≤ a + ( n – 1 )h is denoted as α + ( n – 1 )h x=α ∑ p n ( x ) = p n ( α ) + p n ( α + h ) + p n ( α + 2h ) + … + p n [ α + ( n – 1 )h ] (7. By a similar method. we need to review the definite sum and the fundamental theorem of sum calculus.Chapter 7 Finite Differences and Interpolation 7.+ 4 ( x ) + C 3 5 4 2 (5) (4) (3) (2) (7. its antidifference is (x) –1 (1) (x) (x) (x) Δ p n ( x ) = -----------. Antidifferences are very useful in finding sums of series.34) Example 7.4 Compute the antidifference of the algebraic polynomial p ( x ) = x – 5x + 3x + 4 4 3 (7. in analogy with the fundamental theorem of integral calculus which states that 7−12 Numerical Analysis Using MATLAB® and Excel®.35) Solution: This is the same algebraic polynomial as that of the previous example.– ------------. Third Edition Copyright © Orchard Publications . In analogy with definite integrals for continuous functions. where we found that the corresponding factorial polynomial is pn ( x ) = 4 – ( x ) (1) – 8(x) (2) + (x) (3) + (x) (4) (7. We denote the antidifference as Δ p n ( x ) .36) Then.+ -----------. These are discussed below.– 8 ------------. Before we present an example. It is computed from Δ (x) –1 –1 (n) (x) = -------------------(n + 1) (n + 1) (7. by (7.37) where C is an arbitrary constant.34). we can integrate or antidifferentiate to find the function.38) Also.

Antidifferences

∫a f ( x ) dx

α + ( n – 1 )h

b

= f(b) – f(a )

(7.39)

we have the fundamental theorem of sum calculus which states that

∑ x=α

pn ( x ) = Δ pn ( x )

–1

α + nh α

(7.40)

Example 7.5 Derive a simple expression, in closed form, that computes the sum of the cubes of the first n odd integers. Solution: An odd number can be expressed as 2m – 1 , and thus its cube is ( 2m – 1 ) . To use (7.40), we must express this term as a factorial polynomial. Recalling from (7.12) that

(x)

(n)

3

= x ( x – 1 ) ( x – 2 )… ( x – n + 1 )

(7.41)

**and using the MATLAB expand(f) function where f is a symbolic expression, we execute
**

syms m; f = (2*m−1)^3; expand(f)

**and we obtain ans = 8*m^3-12*m^2+6*m-1 Thus
**

p ( m ) = ( 2m – 1 ) = 8m – 12m + 6m – 1

3 3 2

(7.42)

**Following the procedure of Example 7.3, we find p n ( m ) with MATLAB as
**

pm=[8 −12 6 −1]; d0=[1 0]; [q0,r0]=deconv(pm,d0) d1=[1 −1]; [q1,r1]=deconv(q0,d1) d2=[1 −2]; [q2,r2]=deconv(q1,d2) d3=[1 −3]; [q3,r3]=deconv(q2,d3)

q0 = 8 -12 6

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

7−13

**Chapter 7 Finite Differences and Interpolation
**

r0 = 0 q1 = 8 r1 = 0 q2 = 8 r2 = 0 q3 = 0 r3 = 8 Therefore,

pn ( m ) = 8 ( m )

(3)

0 -4 0

0

-1

2

12

+ 12 ( m )

(2)

+ 2(m)

(1)

–1

(7.43)

**Taking the antidifference of (7.43) we obtain
**

–1 (1) Δ p n ( m ) = 8 ( m ) + 12 ( m ) + 2 ( m ) – ( m ) ------------------ --------------------- -----------------4 3 2 (4) (3) (2)

(7.44)

= 2(m)

(4)

+ 4(m)

(3)

+ (m)

(2)

– (m)

(1)

and with (7.40)

∑

Since

cubes = 2 ( m )

(4)

+ 4(m)

(3)

+ (m)

(2)

– (m)

(1)

n+1 m=1

= 2 ( n + 1 )n ( n – 1 ) ( n – 2 ) + 4 ( n + 1 )n ( n – 1 ) + ( n + 1 )n – ( n + 1 ) –2 ( 1 )

(4)

(7.45)

–4 ( 1 )

(4) (3) (2) (1)

(3)

– (1)

(2)

+ (1)

(1)

(1) (1) (1) (1)

= 1(1 – 1)(1 – 2 )(1 – 3 ) = 0 = 1(1 – 1)(1 – 2 ) = 0 = 1(1 – 1) = 0 = 1

(7.46)

relation (7.45) reduces to

∑ cubes

7−14

= 2 ( n + 1 )n ( n – 1 ) ( n – 2 ) + 4 ( n + 1 )n ( n – 1 ) + ( n + 1 )n – ( n + 1 ) + 1

(7.47)

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Newton’s Divided Difference Interpolation Method
**

and this can be simplified with the MATLAB collect(f) function as follows.

syms n; sum=collect(2*(n+1)*n*(n−1)*(n−2)+4*(n+1)*n*(n−1)+(n+1)*n−(n+1)+1)

sum = 2*n^4-n^2 that is,

∑ cubes

= 2n – n = n ( 2n – 1 )

4

2

2

2

(7.48)

We can verify that this is the correct expression by considering the first 4 odd integers 1, 3, 5, and 7 . The sum of their cubes is

1 + 27 + 125 + 343 = 496

**This is verified with (7.48) since
**

n ( 2n – 1 ) = 4 ( 2 ⋅ 4 – 1 ) = 16 ⋅ 31 = 496

2 2 2 2

One important application of finite differences is interpolation. Newton’s divided−difference interpolation method, Lagrange’s interpolation method, Gregory−Newton forward, and Gregory− Newton backward interpolation methods are discussed in Sections 7.4 through 7.7 below. We will use spreadsheets to facilitate the computations. Interpolation using MATLAB is discussed in Section 7.8 below.

**7.4 Newton’s Divided Difference Interpolation Method
**

This method, has the advantage that the values x 0, x 1, x 2, …, x n need not be equally spaced, or taken in consecutive order. It uses the formula

f ( x ) = f ( x 0 ) + ( x – x 0 ) f ( x 0, x 1 ) + ( x – x 0 ) ( x – x 1 ) f ( x 0, x 1, x 2 ) + ( x – x 0 ) ( x – x 1 ) ( x – x 2 ) f ( x 0, x 1, x 2, x 3 )

(7.49)

where f ( x 0, x 1 ) , f ( x 0, x 1, x 2 ) , and f ( x 0, x 1, x 2, x 3 ) are the first, second, and third divided differences respectively. Example 7.6 Use Newton’s divided−difference method to compute f ( 2 ) from the experimental data shown in Table 7.10.

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

7−15

**Chapter 7 Finite Differences and Interpolation
**

TABLE 7.10 Data for Example 7.6 x y = f (x) −1.0 3.0 0.0 −2.0 0.5 −0.375 1.0 3.0 2.5 16.125 3.0 19.0

Solution: We must compute the first, second, and third divided differences as required by (7.49). The first divided differences are:

– 2.000 – 3.000 ------------------------------------ = – 5.000 0 – ( – 1.0 ) – 0.375 – ( – 2.000 ) = 3.250 -------------------------------------------0.5 – 0.0 3.000 – ( – 0.375 ) ---------------------------------------- = 6.750 1.0 – 0.5 16.125 – 3.000 ----------------------------------- = 8.750 2.5 – 1.0 19.000 – 16.125 = 5.750 -------------------------------------3.0 – 2.5

(7.50)

**The second divided differences are:
**

3.250 – ( – 5.000 ) = 5.500 ---------------------------------------0.5 – ( – 1.0 ) 6.750 – 3.250 -------------------------------- = 3.500 1.0 – 0.0 8.750 – 6.750 = 1.000 -------------------------------2.5 – 0.5 5.750 – 8.750 -------------------------------- = – 1.500 3.0 – 1.0

(7.51)

**and the third divided differences are:
**

3.500 – 5.500 -------------------------------- = – 1.000 1.0 – ( – 1.0 ) 1.000 – 3.500 -------------------------------- = – 1.000 2.5 – 0.0 – 1.500 – 1.000 ------------------------------------ = – 1.000 3.0 – 0.5

(7.52)

With these values, we construct the difference Table 7.11.

7−16

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Lagrange’s Interpolation Method
**

TABLE 7.11 Difference table for Example 7.6

1st Divided Difference 2nd Divided Difference 3rd Divided Difference

x −1.0 0.0 0.5 1.0 2.5 3.0

f (x) 3.000 −2.000

f ( x 0, x 1 ) −5.000

f ( x 0, x 1, x 2 )

f ( x 0, x 1, x 2, x 3 )

5.500 3.250 −1.000 3.500 6.750 −1.000 1.000 8.750 −1.000 −1.500 5.750

−0.375 3.000 16.125 19.000

Now, we have all the data that we need to find f ( 2 ) . We start with x 0 = 0.00 ,* and for x in (7.49), we use x = 2 . Then,

f ( 2 ) = – 2.0 + ( 2 – 0 ) ( 3.250 ) + ( 2 – 0 ) ( 2 – 0.5 ) ( 3.500 ) + ( 2 – 0 ) ( 2 – 0.5 ) ( 2 – 1 ) ( – 1.000 ) = – 2.0 + 6.5 + 10.5 – 3 = 12

This, and other interpolation problems, can also be solved with a spreadsheet. The Excel spreadsheet for this example is shown in Figure 7.1.

**7.5 Lagrange’s Interpolation Method
**

Lagrange’s interpolation method uses the formula

( x – x 1 ) ( x – x 2 )… ( x – x n ) ( x – x 0 ) ( x – x 2 )… ( x – x n ) f ( x ) = ----------------------------------------------------------------------- f ( x 0 ) + ----------------------------------------------------------------------- f ( x 1 ) ( x 0 – x 1 ) ( x 0 – x 2 )… ( x 0 – x n ) ( x 1 – x 0 ) ( x 1 – x 2 )… ( x 1 – x n ) ( x – x 0 ) ( x – x 1 )… ( x – x n – 1 ) + ----------------------------------------------------------------------------- f ( x n ) ( x n – x 0 ) ( x n – x 2 )… ( x n – x n – 1 )

(7.53)

and, like Newton’s divided difference method, has the advantage that the values x 0, x 1, x 2, …, x n need not be equally spaced or taken in consecutive order.

* We chose this as our starting value so that f ( 2 ) will be between f ( 1 ) and f ( 2.5 )

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

7−17

Chapter 7 Finite Differences and Interpolation

Interpolation with Newton's Divided Difference Formula f(x) = f(x0)+(x-x0)f(x0,x1)+(x-x0)(x-x1)f(x0,x1,x2)+(x-x0)(x-x1)(x-x2)f(x0,x1,x2,x3) In this example, w e w ant to evaluate f(x) at x= 2 1st divided difference x -1.00 f(x) 3.000 -5.000 0.00 -2.000 3.250 0.50 -0.375 6.750 1.00 3.000 8.750 2.50 16.125 5.750 3.00 19.000 We use the above formula w ith starting value x0.00 f(2)=B12+(E3-E18)*C13+(E3-E18)*(E3-A14)*D14+(E3-E18)*(E3-A14)*(E3-A16)*E15 or f(2)= 12.00 The plot below verifies that our answ er is correct -1.000 3.000

20 15

2nd divided 3rd divided difference f(x0, x1, x2) difference f(x0,x1,x2,x3)

f(x0, x1)

5.500 -1.000 3.500 -1.000 1.000 -1.000 -1.500

0.000 -2.000 f(x) 0.500 -0.375 1.000 3.000 2.500 16.125 3.000 19.000

10 5 0 -5 -1.0 0.0 1.0 2.0 3.0

x

Figure 7.1. Spreadsheet for Example 7.6

Example 7.7 Repeat Example 7.6 using Lagrange’s interpolation formula. Solution: All computations appear in the spreadsheet of Figure 7.2 where we have used relation (7.53).

7−18

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Gregory−Newton Forward Interpolation Method
**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 A B C

2 f(x) 3.000 -2.000 -0.375 3.000 16.125 19.000 x-x1 2.000 x0-x1 -1.000 x-x0 3.000 x1-x0 1.000 x-x0 3.000 x2-x0 1.500 x-x0 3.000 x3-x0 2.000 x-x0 3.000 x4-x0 3.500 x-x0 3.000 x5-x0 4.000 x-x2 1.500 x0-x2 -1.500 x-x2 1.500 x1-x2 -0.500 x-x1 2.000 x2-x1 0.500 x-x1 2.000 x3-x1 1.000 x-x1 2.000 x4-x1 2.500 x-x1 2.000 x5-x1 3.000 x-x3 1.000 x0-x3 -2.000 x-x3 1.000 x1-x3 -1.000 x-x3 1.000 x2-x3 -0.500 x-x2 1.500 x3-x2 0.500 x-x2 1.500 x4-x2 2.000 x-x2 1.500 x5-x2 2.500 x-x4 -0.500 x0-x4 -3.500 x-x4 -0.500 x1-x4 -2.500 x-x4 -0.500 x2-x4 -2.000 x-x4 -0.500 x3-x4 -1.500 x-x3 1.000 x4-x3 1.500 x-x3 1.000 x5-x3 2.000 x-x5 -1.000 x0-x5 -4.000 x-x5 -1.000 x1-x5 -3.000 x-x5 -1.000 x2-x5 -2.500 x-x5 -1.000 x3-x5 -2.000 x-x5 -1.000 x4-x5 -0.500 x-x4 -0.500 x5-x4 0.500 f(x0) 3.000

D

E

F

G

H

I

J

Numer. Partial Prods 4.500

K

Denom. Partial Prods

L

Division of Partial Prods

Lagrange's Interpolation Method Interpol. at x= x -1.00 0.00 0.50 1.00 2.50 3.00

x0 x1 x2 x3 x4 x5

-0.107 -42.000 f(x1) -2.000 -4.500 -1.200 3.750 f(x2) -0.375 -1.125 0.600 -1.875 f(x3) 3.000 13.500 4.500 3.000 f(x4) 16.125 -145.125 11.057 -13.125 f(x5) 19.000 -85.500 -2.850 30.000 f(2)= Sum= 12

Figure 7.2. Spreadsheet for Example 7.7

**7.6 Gregory−Newton Forward Interpolation Method
**

This method uses the formula

r(r – 1) 2 r( r – 1 )( r – 2) 3 f ( x ) = f 0 + rΔf 0 + ----------------- Δ f 0 + --------------------------------- Δ f 0 + … 2! 3!

2 3

(7.54)

where f 0 is the first value of the data set, Δf 0 , Δ f 0 , and Δ f 0 are the first, second, and third forward* differences respectively. The variable r is the difference between an unknown point x and a known point x 1 divided by the interval h , that is,

( x – x1 ) r = -----------------h

(7.55)

* This is an expression to indicate that we use the differences in a forward sequence, that is, the first entries on the columns

where the differences appear.

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

7−19

**Chapter 7 Finite Differences and Interpolation
**

The formula of (7.54) is valid only when the values x 0, x 1, x 2, …, x n are equally spaced with interval h . It is used to interpolate values near the smaller values of x , that is, the values near the beginning of the given data set. The formula that we will study on the next section, is used to interpolate values near the larger values of x , that is, the values near the end of the given data set. Example 7.8 Use the Gregory−Newton forward interpolation formula to compute f ( 1.03 ) from the following data.

TABLE 7.12 Table for Example 7.8 x y = f (x) 1.00 1.000000 1.05 1.257625 1.10 1.531000 1.15 1.820875 1.20 2.128000 1.25 2.453125

Solution: We enter the given x and f ( x ) values in a difference table; then, we compute the first, second, and third differences. These are not divided differences and therefore, we simply subtract the second value of f ( x ) from the first, the third from the second, and so on, as shown in Table 7.13. For this example,

f 0 = f ( 1.00 ) = 1.000000 h = x 1 – x 0 = 1.05 – 1.00 = 0.05 x – x1 1.03 – 1.00 r = ------------- = -------------------------- = 0.60 h 0.05

(7.56)

**and with the values shown in Table 7.13 and using (7.54), we obtain
**

( 0.60 ) ⋅ ( 0.60 – 1 ) f ( 1.03 ) = 1.000000 + ( 0.60 ) ⋅ ( 0.257625 ) + ------------------------------------------2! ( 0.60 ) ⋅ ( 0.60 – 1 ) ( 0.60 – 2 ) + -------------------------------------------------------------------- ⋅ ( 0.000750 ) = 1.152727 3!

(7.57)

The spreadsheet of Figure 7.3 shows the layout and computations for this example.

7−20

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Gregory−Newton Backward Interpolation Method
**

TABLE 7.13 Difference table for Example 7.8 1st Difference x 1.00 1.05 1.10 1.15 1.20 1.25 f (x) 1.000000 1.257625 0.273375 1.531000 0.289875 1.820875 0.307125 2.128000 0.325125 2.453125 0.018000 0.017250 0.000750 0.016500 0.000750 f ( x 0, x 1 ) 0.257625 0.015750 0.000750 2nd Difference f ( x 0, x 1, x 2 ) 3rd Difference f ( x 0, x 1, x 2, x 3 )

**7.7 Gregory−Newton Backward Interpolation Method
**

This method uses the formula

r(r + 1) 2 r(r + 1 )(r + 2 ) 3 f ( x ) = f 0 + rΔf – 1 + ----------------- Δ f – 2 + ---------------------------------- Δ f – 3 + … 2! 3!

2 3

(7.58)

where f 0 is the first value of the data set, Δf –1 , Δ f –2 , and Δ f –3 are the first, second and third backward differences, and

( x – x1 ) r = -----------------h

**Expression (7.58) is valid only when the values x 0, x 1, x 2, …, x n are equally spaced with interval
**

h . It is used to interpolate values near the end of the data set, that is, the larger values of x .

Backward interpolation is an expression to indicate that we use the differences in a backward sequence, that is, the last entries on the columns where the differences appear. Example 7.9 Use the Gregory−Newton backward interpolation formula to compute f ( 1.18 ) from the data set of Table 7.14.

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

7−21

**Chapter 7 Finite Differences and Interpolation
**

Gregory-Newton Forward Interpolation Method See expressions (7.54) and (7.55) Interpolate f(x) at x= x f(x) Δf 0.257625 1.05 1.257625 0.273375 1.10 1.531000 0.289875 1.15 1.820875 0.307125 1.20 2.128000 0.325125 1.25 2.453125 h= A10-A8= 0.05 0.6 r= (D5-A8)/C20= 0.018000 0.017250 0.000750 0.016500 0.000750 0.015750 0.000750 1.03 Δ 2f Δ 3f

1.00 1.000000

f(1.12)= B8+F20*C9+(F20*(F20-1)*D10)/FACT(2)+(F20*(F20-1)*(F20-2)*E11)/FACT(3) = 1.152727 1.00 1.000000 1.05 1.257625 1.10 1.531000 1.15 1.820875 1.20 2.128000 1.25 2.453125 3.00 2.50 2.00 1.50 1.00 0.50 0.00 1.00 1.05 1.10 1.15 1.20 1.25

Figure 7.3. Spreadsheet for Example 7.8 TABLE 7.14 Data for Example 7.9 x y = f (x) 1.00 1.000000 1.05 1.257625 1.10 1.531000 1.15 1.820875 1.20 2.128000 1.25 2.453125

7−22

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Gregory−Newton Backward Interpolation Method
**

Solution: We arbitrarily choose f 0 = 2.128000 as our starting point since f ( 1.18 ) lies between f ( 1.15 ) and

f ( 1.20 ) . Then, h = 1.20 – 1.15 = 0.05

and

r = ( x – x 1 ) ⁄ h = ( 1.18 – 1.20 ) ⁄ 0.05 = – 0.4

Now, by (7.58) we have:

( – 0.4 ) ( – 0.4 + 1 ) f ( 1.18 ) = 2.128 + ( – 0.4 ) ( 0.307125 ) + ----------------------------------------- ( 0.01725 ) 2! ( – 0.4 ) ( – 0.4 + 1 ) ( – 0.4 + 2 ) + -------------------------------------------------------------------- ( 0.00075 ) = 2.003032 3!

The computations were made with the spreadsheet of Figure 7.4. If the increments in x values are small, we can use the Excel VLOOKUP function to perform interpolation. The syntax of this function is as follows.

VLOOKUP(lookup_value, table_array, col_index_num, range lookup)

where:

lookup_value is the value being searched in the first column of the lookup table table_array are the columns forming a rectangular range or array col_index_num is the column where the answer will be found range lookup is a logical value (TRUE or FALSE) that specifies whether we require VLOOKUP to find an exact or an approximate match. If TRUE is omitted, an approximate match is returned.

In other words, if an exact match is not found, the next largest value that is less than the lookup_value is returned. If FALSE is specified, VLOOKUP will attempt to find an exact match, and if one is not found, the error value #N/A will be returned.

A sample spreadsheet is shown in Figure 7.5 where the values of x extend from −5 to +5 volts. Only a partial table is shown.

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

7−23

**Chapter 7 Finite Differences and Interpolation
**

Gregory-New ton Backw ard Interpolation Method See form ula 7.58 Interpolate f(x) at x= 1.18 x 1.00 1.05 1.10 1.15 1.20 f(x) 1.000000 0.257625 1.257625 0.273375 1.531000 0.289875 1.820875 0.307125 2.128000 0.05 r= (C5-A16)/C18= -0.4 0.017250 0.016500 0.000750 0.015750 0.000750 Δf Δ 2f Δ 3f

h= A16-A14=

f(1.18)= B16+F18*C15+(F18*(F18+1)*D14)/FACT(2)+(F18*(F18+1)*(F18+2)*E13)/FACT(3) = 1.00 1.05 1.10 1.15 1.20 2.003032 2.500 1.000000 2.000 1.257625 1.531000 1.820875 2.128000 1.500 1.000 0.500 0.000 1.00

1.05

1.10

1.15

1.20

Figure 7.4. Spreadsheet for Example 7.9

**7.8 Interpolation with MATLAB
**

MATLAB has several functions that perform interpolation of data. We will study the following: 1. interp1(x,y,xi) performs one dimensional interpolation where x and y are related as y = f(x) and xi is some value for which we want to find y(xi) by linear interpolation, i.e., “table lookup”. This command will search the x vector to find two consecutive entries between which the desired value falls. It then performs linear interpolation to find the corresponding value of y. To obtain a correct result, the components of the x vector must be monotonic, that is, either in ascending or descending order.

7−24

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

nearest − nearest neighbor interpolation linear − linear interpolation.0330 -1.y.FALSE) = A 264 265 4.y. 4.000 -0.900 -0.xi.05 0.0299 -1.8375.’method’) but performs two dimensional interpolation.750 -0. interp2(x.00 -0.5. Third Edition Copyright © Orchard Publications 7−25 .A2:B282.0302 -1. interp1(x.yi.A2:B282.5535.775 -0.y. The spline method does not apply to two dimensional interpolation.975 -0.0270 -1.1484323 0.2) = 0. this does also extrapolation cubic − cubic interpolation.030927 #N/A =VLOOKUP(-1.z.925 -0.8375.xi.0320 -1.’method’) performs the same operation as interp1(x.2) = =VLOOKUP(-1. We will illustrate the applications of these functions with the examples below.0263 A 8 9 B -1.y.05 -2 -1 0 1 2 3 4 5 -2.0313 -1.0316 -1.0277 -1.A2:B282.1484323 Figure 7.xi.0323 -1. The default is linear.xi.0306 -1.0292 -1.8375.550 -0. Numerical Analysis Using MATLAB® and Excel®.xi) but performs two dimensional interpolation.575 -0.700 -0.xi) where the string method allows us to specify one of the methods listed below.725 -0.675 -0.y.Interpolation with MATLAB V I 0.A2:B282.950 -0.2. Using the Excel VLOOKUP function for interpolation 2.’method’) is similar to interp1(x.0288 -1.z.850 -0.10 0.1496775 =VLOOKUP(4. this is the default interpolation spline − cubic spline interpolation.15 0. this requires equidistant values of x 3.800 -0.600 -0.0267 -1.825 -0.0274 -1.0285 -1.TRUE) = =VLOOKUP(-1.8500 -0. interp2(x.650 -0.0309 -1.y.875 -0.2.0309266 -1.625 -0.5500 4.5750 B 0.8250 -0.0281 -1.0326 -1.0295 -1.yi) is similar to interp1(x.20 0.0305803 -0.030927 -0.525 -0.

% We use "a" for current instead of "i" to avoid conflict % with imaginary numbers v_a=[v. voltage (volts) % for a diode whose v−i characteristics are i=0.1 ( e 0.2v)−1).xi) command to interpolate at the desired value. last_value. grid.a.0297 -0. title('volt−ampere characteristics for a junction diode'). % Specify 30 intervals in the −2<=v<=5 interval a=0.a]'.0000 -1. ylabel('current (milliamps)'). % Define "v_a" as a two−column matrix to display volts % and amperes side−by−side.0262 -0. we will use the MATLAB linspace(first_value. 5. Compute i for 30 data points of v within the interval – ( 2 ≤ v ≤ 5 ) . xlabel('voltage (volts)').1(exp(0.1. % Heading of the two−column matrix fprintf(' \n').m % It computes the values of current (in milliamps) vs.0330 -0.2v ( t ) – 1) (7. % This script is for Example_7_10. fprintf(' volts milliamps \n'). plot i versus v in this range. we use the interp1(x.2759 milliamps -0. % Linear (default) interpolation fprintf('current (in milliamps) @ v=1.y.2 . ma) The data and the value obtained by interpolation are shown below. plot(v. and plots the data for this range. number_of_values) command.* (exp(0. The script below produces 30 values in volts.7586 -1. Then. Solution: We are required to use 30 data points within the given range. Third Edition Copyright © Orchard Publications .4f \n'.59) where v is in volts and i in milliamperes.1.a).265 is %2. % v=linspace(−2. and using linear interpolation compute i when v = 1. volts -2.0225 7−26 Numerical Analysis Using MATLAB® and Excel®.265 volts. accordingly. % Display values of volts and amps below the heading ma=interp1(v.* v)−1). % We can use the MATLAB function 'interp1' to linearly interpolate % the value of milliamps for any value of v within the specified interval.Chapter 7 Finite Differences and Interpolation Example 7.265). disp(v_a). the corresponding values in milliamperes.5172 -1.10 The i – v (current−voltage) relation of a non−linear electrical device is given by i ( t ) = 0. 30).

0035 0.1241 0.5172 4.1468 0.2759 4.0760 0.0383 0.6.0086 0.4138 0.5517 -0.1718 current (in milliamps) @ v=1.3793 1.7586 5.1724 0.0345 4.1590 0. Numerical Analysis Using MATLAB® and Excel®.0523 0.0196 0.0187 -0.5862 2.1379 1.0104 -0.3103 -0.0140 0.0690 0.265 is 0.1035 0.0598 0.1135 0.5517 3.3448 2.7931 -0.3103 3.0847 0.0677 0.0060 -0.0318 0.8966 1.8621 2.0345 -0.1034 2.0451 0. Third Edition Copyright © Orchard Publications 7−27 .0000 -0.0939 0.0147 -0.Interpolation with MATLAB -1.0256 0.6207 1.1352 0.0690 3.6552 0.0288 The plot for this example is shown in Figure 7.7931 4.0014 0.8276 3.

Third Edition Copyright © Orchard Publications . % statements for the plot % analytic=(cos([pi/8 pi/4 3*pi/5 3*pi/7]'). % plot(x. ylabel('y').^ 5). π ⁄ 4 .Chapter 7 Finite Differences and Interpolation 0.y. and 3π ⁄ 7 . 'linear').60) and produces the values of analytical values. for comparison with the linear.05 -2 0 2 voltage (volts) 4 6 Figure 7. and spline methods.2*pi.y. % The label 'linear' on the right side of the above statement % could be have been omitted since the default is linear % cubic_int=interp1(x. Plot for Example 7.[pi/8 pi/4 3*pi/5 3*pi/7]'. with the analytical values. cubic. grid.6.1 0. % linear_int=interp1(x. % We need these two y=(cos(x)) . and spline interpolation methods.05 0 -0.10 Example 7.y.[pi/8 pi/4 3*pi/5 3*pi/7]'.15 current (milliamps) 0.y). Compare the values obtained with the linear. % This is the script for Example_7_11 % x=linspace(0.60) in the interval 0 ≤ x ≤ 2π with 120 inte rme diate values. Solution: The script below plots (7.2 volt-ampere characteristics for a junction diode 0. title('y=cos^5(x)'). use the MATLAB interp1(x.120).11 Plot the function y = f ( x ) = cos 5x (7.^ 5. 7−28 Numerical Analysis Using MATLAB® and Excel®. cubic.’method’) function to interpolate at π ⁄ 8 .xi. Then. xlabel('x'). 'cubic'). 3π ⁄ 5 .

3). % 1st column of matrix y(:.y.5f\t %8. % % The statements below compute the percent error for the three % interpolation methods as compared with the exact (analytic) values % error1=(linear_int−analytic). Numerical Analysis Using MATLAB® and Excel®.5f\t %8.*100 .1)=analytic. error2=(cubic_int−analytic).5f\n'.1)=error1./ analytic.3)=cubic_int. % 3rd column of matrix y(:.'spline').Interpolation with MATLAB % spline_int=interp1(x.5f\t %8.y') fprintf(' \n'). % 2nd column of matrix y(:. % Construct a 4 x 3 matrix of zeros z(:.5f\t %8.2)=linear_int.4)=spline_int.*100 . % 4th column of matrix fprintf(' \n'). Third Edition Copyright © Orchard Publications 7−29 .*100 ./ analytic. fprintf('%8. The plot for the function of this example is shown in Figure 7.2)=error2. % Insert line disp('The percent errors for each interpolation method are:') fprintf(' \n').5f\t %8.[pi/8 pi/4 3*pi/5 3*pi/7]'. % 3rd column of matrix % fprintf(' \n').5f\n'.3)=error3. % y=zeros(4.7. fprintf('%8. fprintf('Linear Int \t Cubic Int \t Spline Int \n') fprintf(' \n'). error3=(spline_int−analytic). % Insert line fprintf('Analytic \t Linear Int \t Cubic Int \t Spline Int \n') fprintf(' \n'). % 2nd column of matrix z(:. % 1st column of matrix z(:.% Construct a 4 x 4 matrix of zeros y(:./ analytic.4).z') fprintf(' \n'). % z=zeros(4.

2 -0.00055 Linear Int 0.00282 0.27678 Example 7.64706 Spline Int 0.17678 -0.05211 0.7 in Chapter 1 whose script and plot are shown below.67310 0.6 0. Plot the function of Example 7. Solution: % The file is Example_7_12. use the spline method of interpolation to find the magnitude of the impedance at ω = 792 rad ⁄ s .m % It calculates and plots the impedance Z(w) versus radian frequency w.4 0.8 0.67310 0.11 The analytical and interpolated values are shown below for comparison.17678 -0.40465 -0. Analytic 0.00296 0. Cubic Int 0.01027 -0.22707 5.07445 7−30 Numerical Analysis Using MATLAB® and Excel®.00281 0.00184 -0.00054 Spline Int 0.Chapter 7 Finite Differences and Interpolation 1 0.4 -0.00282 0.00055 The percent errors for each interpolation method are: Linear Int -0.17678 -0. Third Edition Copyright © Orchard Publications .8 -1 y y=cos 5(x) 0 1 2 3 x 4 5 6 Figure 7.67274 0.12 For the impedance example of Section 1.00011 -0.00062 Cubic Int 0.00012 -0.2 0 -0.6 -0.09681 13.00002 0.67311 0.7.17718 -0.

. 103.^6.2).. z=[39.032 187.*10..182 40..513 62.abs(z)') % w=[300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500.*w−10.339 52. semilogx(w.2)=(10+(10.830 266. title('Magnitude of Impedance vs...8.'spline').182 436. grid. % zi=interp1(w.353.481...^5. Third Edition Copyright © Orchard Publications 7−31 .938.468 48.122.603 81. xlabel('w in rads/sec').3f\n'. z=zeros(28.845]. 42. 469. 2400 2500 2600 2700 2800 2900 3000]. Plot for the function of Example 7.8.1)=w'.. ylabel('|Z| in Ohms'). fprintf('%2./(10+j.12 Numerical Analysis Using MATLAB® and Excel®.792./w)))'. Radian Frequency')..088 73.052 145. z(:.286 44..611 51.111 90.1. fprintf(' \n') fprintf('Magnitude of Z at w=792 rad/s is %6.*(0.3f Ohms \n'.104 97.Interpolation with MATLAB % % Use the following five statements to obtain |Z| versus radian frequency w w=300:100:3000.751 120.0f\t %10. z(:.056 1014. zi) fprintf(' \n') The plot for the function of this example is shown in Figure 7..717 46.588 67.789 71. Magnitude of Impedance vs.437 222.665 140.240 54.432 38.^4−j../w). 58.z)..z. 1600 1700 1800 1900 2000 2100 2200 2300. Radian Frequency 1200 1000 800 |Z| in Ohms 600 400 200 0 2 10 10 w in rads/sec 3 10 4 Figure 7.

is R = X +Y 2 2 (7.Y]=meshgrid(x.13 Generate the plot of the function sin R Z = ----------R (7. % Compute distances from origin (0. Third Edition Copyright © Orchard Publications . For convenience. % eps prevents division by zero mesh(X. and the plot in the intervals – 2π ≤ x ≤ 2π and – 2π ≤ y ≤ 2π . Here./ (R+eps).y). X and Y comprise a pair of matrices representing a rectangular grid of points in the x – y plane. y 0 ) = ( 0.y) − Generates interpolation arrays which contain all combinations of the x and y points which we specify. % Create X and Y matrices R=sqrt(X. Then. % Define interval in increments of pi/24 y=x.Chapter 7 Finite Differences and Interpolation MATLAB interpolates the impedance at ω = 792 rad ⁄ s and displays the following message: Magnitude of Z at w=792 rad/s is 217.034 Ohms Two−dimensional plots were briefly discussed in Chapter 1. % y must have same number of points as x [X.Y. we write and execute the following MATLAB script. Y ] matrices that form a rectangular grid of points in the x – y plane. R is a matrix that contains the distances from the origin to each point in the pair of [ X. y ) where z is a matrix. 1. zlabel('z'). mesh(Z) − Plots the values in the matrix Z as height values above a rectangular grid. Solution: The matrix R that contains the distances from the origin to each point in the pair of [ X. 2. % Generate mesh plot for Z=sin(R)/R xlabel('x'). ylabel('y'). 0 ) . Example 7.^ 2 + Y.^ 2).0) to x−y points Z=sin(R).Z). Y ] matrices. % This is the script for Example_7_13 x=−2*pi: pi/24: 2*pi. and connects adjacent points to form a mesh surface. we will review the following commands which can be used for two−dimensional interpolation. y . Using these points. 7−32 Numerical Analysis Using MATLAB® and Excel®. [X.Y]=meshgrid(x.61) in three dimensions x .62) We let the origin be at ( x 0. and z . This function is the equivalent of the function y = sin x ⁄ x in two dimensions. we can form a function z = f ( x.

Then. we write and execute the following script.^3+Y.14').25 y=x. and the plot in the intervals – 10 ≤ x ≤ 10 and – 10 ≤ y ≤ 10 . Plot for Example 7.25: 10. Figure 7.13 Example 7.Z. z_int=interp2(X.Y. % y must have same number of points as x [X. 0 ) .'cubic'). y .9. ylabel('y').y). Third Edition Copyright © Orchard Publications 7−33 .Interpolation with MATLAB title('Plot for the Three−dimensional sin(R) / R Function') The plot for the function of this example is shown in Figure 7. Solution: We let the origin be at ( x 0.*X. Use the cubic method to interpolate the value of z at x = – 1 and y = 2 . zlabel('z'). fprintf(' \n') Numerical Analysis Using MATLAB® and Excel®.9.2.*Y.63) in three dimensions x . % Generate mesh plot xlabel('x'). y 0 ) = ( 0. % Define interval in increments of 0. % Create X and Y matrices Z=X. and z . mesh(X.Z). title('Plot for the Function of Example 7.^3−3.Y.Y]=meshgrid(x. % This is the script for Example_7_14 x=−10: 0.14 Generate the plot of the function z = x + y – 3xy 3 3 (7. −1.

13 500.05 500.11 500.17 500.13 500.17 500.14 500.14 500.05 500.13 500.2f \n'.17 500.15 500.13 500.12 500.15 500.21 500.12 500.15 500.Chapter 7 Finite Differences and Interpolation fprintf('Interpolated Value of z at x = −1 and y = 2 is z = %4.15 500.17 500.18 500.17 500.09 500.08 500.15 500.18 500.13 500.02 500.10. 500.10.17 This rectangular land parcel is 175 meters wide and 275 meters deep.09 500.17 500. 7−34 Numerical Analysis Using MATLAB® and Excel®.10 500.15 500.14 500.z_int) fprintf(' \n') The plot for the function of this example is shown in Figure 7.14 500.15 500.08 500.02 500.14 500.14 500.12 500.17 500.14 500.13 500. Plot for Example 7.13 500.15 500.03 500.16 500.02 500.17 500.09 500.12 500.11 500.16 500.18 500.15 500.11 500.14 Interpolated Value of z at x = -1 and y = 2 is z = 13.09 500.11 500.13 500.08 500.15 500.12 500.01 500.12 500.18 500.16 500.08 500.02 500.09 500.05 500.09 500.08 500.10 500.14 500.14 500.15 A land surveyor measured and recorded the data below for a rectangular undeveloped land which lies approximately 500 meters above sea level.01 500. Third Edition Copyright © Orchard Publications .16 500.19 500.13 500.09 500.14 500.14 500.14 500.01 500.11 500.11 500.12 500.11 500.19 500.12 500. Figure 7.12 500.11 500.09 500. The measurements shown above were made at points 25 meters apart.09 500.00 Example 7.12 500.

% Forms grid of all combinations of xi and yi Numerical Analysis Using MATLAB® and Excel®.09 500.14 500.15 500.19 500.17].16 500.18 500.13 500. b.13 500.'cubic'). Here. Denoting the width as the x – axis .11 500.14 500.15. zlabel('Height.12 500.01 500.11. % This script is for Example_7_15 % x=0: 25: 175.14 500. Solution: The MATLAB script and plot are shown below and explanations are provided with comment statements.5: 275.09 500.14 500. xi=0: 2.13 500.y).03 500.13 500.09 500. % y−axis varies down the columns of z z=[500.01 500.08 500.13 500.09 500. c.21 500.17 500.12.11 500.Interpolation with MATLAB a.y. plot the given data to form a rectangular grid.12 500. 500.18 500.09.14 500. the depth as the y – axis and the height as the z – axis .05 500.17 500.18 500. z_int [xx. size(xi) = 1 71 disp('size(xi)'). meters above sea level').y.15 500. grid off. % mesh(x. Interpolate the value of z at x = 108 m.14 500.yy]=meshgrid(x. % Make y−axis finer disp('size(yi)').16 500.18 500.11 500.05 500. 500.08 500. title('Parcel map') % The pause command below stops execution of the program for 10 seconds % so that we can see the mesh plot pause(10).08 500. Third Edition Copyright © Orchard Publications 7−35 .09 500.11 500.02 500.16 500. Compute the maximum height and its location on the x – y plane.12 500. box off xlabel('x−axis. 500. % x−axis varies across the rows of z y=0: 25: 275. 500.11 500. 500.12 500.12.02 500.15 500.14 500.10 500. 500.z.17 500. % Returns a row vector containing the size of xi where the % first element denotes the number of rows and the second is the number % of columns.14.01 500.09 500.yyi]=meshgrid(xi.13 500.108.13 500. 500. axis([0 175 0 275 500 502]).17 500.02. m').05 500.12 500.12 500. % Make x−axis finer % size(xi).177.14 500.15 500.17 500.yi).5: 175.z). 500.09 500.11 500. 500.16 500.15.02 500.13 500. 500. and y = 177 m.08 500.12 500.13 500.14 500.17 500.14 500. disp('Interpolated z is:').19 500.15 500. 500.14 500. z_int=interp2(x.10.17 500. ylabel('y−axis.11.15 500.09 500.08 500.12 500.15 500.15. size(xi) yi=0: 2. size(yi) [xxi. m').17 500.

disp('size(yyi)'). size(zzi) size(xxi).z.'*k').n]=find(zmax==zzi) %m= 7−36 Numerical Analysis Using MATLAB® and Excel®. and zeros when they are not equal % [m. meters above sea level'). % A=[a11 a12 a13. ylabel('y−axis. a32=5. Likewise max(zzi) returns a row vector which contains the % maxima of the columns in zzi. a13=3 and a33=6 % satisfy the condition A>2 % The == operator compares two variables and returns ones when they % are equal.y). size(yyi). title('Map of Rectangular Land Parcel') hold off.y. zlabel('Height. disp('size(zzi)').yy]=meshgrid(x. grid off. axis([0 175 0 275 500 503]). % Plot smoothed data hold on. the elements a22=3. [xx. For Example. size(zzi) zzi=interp2(x. size(yyi).yyi.xxi. 2 3 −4.yy.z. a31 a32 a33] or % A=[−1 0 3. m'). % Cubic interpolation − interpolates % all combinations of xxi and yyi and constructs the matrix zzi mesh(xxi.j]=find(A>2) % returns %i= % % 2 % 3 % 1 % 3 % % %j= % % 2 % 2 % 3 % 3 % That is.yyi. a21 a22 a23.'cubic'). m').zzi).Chapter 7 Finite Differences and Interpolation % size(xxi) = size(yyi) = size(zzi) = 111 71 disp('size(xxi)'). −2 5 6]. box off xlabel('x−axis. % [i. size(xxi). Observe that size(max(zzi)) = 1 71 % and size(max(max(zzi))) = 1 1 zmax=max(max(zzi)) % Estimates the peak of the terrain % The 'find' function returns the subscripts where a relational expression % is true. Third Edition Copyright © Orchard Publications . % Grid with original data plot3(xx. % max(x) returns the largest element of vector x % max(A) returns a row vector which contains the maxima of the columns % in matrix A.

size(yi) = 1 111 % Remember that i is the row index.yyi. % Cubic interpolation − interpolates % all combinations of xxi and yyi and constructs the matrix zzi Numerical Analysis Using MATLAB® and Excel®.Interpolation with MATLAB % % 65 % %n= % % 36 % % that is. j is the column index.z. Third Edition Copyright © Orchard Publications 7−37 . size(xi) = 1 71 % and the y−coordinate is found from ymax=yi(m) % ymax = % % 3.'cubic').7500 % Column 36.2000 % Row 65.xxi. zmax is located at zzi = Z(65)(36) % % the x−cordinate is found from xmax=xi(n) % xmax = % % 1.1492 size(xi) ans = 1 size(yi) 71 ans = 1 size(xxi) 111 ans = 111 size(yyi) 71 ans = 111 71 zzi=interp2(x. and x−axis % varies across the rows of z and y−axis varies down the columns of z Interpolated z is: z_int = 500.y.

11.15 7−38 Numerical Analysis Using MATLAB® and Excel®.21 where the x and y coordinates are x = 20 and y = 275 . Plot for Example 7. The interpolated value of z at x = 108 m and y = 177 m is z = 500. Third Edition Copyright © Orchard Publications .192 . The plot is shown in Figure 7.Chapter 7 Finite Differences and Interpolation size(zzi) ans = 111 zmax = 500.11. Figure 7.2108 m = 111 n= 9 xmax = 20 ymax = 275 71 zmax=max(max(zzi)) % Estimates the peak of the terrain These values indicate that z max = 500.

• Likewise. 3 and 4 . 2. n = 1. the above relation reduces to Numerical Analysis Using MATLAB® and Excel®. … • We can now express the first differences are usually expressed in terms of the difference operator Δ as Δf k = f k + 1 – f k • Likewise. • If the constant difference between successive values of x is h . x k ) = --------------------------------------------xi – xk and the third. – 1. 2. x j ) – f ( x j. x j. • If the values of x are equally spaced and the denominators are all the same. Third Edition Copyright © Orchard Publications 7−39 . x k ) f ( x i. these values are referred to as the differences of the function. 0. and so on divided differences are defined similarly.f k + n – 2 + … + ( – 1 ) nf k + 1 + ( – 1 ) f k 2! For k = 0 . 1. the second divided difference is defined as: f ( x i.9 Summary • The first divided difference is defined as: f ( xi ) – f ( xj ) f ( x i. for positive integer values of n Δ fk = Δ ( Δ n n–1 fk ) = Δ n–1 fk + 1 – Δ n–1 fk • The difference operator Δ obeys the law of exponents which states that Δ ( Δ fk ) = Δ n m n m+n fk • The nth differences Δ f k are found from the relation n n–1 n n(n – 1) Δ f k = f k + n – nf k + n – 1 + ------------------. fourth. within an interval.– 2. not necessarily consecutive values of x . the second differences are expressed as Δ f k = Δ ( Δf k ) = Δf k + 1 – Δf k 2 and.Summary 7. the typical value of x k is x k = x 0 + kh for k = … . x j ) = ---------------------------xi – xj where x i and x j are any two. in general.

Then. in analogy with Maclaurin power series. The procedure is as follows: 1. 2. Third Edition Copyright © Orchard Publications . n j! j • Factorial polynomials provide an easier method of constructing a difference table.Chapter 7 Finite Differences and Interpolation Δf 0 = f 2 – f 1 Δ f 0 = f 2 – 2f 1 + f 0 Δ f 0 = f 3 – 3f 2 + 3f 1 – f 0 Δ f 0 = f 4 – 4f 3 + 6f 2 – 4 f 1 + f 0 4 3 2 • As with derivatives. Then.for j = 0. the nth differences of a polynomial of degree n are constant. • The factorial polynomials are defined as and (x) (n) = x ( x – 1 ) ( x – 2 )… ( x – n + 1 ) 1 = --------------------------------------------------------( x – 1 ) ( x – 2 )… ( x + n ) (x) –( n ) Using the difference operator Δ with the above relations we obtain and Δ(x) Δ(x) (n) = n(x) (n – 1) –( n ) = –n ( x ) n –( n – 1 ) These are very similar to differentiation of x and x . …. the factorial polynomial reduces to p n ( x ) = r 0 + xq 0 ( x ) 7−40 Numerical Analysis Using MATLAB® and Excel®. we can express that polynomial as pn ( x ) = a0 + a1 ( x ) (1) –n + a2 ( x ) (2) + … + an ( x ) (n) where Δ pn ( 0 ) a j = -----------------. We divide p n ( x ) by x to obtain a quotient q 0 ( x ) and a remainder r 0 which turns out to be the constant term a 0 . • We can express any algebraic polynomial f n ( x ) as a factorial polynomial p n ( x ) . 1.

Third Edition Copyright © Orchard Publications 7−41 . • The definite sum of p n ( x ) for the interval a ≤ x ≤ a + ( n – 1 )h is α + ( n – 1 )h x=α ∑ p n ( x ) = p n ( α ) + p n ( α + h ) + p n ( α + 2h ) + … + p n [ α + ( n – 1 )h ] • In analogy with the fundamental theorem of integral calculus which states that ∫a f ( x ) d x b = f( b) – f(a ) Numerical Analysis Using MATLAB® and Excel®. It is denoted as Δ p n ( x ) . q 0 ( x ) = r 1 + ( x – 1 )q 1 ( x ) and by substitution we obtain p n ( x ) = r 0 + x [ r 1 + ( x – 1 )q 1 ( x ) ] = r 0 + r 1 ( x ) (1) + x ( x – 1 )q 1 ( x ) 3. We divide q 0 ( x ) by ( x – 1 ) . We divide q 1 ( x ) by ( x – 2 ) . to obtain a quotient q 1 ( x ) and a remainder r 1 which turns out to be the constant term a 1 .Summary 2. Then. to obtain a quotient q 2 ( x ) and a remainder r 2 which turns out to be the constant term a 2 . pn ( x ) = r0 + r1 ( x ) (1) + r2 ( x ) + … + rn – 1 ( x ) j + rn ( x ) (n) where Δ pn ( 0 ) r j = a j = -----------------j! • The antidifference of a factorial polynomial is analogous to integration in elementary calculus. and it is computed from Δ (x) –1 –1 (n) (x) = -------------------(n + 1) (n + 1) • Antidifferences are very useful in finding sums of series. and thus q 1 ( x ) = r 2 + ( x – 2 )q 2 ( x ) and by substitution we obtain pn ( x ) = r0 + r1 ( x ) = r0 + r1 ( x ) (1) (1) + x ( x – 1 ) [ r 2 + ( x – 2 )q 2 ( x ) ] + r2 ( x ) (2) (2) + x ( x – 1 ) ( x – 2 )q 2 ( x ) (n – 1) and in general.

and Δ f 0 are the first. and f ( x 0. second. x 1. x 2. x 1.Δ f 0 + --------------------------------. x 3 ) are the first. x 1. • Newton’s Divided Difference Interpolation Method uses the formula f ( x ) = f ( x 0 ) + ( x – x 0 ) f ( x 0. ( x – x1 ) r = -----------------h 2 3 This formula is valid only when the values x 0. …. x n need not be equally spaced.Δ f 0 + … 2! 3! where f 0 is the first value of the data set. x 1. and third forward differences respectively. x 2. x 1 ) + ( x – x 0 ) ( x – x 1 ) f ( x 0. x n are equally spaced with interval h . x 1. x 1 ) . • Lagrange’s Interpolation Method uses the formula ( x – x 1 ) ( x – x 2 )… ( x – x n ) ( x – x 0 ) ( x – x 2 )… ( x – x n ) f ( x ) = ----------------------------------------------------------------------. and third divided differences respectively. x 3 ) where f ( x 0. hence the name forward interpolation. second. x 2. Δ f 0 . 7−42 Numerical Analysis Using MATLAB® and Excel®. …. that is. has the advantage that the values x 0. x 2 ) + ( x – x 0 ) ( x – x 1 ) ( x – x 2 ) f ( x 0. the values near the beginning of the given data set. Third Edition Copyright © Orchard Publications . x 2. x 2. This method has the advantage that the values x 0.f ( x 1 ) ( x 0 – x 1 ) ( x 0 – x 2 )… ( x 0 – x n ) ( x 1 – x 0 ) ( x 1 – x 2 )… ( x 1 – x n ) ( x – x 0 ) ( x – x 1 )… ( x – x n – 1 ) + ----------------------------------------------------------------------------. • The Gregory−Newton Forward Interpolation method uses the formula r(r – 1) 2 r( r – 1)( r – 2) 3 f ( x ) = f 0 + rΔf 0 + ----------------. x n need not be equally spaced or taken in consecutive order. x 2 ) .f ( x 0 ) + ----------------------------------------------------------------------. x 1. …. or taken in consecutive order. Δf 0 .Chapter 7 Finite Differences and Interpolation we have the fundamental theorem of sum calculus which states that α + ( n – 1 )h x=α ∑ pn ( x ) = Δ pn ( x ) –1 α + nh α • One important application of finite differences is interpolation. The variable r is the difference between an unknown point x and a known point x 1 divided by the interval h . like Newton’s divided difference method. f ( x 0. that is.f ( x n ) ( x n – x 0 ) ( x n – x 2 )… ( x n – x n – 1 ) and. It is used to interpolate values near the smaller values of x . x 1.

xi. Δ f –2 . It is used to interpolate values near the end of the data set. second and third backward differences. Δf –1 .Δ f – 3 + … 2! 3! where f 0 is the first value of the data set. cubic (cubic interpolation which requires equidistant values of x ).y.xi) but performs two dimensional interpolation.y. spline (cubic spline interpolation which does also extrapolation). interp1(x. linear (linear interpolation. x 1.xi. Backward interpolation is an expression to indicate that we use the differences in a backward sequence. that is.2 ) r(r + 1 )(r + 2.y. • We can perform interpolation to verify our results with the MATLAB functions interp1(x.Δ f – 2 + ---------------------------------. Third Edition Copyright © Orchard Publications 7−43 .z. the last entries on the columns where the differences appear. the default interpolation). …. x 2. x n are equally spaced with interval h .Summary • The Gregory−Newton Backward Interpolation method uses the formula r(r + 1. and Δ f –3 are the first. Numerical Analysis Using MATLAB® and Excel®.3 ) f ( x ) = f 0 + rΔf –1 + ----------------. and interp2(x. and ( x – x1 ) r = -----------------h 2 3 This formula is valid only when the values x 0. we can use the Excel VLOOKUP function to perform interpolation. • If the increments in x values are small. the larger values of x .yi) which is similar to interp1(x.xi). that is.y.’method’) where method allows us to specify nearest (nearest neighbor interpolation).

348 55 7.10 Exercises 1. to compute: a.2 1. Third Edition Copyright © Orchard Publications . b.3 ) b.416 56 7. Use the data of the table below and Newton’s divided difference formula to compute: a. and then construct the difference table with h = 1 .280 54 7.071 51 7.211 53 7.054 1.636 1.483 x 3. f ( 1.8 2.323 2.112 1.1 1. Use the data of the table below and the appropriate (forward or backward) Gregory−Newton formula. f ( x ) = x – 2x + 4x – x + 6 5 4 3 2.7 2.2 55. f ( 1.95 ) x y=f(x) 1.141 52 7.9 x 50 7.011 7−44 Numerical Analysis Using MATLAB® and Excel®. Express the given polynomial f ( x ) below as a factorial polynomial p ( x ) . 50.0 3. calculate the leading differences.219 1.Chapter 7 Finite Differences and Interpolation 7.5 1.

i. i.r0]=deconv(px. x−3 % Computation of fourth quotient and remainder % Coefficients of fifth divisor. [q2. r 3. [q5. x−2 % Computation of third quotient and remainder % Coefficients of fourth divisor. x−4 % Computation of fifth quotient and remainder % Coefficients of sixth (last) divisor.e.e.e.11 Solutions to End−of−Chapter Exercises 1.d4) d5=[1 −5].d0) d1=[1 −1]. r 1.d2) d3=[1 −3].r2]=deconv(q1. pn ( x ) = r0 + r1 ( x ) (1) + r2 ( x ) (2) + … + rn – 1 ( x ) (n – 1) + rn ( x ) (n) We can compute the remainders by long division but. f ( x ) = x – 2x + 4x – x + 6 5 4 3 The highest power of the given polynomial f ( x ) is 5 . x−1 % Computation of second quotient and remainder % Coefficients of third divisor.Solutions to End−of−Chapter Exercises 7. [q4.r3]=deconv(q2. x % Computation of first quotient and remainder % Coefficients of second divisor. to determine p n ( x ) .d5) % Coefficients of given polynomial % Coefficients of first divisor. Third Edition Copyright © Orchard Publications 7−45 .r4]=deconv(q3.q) function which divides the polynomial p by q. repeated below. r 2.e. [q1. x−5 % Computation of sixth (last) quotient and remainder q0 = 1 r0 = 0 q1 = 1 r1 = 0 q2 = 1 r2 = 0 0 0 13 1 5 0 0 0 2 -1 3 3 0 0 0 0 6 -2 4 0 -1 Numerical Analysis Using MATLAB® and Excel®. d0=[1 0]. i.d3) d4=[1 −4].r5]=deconv(q4.28). The MATLAB script is as follows: px=[1 −2 4 0 −1 6]. we will use the MATLAB deconv(p. we must evaluate the remainders r 0.r1]=deconv(q0.e. then. [q3. i. r 4 and r 5 . i.d1) d2=[1 −2]. we will use (7. i. [q0. for convenience.e.

Chapter 7 Finite Differences and Interpolation q3 = 1 r3 = 0 q4 = 1 r4 = 0 q5 = 0 r5 = 1 Therefore. Δ p n ( 0 ) = j!r j and p n ( x ) above Δ p ( 0 ) = 0! ⋅ 6 = 6 Δ p ( 0 ) = 3! ⋅ 17 = 102 Δ p ( 0 ) = 6! ⋅ 0 = 0 6 3 0 j Δ p ( 0 ) = 1! ⋅ 2 = 2 4 1 Δ p ( 0 ) = 2! ⋅ 13 = 26 Δ p ( 0 ) = 5! ⋅ 1 = 120 5 2 Δ p ( 0 ) = 4! ⋅ 8 = 192 We enter these values in the appropriate spaces as shown on the table below.28). (x) (n) = x ( x – 1 ) ( x – 2 )… ( x – n + 1 ) with the MATLAB collect(‘s_expr’) function. 7−46 Numerical Analysis Using MATLAB® and Excel®.12). i. i..e. (13*x*(x−1))+2*x+6)) px = x^5-2*x^4+4*x^3-x+6 We observe that this is the same algebraic polynomial as f ( x ) .. We will now compute the leading entries for the difference table using (7.e. with reference to (7. the factorial polynomial is pn ( x ) = 6 + 2 ( x ) (1) 4 0 17 8 + 13 ( x ) (2) + 17 ( x ) (3) + 8(x) (4) + (x) (5) We will verify that p n ( x ) above is the same polynomial as the given f n ( x ) by expansion of the factorials using (7.30). Third Edition Copyright © Orchard Publications . syms x. px=collect((x*(x−1)*(x−2)*(x−3)*(x-4)+(8*x*(x−1)*(x−2)*(x-3))+(17*x*(x−1)*(x−2))+..

and third differences. we simply subtract the second value of f ( x ) from the first. we compute the first.071 51 7. Third Edition Copyright © Orchard Publications 7−47 . These are not divided differences and therefore. We will use the differences in a forward sequence.348 55 7. then. Numerical Analysis Using MATLAB® and Excel®. that is.483 x a.416 56 7. and so on.211 53 7. We enter the given x and f ( x ) values in a difference table.Solutions to End−of−Chapter Exercises x p( x) 6 Δ 2 Δ 2 Δ 3 Δ 4 Δ 5 Δ 6 26 102 192 120 0 We obtain the remaining set of values by crisscross addition as shown on the table below.2 should be in the interval 50 ≤ x ≤ 51 . as shown below. This is because the value of 50. x 50 7. x p( x) 6 Δ 2 Δ 2 Δ 3 Δ 4 Δ 5 Δ 6 8 28 36 156 192 578 770 1606 2376 3672 6048 26 102 128 294 422 606 1028 1038 2066 432 312 120 192 120 0 2. the third from the second. the first entries on the columns where the differences appear.141 52 7.280 54 7. second.

348 7. fprintf('\n').071 + ( 0.001 0..211 7.20 ) ⋅ ( 7. x 3 ) f ( x 0.0 = 0.071 2nd Difference f ( x 0.416 7.20 1 h and with these values. x 2 ) 3rd Difference f ( x 0.20 – 1 ) f ( 50.067 7. disp(spline_interp) spline interpolation yields f(50. fx=[7.Chapter 7 Finite Differences and Interpolation 1st Difference x 50 51 52 53 54 55 56 f (x) 7.348 7. Check with MATLAB: x =[50 51 52 53 54 55 56].141 0.483 f 0 = f ( 50 ) = 7.071 h = x 1 – x 0 = 51 – 50 = 1 x – x1 -------------------------r = ------------.001 -0.068 -0.416 7.280 7.071 7.⋅ ( 0.085 3! The spreadsheet below shows the layout and computations for Part (a). x 1.20 ) ⋅ ( 0.000 0. x 1 ) 0.483]. spline_interp=interp1(x.000 -0.071 ) + ------------------------------------------2! ( 0.001 -0.20 ) ⋅ ( 0.= 50.280 7.2 – 50.001 0.[50.070 7.000 0.20 – 1 ) ( 0. x 1.070 -0.2]'.069 0. Third Edition Copyright © Orchard Publications .2) = 7. we obtain ( 0.0849 7−48 Numerical Analysis Using MATLAB® and Excel®.2 ) = 7. using (7.2) = \n').'spline').211 7..068 0.54).fx.001 ) = 7..141 7.20 – 2 ) + -------------------------------------------------------------------. fprintf('spline interpolation yields f(50. x 2.001 0.001 0.

we will use the backward interpolation formula r(r + 1.0 52.211 0.50 7.9 is very close to the last value in the given range.2 ) r(r + 1 )(r + 2.483 r= (D5-A8)/C22= 0.000 -0.003 0.416 0.000 -0.40 7.068 7.3 ) f ( x ) = f 0 + rΔf – 1 + ----------------.2 Δ 2f Δ 3f Δ 4f Δ 5f Δ 6f h= A10-A8= 1.0 53. Third Edition Copyright © Orchard Publications 7−49 .001 -0.001 -0.069 7.348 7.20 7.Solutions to End−of−Chapter Exercises Gregory-New ton Forw ard Interpolation Method for Exercise 7.001 -0.141 0.54) and (7.001 0.002 -0.Δ f – 2 + ---------------------------------. Since the value of 55.070 7.00 50 51 52 53 54 55 56 b.071 7.280 7.0 56.280 0.067 7.2 -0.00 f(50.416 7.2(a) See expressions (7.348 0.2)= round(B8+F22*C9+(F20*(F20-1)*D10)/FACT(2)+(F20*(F20-1)*(F20-2)*E11)/FACT(3).001 0.0 54.001 0.068 7.Δ f – 3 + … 2! 3! Numerical Analysis Using MATLAB® and Excel®.001 0.0 f(x) 7.483 7.003 Δf 50.085 50 51 52 53 54 55 56 7.30 7.10 7.211 7.3) = 7.071 0.0 55.55) Interpolate f(x) at x= x 50.000 -0.0 51.000 0.001 0.141 7.070 7.

070 ) + ----------------------------------------.1 2. Third Edition Copyright © Orchard Publications .1 ) ( 0.9 ) lies between f ( 55 ) and f ( 56 ) .054 1.440 -------------------------------2.800 -------------------------------1.500 2. second and third backward differences.112 1.280 7.219 – 1.054 = 2..1 + 1 ) ( – 0. fprintf('spline interpolation yields f(55.054 – 1. fprintf('\n').1 1.7 7−50 Numerical Analysis Using MATLAB® and Excel®...636 – 1.8 2.= 2.390 1.070 = 0.5 – 1.4764 3.1 ) ( – 0.211 7.219 1.690 – 2.112 -------------------------------.071 7. and Δ f –3 are the first.483 as our starting point since f ( 55.390 – 1.690 -------------------------------.1 ) ( – 0.323 – 2.400 1.9 ) = 7.7 2. The first divided differences are: 1.8 – 1.090 1.011 a. Δf –1 .[55.= 1.090 -------------------------------.000 ) 2! ( – 0.7 – 1.9]'.5 – 1. Δ f –2 .2 – 1. disp(spline_interp) spline interpolation yields f(55.fx.8 The second divided differences are: 1.483].9) = \n'). fx=[7.1 1.2 3.011 – 2.9) = 7. and ( x – x1 ) r = -----------------h 2 3 We arbitrarily choose f 0 = 7.636 -------------------------------.= 2.070 1.390 -------------------------------.0 – 1.0 3.348 7.0 ) ⁄ 1 = – 0.5 1.7 3.( – 0. Then.1 + 2 ) + -------------------------------------------------------------------.483 + ( – 0.2 1.5 2.219 -------------------------------. h = 56 – 55 = 1 and r = ( x – x 1 ) ⁄ h = ( 55.000 1.1 + 1 ) f ( 55. spline_interp=interp1(x.7 – 1.323 2.9 – 56.= 1.0 – 1.476 3! Check with MATLAB: x =[50 51 52 53 54 55 56].001 ) = 7.= 2. x y=f(x) 1.416 7.2 2.1 Now.440 – 2.5 2.58) we have: ( – 0.141 7.8 – 1.690 -------------------------------1.Chapter 7 Finite Differences and Interpolation where f 0 is the first value of the data set.636 1.= 1.'spline').090 – 1. by (7.323 = 3.( 0.

Third Edition Copyright © Orchard Publications 7−51 . Then.350 b.8 ) ( 1.004 = 1.Solutions to End−of−Chapter Exercises and the third divided differences are: 1.5 1.0 – 1.5 ) + ( 1.390 1.3 ) . Then. 1st Divided Difference 2nd Divided Difference 3rd Divided Difference x 1.95 – 2 ) ( 1.3 – 1. x 1.818 The spreadsheet below verifies our calculated values. x 2 ) f ( x 0.400 = 1. we use x = 1. x 2 ) + ( x – x 0 ) ( x – x 1 ) ( x – x 2 ) f ( x 0.49).3 . x 1.4 ) + ( 1.49).800 = 1.0 f (x) 1.3 ) = 1.To find f ( 1. x 2 ) + ( x – x 0 ) ( x – x 1 ) ( x – x 2 ) f ( x 0.95 – 1.019 – 0. f ( x ) = f ( x 0 ) + ( x – x 0 ) f ( x 0. x 2.000 2.3 – 1.95 – 2 ) ( 1.172 – 0.000 -------------------------------2.44 ) + ( 1.219 f ( x 0.3 – 1.500 3.000 2.3 – 1.000 -------------------------------1.0 and for x in (7.323 3.2 2. x 1.1 ) ( 1.400 – 0.95 – 1. x 2.112 1. x 1.7 1.3 – 1.070 f ( x 0. we use x = 1. x 3 ) 0. We start with x 0 = 1. x 1 ) 1.7 – 1.1 1.028 – 0.054 2.011 – 0. Numerical Analysis Using MATLAB® and Excel®.011 + ( 1.07 ) + ( 1.000 = 1.636 2. x 1 ) + ( x – x 0 ) ( x – x 1 ) f ( x 0.8 – 1. x 2. x 1 ) + ( x – x 0 ) ( x – x 1 ) f ( x 0.95 – 2 ) ( 3.1 ) ( 1.2 ) ( 1.112 + ( 1.1 ) ( 1.112 + 0.000 2.440 1. x 1. x 1. we construct the difference table below. f ( x ) = f ( x 0 ) + ( x – x 0 ) f ( x 0. x 3 ) f ( 1.95 ) we start with x 0 = 2.5 ) ( 1 ) = 1.000 1.8 ) ( 2.000 – 1.400 2.5 With these values.95 ) = 3.1 2.800 1.7 ) ( 1 ) = 3.011 To find f ( 1.95 – 1.500 – 2.214 + 0.2 ) ( 1.3 – 1.002 = 2.690 1.000 -------------------------------1.090 1.2 1.8 2.1 and for x in (7.95 . x 3 ) f ( 1.

054 2...636 2.2 1.0 1.5 1.7 1. x2) f(x0.8 2.219 1.090 2. Third Edition Copyright © Orchard Publications .323 3..054 2.000 1.95]'.8 2 1. disp(spline_interp) spline interpolation value of f(1. fx=[ 1.3 1. fprintf('\n').x1.1 1.390 1.000 0.1 1.636 2.3380 spline_interp=interp1(x.112 1.636 2. spline_interp=interp1(x.2 1.2 1.3]'.800 1.x2.0 Check with MATLAB: x=[ 1.219 1.323 3.00 f(x) 2.000 1.'spline').50 1..00 1.8184 7−52 Numerical Analysis Using MATLAB® and Excel®.8 2.50 2.3): 1.000 2nd divided 3rd divided difference difference f(x0.00 1.011].fx.'spline').054 2.400 1.500 2.95): 2. fprintf('spline interpolation value of f(1.50 3. x1) 1.7 1.5 1. disp(spline_interp) spline interpolation value of f(1.0].219 1.. fprintf('spline interpolation value of f(1.3): \n\n').112 1.5 x 1.323 3.011 3.95): \n\n').112 1. fprintf('\n').5 1.070 1.8 2.440 3.7 1.[1.1 f(x) 1..690 2.Chapter 7 Finite Differences and Interpolation 1st divided difference f(x0.fx.x3) x 1.011 2.[1. x1.0 1.

(8. we normally assume that the data. Third Edition Copyright © Orchard Publications 8−1 . and regression with power series approximations.2. Parabolic line approximation In finding the best line. We will illustrate their application with several examples. that is.1 Curve Fitting Curve fitting is the process of finding equations to approximate straight lines and curves that best fit given sets of data.2.2.1. we can use the equation for the quadratic or parabolic curve of the form y = ax + bx + c y 2 (8.Chapter 8 Linear and Parabolic Regression T his chapter is an introduction to regression and procedures for finding the best curve to fit a set of data. 8.1 and 8. Numerical Analysis Using MATLAB® and Excel®.1) y = mx + b y x Figure 8. We will discuss linear and parabolic regression.2) x Figure 8. for the data of Figure 8. For Figure 8. and our task is to find the dependent variable y . This process is called regression. Straight line approximation. shown by the small circles in Figures 8. For example. we can use the equation of a straight line.1. represent the independent variable x .

y 1 ). ( x 3.2 Linear Regression We perform linear regression with the method of least squares. as follows: Let x and y be two related variables.5) In (8. the slope m and y-intercept b are the same in all equations since we have assumed that all points lie close to one straight line.Chapter 8 Linear and Parabolic Regression Regression can be linear (straight line) or curved (quadratic. and so on. We denote the straight line equations passing through these points as y 1 = mx 1 + b y 2 = mx 2 + b y 3 = mx 3 + b … y n = mx n + b (8. We derive the values of m and b .5). we have observed the values y 1. However. etc. we will not obtain valid values for all points if we solve just two 8−2 Numerical Analysis Using MATLAB® and Excel®. The best fitting straight line or curve has the property that d 1 + d 2 + … + d 3 = minimum 2 2 2 (8. and we have observed that the points ( x 1. 8. x 2. y 2 ). Investment corporations use regression analysis to compare a portfolio’s past performance versus index figures. x 3. …. With this method. but we interested in finding the most suitable. Now.3) is called a least squares line. y n . y 2. a straight line that satisfies (8.4) such that the sum of the squares of the errors will be minimum.) and it is not restricted to engineering applications. …. that will make the equation of the straight line to best fit the observed data. Financial analysts in large corporations use regression to forecast future costs. let us suppose that we have plotted the values of y versus the corresponding values of x . Let the distance of data point x 1 from the line be denoted as d 1 . the distance of data point x 2 from the same line as d 2 . we can find more than one straight line or curve to fit a set of given data. x n . ( x 2. cubic. we compute the coefficients m (slope) and b (y-intercept) of the straight line equation y = mx + b (8. and assume that corresponding to the values x 1. …. we need to determine the values of the unknowns m and b from all n equations. y n ) approximate a straight line. ( x n. y 3 ). y 3. and the Census Bureau use it for population forecasting.3) and it is referred to as the least-squares curve. Thus. Third Edition Copyright © Orchard Publications . we call it a least-squares parabola. If it is a parabola. Obviously.

6) ∑ squares ∂ ∂m is a function of two variables m and b . The straight line that we choose must be a straight line such that the distances between the observed values. Let the sum of the squares of the errors be ∑ squares Since = [ y 1 – ( mx 1 + b ) ] + [ y 2 – ( mx 2 + b ) ] + … + [ y n – ( mx n + b ) ] 2 2 2 (8.6) we must equate to zero its two partial derivatives with respect to m and b .8) The second derivatives of (8. Then. to minimize (8.Linear Regression equations with two unknowns. depending on the position of the observed value. is y 1 – ( mx 1 + b ) .7) and (8. * The error (difference) between the observed value y 1 . will be minimum. Accordingly.8) are positive and thus value. On the contrary. and the value at the point on the straight line. we find the sum of the squared distances between observed points and the points on the straight line. For this reason. and the corresponding values on the straight line. Collecting like terms. Likewise.7) and ∂ ∂b ∑ squares = – 2 [ y 1 – ( mx 1 + b ) ] – 2 [ y 2 – ( mx 2 + b ) ] – … – 2 [ y n – ( mx n + b ) ] = 0 (8. if we were to combine positive and negative values.8) we obtain ∑ squares will have its minimum * A linear system of independent equations that has more equations than unknowns is said to be overdetermined and no exact solution exists. this method is referred to as the method of least squares. Numerical Analysis Using MATLAB® and Excel®. and simplifying (8. ∑ squares = – 2x 1 [ y 1 – ( mx 1 + b ) ] – 2x 2 [ y 2 – ( mx 2 + b ) ] – … – 2x n [ y n – ( mx n + b ) ] = 0 (8. and the value that lies on the straight line. This will be achieved if we use the magnitudes (absolute values) of the distances. Third Edition Copyright © Orchard Publications 8−3 . some may cancel each other and give us an erroneous sum of the distances. a system that has more unknowns than equations is said to be underdetermined and these systems have infinite solutions.7) and (8. the error between the observed value y 2 and the value that lies on the straight line is y 2 – ( mx 2 + b ) and so on. This difference could be positive or negative.

5 70 48.3 80 51.1 90 54 100 56.9) simultaneously by Cramer’s rule.10) where Δ = Σx Σx Σx n 2 D1 = D2 = Σx Σxy Σx Σy (8. m and b are computed from D1 m = ----Δ D2 b = ----Δ Σxy Σx Σy n 2 (8.1 In a typical resistor.9) where Σx = sum of the numbers x Σy = sum of the numbers y Σxy = sum of the numbers of the product xy Σx = sum of the numbers x squared n = number of data x 2 We can solve the equations of (8.0 30 37 40 40 50 42.3 where we enter the given values and we perform the computations using spreadsheet formulas. or with Excel.1 Data for Example 8. we use the spreadsheet of Figure 8. 8−4 Numerical Analysis Using MATLAB® and Excel®.11) Example 8.0 20 34. Third Edition Copyright © Orchard Publications . TABLE 8. For convenience.Resistance versus Temperature T ( C) ° x y 0 27. The temperature increments and the observed resistance values are shown in Table 8-1.Chapter 8 Linear and Parabolic Regression ( Σx )m + ( Σx )b = Σxy ( Σx )m + nb = Σy 2 (8.6 60 45.6 10 31. the resistance R in Ω (denoted as y in the equations above) increases with an increase in temperature T in °C ( denoted as x ) . or with MATLAB using matrices.7 R (Ω) Solution: There are 11 sets of data and thus n = 11 . Compute the straight line equation that best fits the observed data.1 . With Cramer’s rule.

1 54.123 26559 = 467. Numerical Analysis Using MATLAB® and Excel®.288 550 = 11 b=D2/Δ = 28. Thus.0 Resistance 50. and y (the measured resistance corresponding to each temperature value) in Column B.0 20.288x + 28.6 45.3.0 40.Linear Regression Spreadsheet for Example 8.123 (8. The values of m and b are shown in cells I20 and I24 respectively. Spreadsheet for Example 8. Columns C and D show the x 2 and xy products.12) We can use Excel’s Add Trendline feature to produce quick answers to regression problems.8 3402850 34859 121000 Σx Σ xy Σy Σx 2 n Σx n Σ xy Σy Σx Figure 8.0 34. We will illustrate the procedure with the following example.6 31. we enter the x (temperature) values in Column A.11).1 x (0C) 0 10 20 30 40 50 60 70 80 90 100 550 Σx 2 y(Ω ) 27. Third Edition Copyright © Orchard Publications 8−5 .10) and (8.3 51.5 48. Then.0 56.7 467. we compute the sums so they can be used with (8. All work is shown on the spreadsheet of Figure 8. the straight line equation that best fits the given data is y = mx + b = 0.0 40.0 42.0 30.3.8 Σx x2 0 100 400 900 1600 2500 3600 4900 6400 8100 10000 38500 xy 0 310 680 1110 1600 2130 2730 3381 4088 4860 5670 26559 38500 = 550 26559 = 467.8 38500 = 550 Resistance versus Tem perature 60.1 Accordingly.0 37.0 0 20 40 60 80 100 Temperature 550 = 11 m=D1/Δ = 0.

and on the Gridlines tab. We click on the Chart Wizard icon. we type Resistance (Ohms).2 Repeat Example 8. and we click OK. Plot of the straight line for Example 8. On the Chart sub-types options. Under the Value (Y) axis. we perform the following steps: 1. and we observe that the plot appears next to the data.7 60 50 40 30 20 0 20 40 60 80 100 Temperature (degrees Celsius) Straight line for Example 8. we click on the small (with the hand) box. we type Straight line for Example 8.4.2. we change the Major Unit to 10. 2. and on the Chart title box. we click on Next>Next> Next>Finish. and we press the Delete key to delete it. we choose Plot Area from the taskbar below the main taskbar. on the Value X-axis. We click anywhere on the y-axis to select it.0 42. 3. Solution: We first enter the given data in columns A and B as shown on the spreadsheet of Figure 8.4. We click on Chart on the main taskbar.2 To produce the plot of Figure 8. We observe now that the plot area is white.1 using Excel’s Add Trendline feature.2 Figure 8. We click on the Scale tab. on the Patterns tab we click on the white box (below the selected gray box). We click on the Titles tab. we click on the top (scatter) sub-type.0 40.5 48. we change the maximum value from 150 to 100. we type Temperature (degrees Celsius).6 45. and we click on the small (with the hand) box. Next. we click on the Major gridlines box to deselect it. We click on XY (Scatter) Type. and we click on the small (with the hand) box. and we click on OK. and observe six square handles (small black squares) around it.Chapter 8 Linear and Parabolic Regression Example 8.3 51. we click anywhere on the perimeter of the Chart area.6 31. The displayed chart types appear on the Standard Types tab. Then. and we click on OK. We click on the Scale tab.0 37. We click on the Series 1 block inside the Chart box. x (0C) 0 10 20 30 40 50 60 70 80 90 100 y(Ω ) 27. Third Edition Copyright © Orchard Publications Resistance (Ohms) .1 54. We click anywhere on the x-axis to select it. To change the plot area from gray to white.0 56. and on the Value Y-axis.0 34.4. we change the minimum value from 0 to 20. 8−6 Numerical Analysis Using MATLAB® and Excel®.

4. Numerical Analysis Using MATLAB® and Excel®. This feature will be illustrated in Example 8. we click on Add Trendline. by placing the cursor near the center handle of the left or right side of the Chart area.3 Find the least−squares parabola for the data shown in Table 8. and we click on OK. We place the cursor near the center handle of the upper side of the graph. 8. On the Type tab. we can stretch or shrink the width of the plot to the left or to the right. 5.Parabolic Regression 4.2. We can also use Excel to compute and display the equation of the straight line. We can also stretch (or shrink) the height of the Chart area by placing the cursor near the center handle of the lower side of the graph. We now observe that the points on the plot have been connected by a straight line. b.14) where n = number of data points. and we click on Chart above the main taskbar. we click anywhere on the perimeter of the Chart area. and c are found from ( Σx )a + ( Σx )b + nc = Σy ( Σx )a + ( Σx )b + ( Σx )c = Σxy ( Σx )a + ( Σx )b + ( Σx )c = Σx y 4 3 2 2 3 2 2 (8. Example 8. It provides a wealth of information for statisticians. Third Edition Copyright © Orchard Publications 8−7 .13) where the coefficients a. On the pull-down menu. The Data Analysis Toolpack in Excel includes the Regression Analysis tool which performs linear regression using the least squares method. We click anywhere on the perimeter of the Chart area to select it. To make the plot more presentable.3 Parabolic Regression We find the least-squares parabola that fits a set of sample points with y = ax + b + c 2 (8. and move it downwards with the mouse. and we observe the six handles around it. Similarly. and when the two-directional arrow appears. we move it upwards by moving the mouse in that direction. we click on the first (Linear). and contains several terms used in probability and statistics.

73 2.24 182.15c = 2698.3 7.2 32.24 5.6 5.3 7.09 148.15) with matrix inversion and multiplication. Spreadsheet for Example 8.40 6. and from these we form the coefficients of the unknown a.5 5. Third Edition Copyright © Orchard Publications .61 29.16 282.68 26.04 941.78 16 9.2 4. A B C 2 D 3 E 4 F G 2 x x x xy 1 x y xy 2 1.76 17.15b + 79.8 5.9 40.6.49 437.0 9.0 8.70 332.5 5.93 31.79 92.06 7.46 259.48 4 1.6 4.96 636.08 38.1 6.71 13 7.2 Data for Example 8.87 10 5.7 5.2 3.93 11 6.70 67.72 2698.8 5.3 7.4 6.86 332.7 7.3 18.1 7.5 4.76 438.1c = 437.48 9 5.60 41.17 46.6 2.14).06 5470.05 39.3 By substitution into (8.88 789.9 7.4 6.48 37.35 21.5 1. b.3 9.4 Solution: We construct the spreadsheet of Figure 8.7 7.5.8 4004.8 7.8 2.70 17.49 185.6 9.22 38.19 9223.76 294.72 32331.88 31. The sum values are shown in Row 18.1 3.27 7 4.8 2.5 73.01 117.58 14 8.44 18.15 4004. 8−8 Numerical Analysis Using MATLAB® and Excel®.1 6.1b + 15c = 87.50 10.44 1.5. and c .2 1.6 6.62 12 7.72 44.1 2.7 96.31 17 Σx= Σy= Σx2= Σx3= Σx4= Σxy= Σx2y= 18 79.04 233.6 24.07 5. as shown in Figure 8.9 1.37 (8.6 50.83 10.Chapter 8 Linear and Parabolic Regression TABLE 8.15a + 79.58 45. and from the data of Columns A and B.49a + 4004.22 207.4 28.91 2541.64 778. 530.8 530.1 6.49 79.3 7.50 32331.19 1055.50b + 530.65 11.9 7.98 3336.29 6 3.39 134.37 Figure 8.7 6.1 7.15) We solve the equations of (8. we compute the values shown in Columns C through G.2 3.1 87.4 4.48 3 1.51 341.6 4.96 262.7 7.6 5.50a + 530.1 57.98 8 4.2 4.8 3.4 84.38 5.6 6.41 357.65 576.5 5.3 x y x y 1.25 3. The procedure was presented in Chapter 4.79 5 2.28 287.42 45.14 1677.82 15 9.69 7163.

3 Example 8.78 Figure 8.385 0.50 530.20x +1.20 -1 A = 8 -0.964 5. for brevity.032 c= 2.6.524 3.104 5.9 1.700 3.0 1.385 0.94x+2.94 9 0.6 0.00 87.50 530.8 0.040 4.520 4.4 1.78 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 x 6 7 8 9 10 2 Figure 8.364 4.72 4 2 Σx y= 2698.672 4. x 0. only a partial list of Numerical Analysis Using MATLAB® and Excel®.1 0.78 2 The plot for this parabola is shown in Figure 8. the least−squares parabola is y = – 0.2 1.15 79.7 0.016 0.94x + 2.49 4004.872 4. Third Edition Copyright © Orchard Publications y 8−9 . Solution: We enter the given data on the spreadsheet of Figure 8. Parabola for Example 8.4 0.2 0.5 y 2.780 2.240 y = −0.80 3 Σxy= A= 4004. Use Excel’s Add Trendline feature to derive a polynomial that best approximates the given data.181 -0.3 0.1 1.3 were applied across the terminal of a non−linear device and the current ma (milliamps) values were observed and recorded.032 -0.15 5 6 7 0.972 3.3 2 Σy= 530.160 3.Parabolic Regression A B C D E F G 1 Matrix Inversion and Matrix Multiplication for Example 8.344 3.002 a= -0.0 0.979 -0.20x + 1.15) Therefore.8 where.5 0.820 4.204 4.7.3 1.7.4 The voltages (volts) shown on Table 8. Spreadsheet for the solution of the equations of (8.016 b= 1.10 437.15 79.10 15.37 32331.

05 3. TABLE 8.03 0. it is discussed in probability and statistics textbooks. ISBN 0-9709511-0-8.0.50 1.08 3. Here.4 Experimental Data Volts ma Volts ma 0.14 4.1275x .23 0.75 1.25 0.25 1.50 1.* 2 * It is also discussed in Mathematics for Business.2.8. On the Options tab. we create the plot shown next to the data.18 1. to obtain the plot.25 1. The quantity R is a measure of the goodness of fit for a straight line or.11 0.00 1.23 4.28 0.75 0.25 2.25 1.4 Following the steps of Example 8.00 2.14 0. Plot for the data of Example 8.00 1.00 0.50 0.9997 1 2 3 4 5 Figure 8.00 1.18 0.85 1. However.0.25 0.11 4.42 1. Science.08 0. and on OK.60 0.50 0.Chapter 8 Linear and Parabolic Regression the given data is shown.00 0.01 3.01 0.03 3.75 1.75 0.3 Data for Example 8.50 0.34 0.75 1.50 2. the smooth curve was chosen from the Add trendline feature.50 0.25 0.75 0.0403x 2 + 0. we clicked on Display R squared value on chart.00 0. for parabolic regression.72 1.42 0.63 2.34 Volts Amps 2.75 0.0177 R2 = 0.25 0. as in this example.05 0.18 4.28 5.00 0.50 0.00 1.91 2.00 0.00 0.00 0.00 0.39 2.50 0. and Technology. 8−10 Numerical Analysis Using MATLAB® and Excel®.25 0.50 1.50 0.75 0. This is the Pearson correlation coefficient R . we need to enter all data in Columns A and B. but we clicked on the polynomial order 3 on the Add trendline Type tab.00 0 y = 0. Third Edition Copyright © Orchard Publications .75 0.00 2.0182x 3 .75 2. we clicked on Display equation on chart.25 0.

With MATLAB.Parabolic Regression The correlation coefficient can vary from 0 to 1. Thus. Likewise.5 48. Use n = 1 to compute the best straight line approximation.6 31 34 37 40 42. Third Edition Copyright © Orchard Publications 8−11 . Thus.1 54 56. there is no relationship between the dependent y and independent x variables. MATLAB returns the value of the polynomial at point x. xlabel('T'). % This is the script for Example 8.R. n=1'). Example 8.y. % y−axis data axis([−10 110 20 60]).6 45. If n = 2 . the result of Example 8. regression is performed with the polyfit(x. where x and y are the coordinates of the data points. Let p denote the polynomial (linear.R. cubic.y.x) command to evaluate the best line approximation p in the 0 ≤ T ≤ 100 range in ten degrees increments. % Fits a first degree polynomial (straight line since n =1) and returns % the coefficients m and b of the straight line equation y = mx + b 2 2 Numerical Analysis Using MATLAB® and Excel®.1). When R ≈ 0 . or higher order) approximation that is computed with the MATLAB polyfit(x.5 % T= [ 0 10 20 30 40 50 60 70 80 90 100].n) function. If x is a row vector.x) function to evaluate the polynomial.1 using the MATLAB’s polyfit(x. the polynomial is evaluated for all values of the vector x. When R ≈ 1 . there is a nearly perfect fit between the cubic polynomial and the experimental data. and compute the percent error (difference between the given values and the polynomial values). Use also the polyval(p. Plot resistance R versus temperature T in the range – 10 ≤ T ≤ 110 °C . linear regression. if n = 3 . Suppose we want to evaluate the polynomial p at one or more points. ylabel('R'). quadratic. and returns the coefficients m and b . % Establishes desired x and y axes limits plot(T. it computes the best quadratic polynomial approximation and returns the coefficients of this polynomial. and so on.4 indicates that there is a strong relationship between the variables x and y . that is. We can use the polyval(p.5 Repeat Example 8. there is a nearly perfect relationship between these variables. If x is a scalar. that is. and n is the degree of the polynomial.'*b'). hold % Hold current plot so we can add other data p=polyfit(T.7]. MATLAB computes the best straight line approximation.y.n) function. it computes the best cubic polynomial approximation. Solution: The following MATLAB script will do the computations and plot the data.n) command.3 51. % Display experimental (given) points with asterisk % and smoothed data with blue line grid. title('R (Ohms) vs T (deg Celsius. % x−axis data R=[27. if n = 1 .

format bank % Two decimal place display will be sufficient disp('Smoothed R values evaluated from straight line are:').T) % Compute and display the values of the fitted % polynomial at same points as given % (experimental) values of R R_exper = R % Display the experimental values of R for comparison % The statement below computes the percent error between % the fitted polynomial and the experimental data disp('% Error at points of given values is:') % The percent error is computed with the following statement error=(R_smoothed−R_exper).5 MATLAB also displays the following data: Coefficients m and b are: 0. q=polyval(p.9. Plot for Example 8.*100.9. R_smoothed=polyval(p. 60 R (Ohms) vs T (deg Celsius. disp(p). n=1 55 50 45 R 40 35 30 25 0 10 20 30 40 50 T 60 70 80 90 100 Figure 8.a). plot(a.Chapter 8 Linear and Parabolic Regression % Define range to plot the polynomial % Compute p for each value of a % Plot the polynomial % Display the coefficients m and b fprintf('\n') % Insert line disp('Coefficients m and b are:').2881 28.1227 Smoothed R values evaluated from straight line are: R_smoothed = 8−12 Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications .q) The plot for the data of this example is shown in Figure 8./R_exper format short % Return to default format a=0: 10: 100. fprintf('\n').

63 0.1 54.29 Column 11 56.0 34. % 2nd column of matrix y(:.53 45.1)=T'.4f\t %5./R_exper.01 -0.1).0 37. Third Edition Copyright © Orchard Publications 8−13 .6 45.17 -0.00 34. error=(R_smoothed−R_exper).89 0.10 40.14 -0.70 % Error at points of given values is: error = Columns 1 through 5 1.00 51.02 Column 11 0.4f\n'. R_exper = R.12 31.30 Column 11 56. % x−axis data R=[27.60 45. % 1st column of matrix y(:.0 42.50 48.88 Columns 6 through 10 42.4).Parabolic Regression Columns 1 through 5 28. y=zeros(11. % 4th column of matrix fprintf(' \n'). % 3rd column of matrix y(:.41 48. % y−axis data p=polyfit(T.3)=R_smoothed'.T).6 31.R.65 54. R_smoothed=polyval(p.5 48.4)=abs(error)'.00 -0.09 Numerical Analysis Using MATLAB® and Excel®.2)=R_exper'. T= [0 10 20 30 40 50 60 70 80 90 100].17 39.77 51.*100.3 51.93 R_exper = Columns 1 through 5 27.0 40.34 Columns 6 through 10 -0.00 54.y') 36.05 37. The following MATLAB script will do that and will display the error in absolute values.88 0.7].4f\t %5.0 56.41 We can make the displayed data more presentable by displaying the values in four columns.60 31.00 Columns 6 through 10 42.00 33. % Construct an 11 x 4 matrix of zeros y(:.20 -0.0f\t %5. % Insert line fprintf('%3. % Insert line fprintf('Temp \t Exper R\t Smoothed R \t |Error| \n') fprintf(' \n').

Use the power series method to derive a polynomial that best approximates the given data.91 2.0226 0.00 0. we can draw a smooth curve and compute the coefficients of a power series by approximating the derivatives di ⁄ dv with finite differences Δi ⁄ Δv .8939 0.50 0.11 4.28 5.0117 0.75 1.5000 48. % Insert line When this script is executed.1000 54.50 0.5273 45.10.8845 36.60 0.0000 37.05 3.6000 31.6464 42.4089 8.0036 33.6 The voltages (volts) shown in Table 8.1227 31.4.23 4.00 0.00 0.63 2.01 3.1700 54.75 0.3396 0.4 Data for Example 8. Example 8.00 1.25 0.1370 0.6339 0.4082 48. Third Edition Copyright © Orchard Publications .00 1.50 0.8841 0.18 4. 8−14 Numerical Analysis Using MATLAB® and Excel®.0509 56.0000 56.08 3.0000 42.75 0.39 2.75 0.00 0.50 0.14 4.4 Regression with Power Series Approximations In cases where the observed data deviate significantly from the points of a straight line. TABLE 8.25 0.25 1.25 0.7655 39.6000 45.0000 34.00 2.2018 0.50 0.72 1.75 0.0000 40.34 Solution: We begin by plotting the given data and we draw a smooth curve as shown in spreadsheet of Figure 8.2891 51.6 Experimental Data Volts ma Volts ma 0.1707 0.50 1.7000 28. MATLAB displays the following where the error is in percent. and the current ma (milliamps) values were observed and recorded.Chapter 8 Linear and Parabolic Regression fprintf(' \n').42 0. Temp 0 10 20 30 40 50 60 70 80 90 100 Exper R Smoothed R |Error| 27. The following example illustrates the procedure. were applied across the terminal of a non−linear device.03 3.9318 1.18 1.0943 0.25 0.85 1.3000 51.00 1.

50 0.20 0.20 1.00 1.25 4.14 4.5.00 4.25 0.00 1.02 Figure 8.00 2.50 0.01 0.00 0.14 0.5 Data for the first derivative Smoothed Data for Computation of Δi / Δv Volts ma Volts ma 0.75 4.03 0.18 1. 2.72 1.80 0.11.00 1. i | v =0 = i(0) = −0.25 3. In cell E4 we enter the formula =(B5-B4)/(A5-A4) and we copy it down to E5:E23.02 2.11 2.41 Next.04 3.50 4.25 0.72 0.10 we read the voltmeter reading and the corresponding smoothed ma readings and enter the values in Table 8.75 3.75 1.00 3.01 1.00 0.85 1.00 0.18 0.00 0.6 Using the plot of Figure 8. …20 To facilitate the computations. TABLE 8.25 2.00 0.25 0.42 0. Numerical Analysis Using MATLAB® and Excel®.20 1.60 0. we enter these values in the spreadsheet of Figure 8.75 0.60 0.60 0.50 0.23 0.40 2.40 1.27 5.25 1.75 0.50 0.75 0.25 1.75 2.06 3.11 4. Third Edition Copyright © Orchard Publications 8−15 .00 0.50 1.20 0 1 2 3 v 4 5 6 Smoothed Experimental Data From this plot.75 5.00 1.75 1.49 0.50 0. we compute Δ i ⁄ Δ v for i = 1.00 0.25 0.00 ma 0.00 1.89 2.33 −0.85 1.50 2.50 0.18 4.Regression with Power Series Approximations Experim ental volts 0.60 1.50 3.40 0.09 3.05 0.00 -0.91 ma 0. Spreadsheet for Example 8.01 3.22 4.34 0.63 2.10.39 1.08 0.50 1.25 0.80 1.28 0.63 1.75 0.

Finally.50 3.80 0.25 2.40 1.04-(0.16 0.12v + 0.00 0.06 0.08 0.01-(-0.12v – 0. Spreadsheet for computation of Δi ⁄ Δv in Example 8.08 )v 2! = – 0.6 Next.02 2 2 2 2 2 2 2 (8. for this example we will consider only the first three terms of the polynomial whose coefficients i.01))/(0.02))/(0.50 0. However.04 … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … 1.18 0.60 0.08 0.12 0.00 3.72 0.11 0.75 1. we plot Δ i ⁄ Δ v versus volts and again we smooth the data as shown in Figure 8.25-0.49 0. Following the same procedure we can find higher order derivatives.04 0.63))/(0.25 3.13.44 0.25 1.64 0.85 1. Δi ⁄ Δv and best fits the given data is Δi ⁄ Δv .14. the polynomial that 1.32 0.12.52 0. all three evaluated at v = 0 and are read from the plots.12 0.48 0.00)= 0.12 0.09 0.75 4. Third Edition Copyright © Orchard Publications .00 2.25-0.75 5.25-0.20 0.75 3.22 0. and from these we compute Δ i ⁄ Δ v . The smoothed values of the plot of Figure 8.02 + 0.00 B Smoothed ma -0.′′ 2 i ( v ) = i ( 0 ) + i′ ( 0 ) + ---.00 4.01 1.50 4.75 2.63 Δi20 / Δv20= (1.01 0.16 0.50 1.25 0.00)= Figure 8.27 0.04v + 0. we plot the computed values of Δi ⁄ Δv versus v and again we smooth the data as shown in the spreadsheet of Figure 8. Therefore.12 0.25 4.i ( 0 ) + … = – 0.24 0.92 1.Chapter 8 Linear and Parabolic Regression A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Volts 0.14 0.32 0.89-(1.41 0.76 0.5 ( – 0.11.12 are shown in Figure 8.50 2.02 0.00)= Δi2 / Δv2= (0.16) 8−16 Numerical Analysis Using MATLAB® and Excel®.33 0.00 1.20 1.89 C D E Computed Δi / Δv Δi1 / Δv1= (0.

32 0.50 2.08 0.16 0.24 0. Numerical Analysis Using MATLAB® and Excel®.50 4.16 0.75 2.76 0.12 0.20 Figure 8.00 4. The MATLAB script below computes the smoothed line and produces the plot shown on Figure 8.00 1.49 0.8 0. In this example we will use n = 3 as we did with Excel.7 Repeat Example 8.02 0.y.72 0.25 4.60 0.6 Example 8.00 3.14 0.80 0.12 0.12 Δi / Δv -0.01 0. Solution: With MATLAB. higher degree polynomial regression is also performed with the polyfit(x.50 3.n) function.40 1.25 3.18 0.92 1.75 5.09 0.15.64 0.20 0.2 0.00 Δi / Δv 0.08 0.75 1.11 0.y.4 using the MATLAB polyfit(x.25 1.n) function.44 0.04 Smoothed Δ i / Δ v 1.48 0.50 0. Use n = 3 to compute the best cubic polynomial approximation.06 0.75 3.12. Plot to obtain smoothed data for Δi ⁄ Δv in Example 8.52 0.12 0.33 0.25 2.0 0.12 0.75 4.27 0.6 0.0 0 1 2 volts 3 4 5 1.25 0.4 From this plot.01 0.22 0.89 1.85 1.50 1. (Δi / Δv) | v=0 = i'(0) = 0.32 0.00 0. Third Edition Copyright © Orchard Publications 8−17 .2 1.41 0.00 2.04 0. where n ≥ 2 .63 1.Regression with Power Series Approximations Com puted Volts 0.

24 0.00 0.25 0.24 0.25-0.25 0.20 0.00)= -0.25 1.56 0.35 0.75 4 4.75 2 2.29 0. 3.36 0.12 0.'+r'). % Define range to plot the polynomial q=polyval(p.10 0.5 3.34 0.ma.82 0.25 4..25-0.50 4.00 2.04 0.5 1.91].03 0.32 0.08 0.25 3.04 0.92)/(0.20 0.01 0.25 2.11-0.25 2.75 1 1.63 1.25 3. Third Edition Copyright © Orchard Publications .00 1.00 0.48 0.73 0.11 0.00 1.a).75 2.60 0.50 2.92 Δi / Δv21= / 2 Δv 2= (0.23 0.44 … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … (1.36 0.00)= (0.ma.75 5].04 -0.00)= 1.12 0.39 1.44 0.32 0.75 3. % y−axis data axis([−1 6 −1 2])..10-011)/(0.3) % Fits a third degree polynomial to % the data and returns the coefficients % of the polynomial (cubic equation for % this example since n=3) a=0:0.5 0.12)/(0.25 4.03-0.41 0.85 1.25-0.13.16 0.28 0.28.04 0.5 4..14 0.12 0.00 3.14 0... grid % Indicate data points with + and straight line in red % hold % hold current plot so we can add other data disp('Polynomial coefficients in descending order are: ') % p=polyfit(v.11 0.75 1.00 2 2 0.75 5.50 0.75 4.50 0. % x−axis data ma=[0 0.17 0.64 0.18 0.6 v=[0 0.5 2.42 0.24 0.25 1.03 Δi220 / Δv220= Figure 8. Spreadsheet for computation of Δi ⁄ Δv in Example 8.50 3.12 0.11 0.40 0..50 1.18 1.00 4.05 0. 0.Chapter 8 Linear and Parabolic Regression A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 B C D E Computed 2 2 Δi / Δv 2 1 2 Δi 2 Smoothed Δi/Δv Volts 0.75 3.10 0.25:5.08 0.72 0. % Establishes desired x and y axes limits plot(v.% Calculate p at each value of a % continued on the next page 8−18 Numerical Analysis Using MATLAB® and Excel®.

n=3').*100.28 0.04 0.04 0.1 0 3 From this plot. Third Edition Copyright © Orchard Publications 8−19 . % Construct a 21 x 4 matrix of zeros y(:.36 0.50 Δ i2 / Δ v2 -0.00 4.92 4 5 0.6 % plot(a.32 0.25 0.04 -0.1)=v'.14. % Calculate the values of the fitted polynomial ma_exper = ma.20 0.00 0. xlabel('v').50 1.25 4.00 3.41 0.12 0.10 0.24 0./(ma_exper+eps).3 0.00 0.40 0. title('milliamps vs volts.4)=abs(error)'.Regression with Power Series Approximations Com puted Volts 0.25 3.14 0.08 0. Plot to obtain smoothed data of Δi ⁄ Δv in Example 8.10 0.11 0.12 0.48 0.2 0.44 2 2 Smoothed Δ i / Δ v 0. % 3rd column of matrix y(:.3)=ma_smooth'.75 1.32 0..08 v 2 2 0.11 0.12 0.q).24 0.29 0. ylabel('ma') % Plot the polynomial % Display actual.36 0..5 0.75 4.50 2.1 0.17 0.4 0.25 1.16 0. % 1st column of matrix y(:.0 -0.82 0.25 2.12 0. (Δi 21 Δv2) | v=0 =2 / i''(0) = − 0. % Insert line % continued on the next page Numerical Analysis Using MATLAB® and Excel®.2)=ma_exper'.73 Figure 8.00 2.00 1.20 0.4).64 0.75 2. % 4th column of matrix fprintf(' \n').04 0.v). % The following statement computes the percent error between the % smoothed polynomial and the experimental (given) data error=(ma_smooth−ma_exper).24 0.35 0. smoothed and % error values ma_smooth=polyval(p..50 3.56 0.75 3. % 2nd column of matrix y(:.50 0. % y=zeros(21.

61614 25.01197 0.69226 3.78451 3.00 0.51632 2.0403 0.16677 3.23000 0.08775 0. Polynomial coefficients in descending order are: p = 0.75 1.11433 0.05797 1.57123 8−20 Numerical Analysis Using MATLAB® and Excel®.22191 0.2f\t %7.28000 0. fprintf(' \n').1275 -0.5f\n'.15.5 0 -0.11000 0.25 1.14441 0.00 2.33393 0.5 1 1.5 0 0.75 3.93513 3.05000 0.42000 0. fprintf('%3.14852 0.18000 0.00 1.17970 0.06298 0.03828 0.59657 |%Error| 7955257388080461.Chapter 8 Linear and Parabolic Regression 2 milliamps vs volts.0182 -0. Plot for Example 8.74402 27.03000 0. n=3 1.25 2.5 v 3 3.00000 0.5 1 ma 0.01000 0.58785 1.7 fprintf('volts \t Exper ma\t Smoothed ma \t |%%Error| \n').5f\t %7.17324 0.5 5 Figure 8.34000 0.14000 0.08000 0.00 3.60000 -0.50000 0.5f\t %7.40716 0.01766 0.25 Exper ma Smoothed ma 0.95052 9.5 4 4.5 2 2.y') fprintf(' \n'). Third Edition Copyright © Orchard Publications .49413 0.50 1.00000 19.75 2.50 2.0177 volts 0.27275 0.25 0. MATLAB computes and displays the following data.50 0.

25 4.01374 1.. b. y ( 4 ).n) and polyval(p. y ( 16 ) c.Regression with Power Series Approximations 3. compute y ( 0 ).28020 0.16. y ( 10 ).50 3. grid.17) is shown in Figure 8.63155 1.54911 1. We added eps to avoid division by zero. Solution: a. % and ninth degree polynomials % continued on the next page Numerical Analysis Using MATLAB® and Excel®. y ( 12 ). % of x and y with fifth.y. y ( 6 ).39000 1.7). title('(sinx)/x curve for x > 0') The plot for the function of (8. The fplot function below plots y = sin x ⁄ x .9). y=sin(x). fplot('sin(x). plot y versus x for these values and use the MATLAB polyfit(x.y. Example 8.8 Use MATLAB to a.75 4.89005 0. y ( 2 ).00 4.[0 16 −0.85000 1. p9=polyfit(x. b.5 1])../(x+eps) p7=polyfit(x.40048 1.71618 0.91000 0.85467 1.19511 1.00000 1.75 5.18000 1.37399 1.17) in the interval 0 ≤ x ≤ 16 radians. x=0:2:16. plot the function y = sin x ⁄ x (8.63000 1.53040 0. We use the script below to evaluate y at the specified points.04436 We will conclude this chapter with one more example to illustrate the uses of the MATLAB polyfit(x.50 4.x) functions. Third Edition Copyright © Orchard Publications 8−21 .72000 0.75362 0.n) and polyval(p./(x+eps)'.x) functions to find a suitable polynomial that best fits the x and y data.y.y. y ( 14 ).09538 1. y ( 8 ).00 0.. seventh.

4546 −0.3]. x_span). hold off format short e % Exponential short format disp('The coefficients of 5th order polynomial in descending order are:') p5_coef=polyfit(x.5).'−−'.0.3]. grid.y.p7_pol. p5=polyfit(x.4.y. '9th degree polynomial').y_ref.2.y_ref−0.0466 0.5 0 2 4 6 8 10 12 14 16 Figure 8. x=[0 2 4 6 8 10 12 14 16].y.1. x_span).x.'*').p9_pol. x_span.p5_pol.x_ref. % The following are line legends for each curve plot(x_ref. plot(x_span.5 0 -0.5) disp('The coefficients of 7th order polynomial in descending order are:') p7_coef=polyfit(x.1. '5th degree polynomial').16.5.1: 16. x_span.0708 −0. hold on.3.5.'. '7th degree polynomial').y.1.0544 −0.7) disp('The coefficients of 9th order polynomial in descending order are:') p9_coef=polyfit(x.'−.'−').9) format short % We could just type format only since it is the default 8−22 Numerical Analysis Using MATLAB® and Excel®.5. % Fits the polynomial to the data x_span=0: 0.y.1. p9_pol=polyval(p9.9. text(5.0447 0.y_ref−0. text(5. % Specifies values for x−axis p5_pol=polyval(p5.1892 −0. % The following two statements establish coordinates for three legends % in x and y directions to indicate degree of polynomials x_ref=[2 5. % The following are text legends for each curve text(5. y_ref=[1.'−−'. Third Edition Copyright © Orchard Publications .'−'.3.'. y=[1 0.Chapter 8 Linear and Parabolic Regression 1 (sinx)/x curve for x > 0 0. The script for finding a suitable polynomial is listed below. Plot for Example 8. % Compute the polynomials for this range of x values. p7_pol=polyval(p7.0180].x_ref.1237 −0. x_span).8 c.'−.

17. 1.4 0 2 4 6 8 10 12 14 16 Figure 8. 7th.5865e-006 6.1923e-006 9. Polynomials for Example 8.8 0. Third Edition Copyright © Orchard Publications 8−23 .0444e-008 1.5032e-004 -9.9437e-002 1. The coefficients of 5th order polynomial in descending order are: p5_coef = 6.4 5th degree polynomial 1.17.0293e+000 The coefficients of 7th order polynomial in descending order are: p7_coef = Columns 1 through 6 2.Regression with Power Series Approximations The 5th.6672e-004 -5. and 9th order polynomials are shown below.3560e-001 Columns 7 through 8 7.2 0 -0.5825e-003 1.4318e-004 -4.2 -0.0067e-002 -1.4 0.6 0.9965e-001 p9_coef = Columns 1 through 6 -1.2 7th degree polynomial 1 9th degree polynomial 0.6483e-006 -1.8 The coefficients of the 5th.0000e+000 Numerical Analysis Using MATLAB® and Excel®.6529e-001 -1.1644e-003 -9.2092e-002 3.8340e-005 4.0057e-001 0 4.2508e-001 9.4572e-002 -1.7650e-003 Columns 7 through 10 -8. and 9th order polynomials are shown in Figure 8. 7th.9165e-001 The coefficients of 9th order polynomial in descending order are: -4.

Third Edition Copyright © Orchard Publications . If it is a parabola. • Regression is the process of finding the dependent variable y from some data of the independent variable x . 8−24 Numerical Analysis Using MATLAB® and Excel®. With this method. etc. Regression can be linear (straight line) or curved (quadratic.Chapter 8 Linear and Parabolic Regression 8. we compute the coefficients m (slope) and b (y-intercept) of the straight line equation y = mx + b such that the sum of the squares of the errors will be minimum. b. Σy = sum of the numbers y Σxy = sum of the numbers of the product xy . cubic.) • The best fitting straight line or curve has the property that d 1 + d 2 + … + d 3 = minimum and it is referred to as the least−squares curve. The values of m and b can be found from the relations ( Σx )m + ( Σx )b = Σxy 2 2 2 2 where ( Σx )m + nb = Σy Σx = sum of the numbers x . A straight line that satisfies this property is called a least squares line. Σx = sum of the numbers x squared n = number of data x 2 The values of m and b are computed from D1 m = ----Δ Σx Σx Σx n 2 where Δ = D2 b = ----Δ Σxy Σx Σy n Σx Σxy Σx Σy 2 2 D1 = D2 = • We find the least−squares parabola that fits a set of sample points with y = ax + b + c where the coefficients a.5 Summary • Curve fitting is the process of finding equations to approximate straight lines and curves that best fit given sets of data. • We perform linear regression with the method of least squares. we call it a least−squares parabola. and c are found from ( Σx )a + ( Σx )b + nc = Σy ( Σx )a + ( Σx )b + ( Σx )c = Σxy ( Σx )a + ( Σx )b + ( Σx )c = Σx y 4 3 2 2 3 2 2 where n = number of data points.

if n = 3 . • In cases where the observed data deviate significantly from the points of a straight line. Likewise. If n = 2 . where x and y are the coordinates of the data points. if n = 1 . regression is performed with the polyfit(x. Numerical Analysis Using MATLAB® and Excel®.Summary • With MATLAB. and n is the degree of the polynomial.y. it computes the best cubic polynomial approximation. Third Edition Copyright © Orchard Publications 8−25 .n) command. and returns the coefficients m and b . linear regression. Thus. that is. and so on. it computes the best quadratic polynomial approximation and returns the coefficients of this polynomial. MATLAB computes the best straight line approximation. we can draw a smooth curve and compute the coefficients of a power series by approximating the derivatives dy ⁄ dx with finite differences Δy ⁄ Δx .

11). Repeat Exercise 2 above using Excel’s Trendline feature.45 120 0.x) functions. 3. The sales during these years are shown on the next page.70 180 0.1 to compute the straight line equation that best fits the given data.n) and polyval(p.55 140 0. 5.6 Exercises 1. Consider the system of equations below derived from some experimental data.y. Third Edition Copyright © Orchard Publications . 4.60 160 0.10) and (8. In a non−linear device. measurements yielded the following sets of values: millivolts milliamps 100 0. 2. 2x + y = – 1 x – 3y = – 4 x + 4y = 3 3x – 2y = – 6 – x + 2y = 3 x + 3y = 2 Using the relations (8.85 Use the procedure of Example 8. find the values of x and y that best fit this system of equations.Chapter 8 Linear and Parabolic Regression 8. A sales manager wishes to forecast sales for the next three years for a company that has been in business for the past 15 years.80 200 0. 8−26 Numerical Analysis Using MATLAB® and Excel®. Repeat Exercise 2 above using the MATLAB’s polyfit(x.

y.678.687 28.321 148.548 13.837 207.149.369 72.456. Third Edition Copyright © Orchard Publications 8−27 . Numerical Analysis Using MATLAB® and Excel®.n) and polyval(p. Repeat Exercise 5 above using the MATLAB polyfit(x.048.547.873.127 39. compute the sales for the next three years. 6.Exercises Year 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Sales $9.987 Using Excel’s Trendline feature. choose an appropriate polynomial to smooth the given data and using the polynomial found.642.784 54. You may round the sales to the nearest thousand.547.352 204.x) functions.147.453.782 89.632 206.983 176.163.147.456.545.574 130.745 19.216 112.456.

Chapter 8 Linear and Parabolic Regression 8.039 8−28 Numerical Analysis Using MATLAB® and Excel®.7 Solutions to End−of−Chapter Exercises 1. A B C D E F G H I J 1 Spreadsheet for Exercise 8. Third Edition Copyright © Orchard Publications .172 and y = 1.1 2 2 2 a b c a ab b ac bc 3 4 5 2 1 -1 4 2 1 -2 -1 6 1 -3 -4 1 -3 9 -4 12 7 1 4 3 1 4 16 3 12 8 3 -2 -6 9 -6 4 -18 12 9 -1 2 3 1 -2 4 -3 6 10 1 3 2 1 3 9 2 6 11 7 5 -3 17 -2 43 -22 47 12 Σ 13 2 Σa Σab 14 17 -2 15 Δ = = 727 2 Σab Σb 16 -2 43 x=D1/Δ= -1.172 17 Σac Σab 18 -22 -2 19 D1 = = -852 2 Σbc Σb 20 47 43 y=D2/Δ= 1. We construct the spreadsheet below by entering the given values and computing the values from the formulas given.039 21 2 Σa Σac 22 17 -22 23 D2 = = 755 Σab Σbc 24 -2 47 Thus. x = – 1.

Third Edition Copyright © Orchard Publications 8−29 .80 0.2 x (mV) y(mA) 100 120 140 160 180 200 900 x2 xy 45 66 84 112 144 170 621 Milliam ps versus Millivolts 1.45 10000 0.004x + 0.70 25600 0.Solutions to End−of−Chapter Exercises 2.55 14400 0.0 142000 900 900 = 6 m=D1/Δ = 0.85 40000 3.004 900 = 6 b=D2/Δ = 0. y = mx + b = 0.40 100 0. We construct the spreadsheet below by entering the given values and computing the values from the given formulas.00 Milliamps 0.0476 Numerical Analysis Using MATLAB® and Excel®.60 0.95 142000 120 140 160 180 200 Millivolts Σx 2 Σx = n Σx = n Σ xy = Σy 142000 900 621 4. Spreadsheet for Exercise 8.60 19600 0.0 2000 171 42000 Σx Σ xy Σy 2 Σx Σx Thus.80 32400 0.0476 621 = 4.

hold % Hold current plot so we can add other data p=polyfit(mv. title('ma (milliamps) vs mv (millivolts. % Define range to plot the polynomial q=polyval(p.004 900 = 6 b=D2/Δ = 0. % Compute p for each value of a plot(a. Trendline for Exercise 8.60 19600 0. xlabel('mv').70 25600 0. we obtain the trendline shown below.60 0.ma.Chapter 8 Linear and Parabolic Regression 3.2. Third Edition Copyright © Orchard Publications .80 0.0 142000 900 900 = 6 m=D1/Δ = 0. 8−30 Numerical Analysis Using MATLAB® and Excel®. % Fits a first degree polynomial (straight line since n =1) and returns % the coefficients m and b of the straight line equation y = mx + b a=0: 10: 200.55 0.45 10000 0.45 0.0 2000 171 42000 Σx Σ xy Σy Σx 2 Σx 4. % x-axis data % y-axis data % Establishes desired x and y axes limits % Display experimental (given) points with % asterisk and smoothed data with blue line grid.85].85 40000 3.0476 621 = 4.1). plot(mv.70 0. ylabel('ma'). axis([100 200 0 1]).80 0.a).40 100 0. n=1').95 142000 120 140 160 180 200 Millivolts Σx 2 Σx = n Σx = n Σ xy = Σy 142000 900 621 4.80 32400 0.55 14400 0.'*b').ma. ma=[0.q) % Plot the polynomial % Display the coefficients m and b fprintf('\n') % Insert line mv= [100 120 140 160 180 200].00 Milliamps 0.3 x (mV) y(mA) 100 120 140 160 180 200 900 x2 xy 45 66 84 112 144 170 621 Milliam ps versus Millivolts 1. Following the procedure of Example 8.60 0.

% Insert line fprintf('%3. fprintf('\n'). disp(p). % The percent error is computed with the following statement error=(ma_smoothed-ma_exper). % 4th column of matrix fprintf(' \n').4)=abs(error)'.4f\n'.3)=ma_smoothed'.6000 0.Solutions to End−of−Chapter Exercises disp('Coefficients m and b are:').8 0. Third Edition Copyright © Orchard Publications 8−31 .5500 0. % Display the experimental values of ma for comparison % The statement below computes the percent error between % the fitted polynomial and the experimental data % disp('% Error at points of given values is:').7805 0. n=1 Exper ma Smoothed ma 0. format short % Return to default format y=zeros(6.4f\t %5.5108 2.8000 0.4500 0.2 0. % Insert line Coefficients m and b are: 0.0582 2. % Construct an 6 x 4 matrix of zeros y(:.4f\t %5. % Insert line fprintf('mv \t Exper ma\t Smoothed ma \t |Error| percent \n') fprintf(' \n').6 ma 0.4405 1.4 0.7000 0. % Compute the values of the fitted polynomial at % same points as given (experimental) values of ma ma_exper = ma./ma_exper.2)=ma_exper'.5 0.8619 Numerical Analysis Using MATLAB® and Excel®.4006 ma (milliamps) vs mv (millivolts.0041 mv 100 120 140 160 180 200 0. % 3rd column of matrix y(:.6990 0.1361 2.4548 0.y') fprintf(' \n').4).0f\t %5.8500 0. format bank % Two decimal place display will be sufficient ma_smoothed=polyval(p.mv).1)=mv'.1 0 0 20 40 60 80 100 mv 120 140 160 180 200 0.7 0.3 0.5362 0.*100. % 1st column of matrix y(:.9365 0.0476 |Error| percent 1.9 0.6176 0. % 2nd column of matrix y(:.

9966 258000000 208000000 158000000 108000000 58000000 8000000 0 5 10 15 20 The sales for the next 3 years are from the equation above produced by Excel. % Display experimental (given) points with % asterisk and smoothed data with blue line hold % Hold current plot so we can add other data grid.sales.. % y-axis data plot(year. we choose Polynomial 4 and we obtain the trendline shown below.2E+06x 2 + 1E+07x . 1 2 3 4 5 6 7 8 9 10 11 12 13 14 9149548 13048745 19147687 28873127 39163784 54545369 72456782 89547216 112642574 130456321 148678983 176453837 207547632 206147352 y = -17797x 4 + 436354x 3 .'*b'). xlabel('Years'). p=polyfit(year. fprintf('\n').sales. % Compute p for each value of a plot(a. in most cases. We will compare these values with the results of Exercise 6. ylabel('Yearly Sales'). These results indicate that non-linear interpolation is. 8−32 Numerical Analysis Using MATLAB® and Excel®. 15. title('Yearly Sales vs Years. Third Edition Copyright © Orchard Publications . % x-axis data sales=[9149548 13048745 19147687 28873127 39163784 .. % Fits a first degree polynomial (n=4) and returns % the coefficients of the polynomial a=linspace(0.. 15). 148678983 176453837 207547632 206147352 204456987].Chapter 8 Linear and Parabolic Regression 5. unreliable.. n=4'). disp(p).a). year= [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15].2E+06 R2 = 0. Following the procedure of Example 8.q) % Plot the polynomial % Display coefficients ofpolynomial fprintf('\n') % Insert line disp('Coefficients are:').4.4). y 16 = – 17797x + 436354x – 2 × 10 x + 10 x – 2 × 10 y 17 = – 17797x + 436354x – 2 × 10 x + 10 x – 2 × 10 y 18 = – 17797x + 436354x – 2 × 10 x + 10 x – 2 × 10 4 3 6 2 7 4 3 6 2 7 4 3 6 2 7 6 x = 16 6 x = 17 6 x = 18 = 266961792 = 247383965 = 206558656 6. % Define range to plot the polynomial q=polyval(p. 54545369 72456782 89547216 112642574 130456321 .

35 11. y=zeros(15. Third Edition Copyright © Orchard Publications 8−33 . fprintf('year\t Exper sales\t Smoothed sales \t |Error| percent \n') fprintf(' \n').*100.0f\t %5.5 Yearly Sales 1 0.67 11.2415 Yearly Sales vs Years. % Display the experimental values of ma for comparison % The statement below computes the percent error between % the fitted polynomial and the experimental data % The percent error is computed with the following statement error=(sales_smoothed-sales_exper).year). fprintf('%2.5 x 10 8 0.5 2 1. % 1st column of matrix y(:.y') fprintf(' \n').Solutions to End−of−Chapter Exercises % Compute the values of the fitted polynomial at % same points as given (experimental) values of ma sales_exper = sales.2f\n'. % Construct an 15 x 4 matrix of zeros y(:.0018 2.5 0 -0.63 1.0f\t %9.4).1641 -0. % 2nd column of matrix y(:. % 4th column of matrix fprintf(' \n'). sales_smoothed=polyval(p.0436 -0.1)=year'.2)=sales_exper'. % 3rd column of matrix y(:. Coefficients are: 1.0e+007 * -0.0f\t %9.3)=sales_smoothed'./sales_exper.2386 1.63 Numerical Analysis Using MATLAB® and Excel®. n=4 0 5 Years 10 15 year Exper sales Smoothed sales 1 2 3 4 9149548 13048745 19147687 28873127 7258461 14529217 21374599 29344934 |Error| percent 20.4)=abs(error)'.

Chapter 8 Linear and Parabolic Regression 5 6 7 8 9 10 11 12 13 14 15 39163784 54545369 72456782 89547216 112642574 130456321 148678983 176453837 207547632 206147352 204456987 39563426 52726163 69102111 88533118 110433913 133792104 157168183 178695519 196080363 206601848 207111986 1.63 1.13 1. shown on the previous page. we form the polynomial y = – 1. y18 y16 = 1. linear regression gives the best approximations.415*10^6.415*10^6. y17=−1.8*10^4*x^4+4. x=18. x=17.8*10^4*x^4+4. 8−34 Numerical Analysis Using MATLAB® and Excel®.22 1.4462e+008 y18 = 8.1641 × 10 x – 2.56 5.53 0. As stated above.386*10^6*x^2+1.1641*10^7*x−2.30 From the coefficients produced by MATLAB.36*10^5*x^3−2.36*10^5*x^3−2.36 × 10 x – 2. Third Edition Copyright © Orchard Publications . y16=−1.34 4.36*10^5*x^3−2.1641*10^7*x−2.386*10^6*x^2+1. We should remember that the equations produced by both Excel and MATLAB represent the equations that best fit the experimental values.71 1.8*10^4*x^4+4.1641*10^7*x−2.415*10^6.02 3. y18=−1.27 5. y17.415 × 10 4 4 5 3 6 2 7 6 and from it we find the values of y (the yearly sales) as follows: x=16.7243e+007 These values vary significantly from those of Exercise 5.386*10^6*x^2+1. non-linear interpolation especially for polynomials of fourth degree and higher give inaccurate results. y16.96 2. For extrapolation.8 × 10 x + 4.7923e+008 y17 = 1.386 × 10 x + 1.

4 .y 1( 4 ) h 2 + … 1 2! 3! 4! (9.1).y''' i h i + 1 + ---.5 with the initial condition y ( 0 ) = 1 .( x – a ) n! 2! (n) (9. and Milne’s methods are discussed. Adams’.3) In general.5) correct to four decimal places for values x 0 = 0.2 .y i( 4 ) h i + 1 + … 2! 3! 4! (9. Third Edition Copyright © Orchard Publications 9−1 . x 2 = 0. The Taylor.4) Example 9. x 3 = 0.y''' h 2 + ---. x 4 = 0.( x – a ) + … + ----------------. to minimize the error f ( x 1 ) – y 1 we need to keep h 1 sufficiently small. 9. (9. Letting h 1 = x – a in (9.y''0 h 1 + ---.1 Use the Taylor series method to obtain a solution of y' = – xy x 5 = 0. Runge−Kutta. 1 1 1 2 3 4 y i + 1 = y i + y' i h i + 1 + ---.1 . we obtain: 1 1 1 2 3 4 y 1 = y 0 + y' 0 h 1 + ---. close to x 1 . For another value x 2 > x 1 .1) Now.3 . we can find the approximate value y 1 of f ( x 1 ) by using the first k + 1 terms in the Taylor expansion of f ( x 1 ) about x = a . if x 1 > a is a value close to a . 1112 3 4 y 2 = y 1 + y'1 h 2 + ---. we repeat the procedure with h 2 = x 2 – x 1 .1 Taylor Series Method We recall from Chapter 6 that the Taylor series expansion about point a is n f'' ( a ) f (a) 2 y n = f ( x ) = f ( a ) + f' ( a ) ( x – a ) + ----------.y''1 h 2 + ---.0 .2) Obviously.Chapter 9 Solution of Differential Equations by Numerical Methods T his chapter is an introduction to several methods that can be used to obtain approximate solutions of differential equations.y''' 0 h 1 + ---.y'' i h i + 1 + ---. then. and Numerical Analysis Using MATLAB® and Excel®.y 0( 4 ) h 1 + … 2! 3! 4! (9. Such approximations are necessary when no exact solution can be found. x 1 = 0.

Using the values of the coefficients of y i in (9.0000 0.1 – 0.99 0.4 -0.2 0. x 3 = 0.Chapter 9 Solution of Differential Equations by Numerical Methods Solution: For this example.2 -0. Third Edition Copyright © Orchard Publications .0000 0.0 -1.2 . and x 4 = 0.8) = ( x i – 6x i + 3 )y i 4 2 where x i represents x 0 = 0. 1.1 -0. The first through the fourth derivatives of (9.0080 0.0010 0.0016 -0.00 0.8). we construct the spreadsheet of Figure 9.0640 0.592 2.4681 9 0.0 .3 0.873 2.01 0.000 3. Spreadsheet for Example 9.4 .0000 6 0. y i + 1 = y i + 0.6) for i = 0.7616 8 0.09 0.1 9−2 Numerical Analysis Using MATLAB® and Excel®. and 4 . x 2 = 0.7) = ( – x + 3x ) ( – xy ) + ( – 3x + 3 )y = ( x – 6x + 3 )y 3 2 4 2 We use the subscript i to express them as y' i = – x i y i y'' i = ( x i – 1 )y i y''' i = ( – x i + 3x i )y i yi (4) 3 2 (9.00 0.3 -0.000004y i (4) (9.0001 -0.1 and by substitution into (9.0656 10 0.91 0.16 0.4).000167y''' i + 0.0 = 0.136 2.5) are: y' = – xy y'' = – xy' – y = – x ( – xy ) – y = ( x – 1 )y y''' = ( x – 1 )y' + 2xy = ( x – 1 ) ( – xy )2xy = ( – x + 3x )y y (4) 2 2 2 3 (9. h = x 1 – x 0 = 0. 3.1y' i + 0.1 .4 Figure 9.299 2.005y'' i + 0.0 0. x 1 = 0. 2.96 0.3 .0270 0.0256 -0.84 1.1.0081 -0.9401 7 0.1.1 0.04 0. A B C D E F G H 1 Differential Equation is y' = −xy 2 Numerical solution by Taylor method follows 3 2 3 4 2 3 4 2 xi xi xi -xi xi -1 -xi +3xi xi -6xi +3 xi 4 5 0.

9) (9. and we obtain the following relations: y' 0 = – x 0 y 0 = – 0y 0 = 0 y' 1 = – x 1 y 1 = – 0.99 y 1 y''2 = ( x 2 – 1 ) y 2 = – 0.1.4681y 3 3 y ( 4 ) = ( x 4 – 6x 4 + 3 ) y 4 = 2. are now substituted into (9.9401y 1 1 y ( 4 ) = ( x 2 – 6x 2 + 3 ) y 2 = 2. we obtain: Numerical Analysis Using MATLAB® and Excel®.6).10) (9. Third Edition Copyright © Orchard Publications 9−3 .96 y 2 y''3 = ( x 3 – 1 ) y 3 = – 0.4y 1 y''0 = ( x 0 – 1 ) y 0 = – y 0 y''1 = ( x 1 – 1 ) y 1 = – 0. and H6:H10 of the spreadsheet of Figure 9.11) (9.12) into (9.12) By substitution of (9.8).136y 4 4 y ( 4 ) = ( x 0 – 6x 0 + 3 ) y 0 = 3y 0 0 y ( 4 ) = ( x 1 – 6x 1 + 3 ) y 1 = 2.9) through (9.7616y 2 2 y ( 4 ) = ( x 3 – 6x 3 + 3 ) y 3 = 2.2y 1 y' 3 = – x 3 y 3 = – 0. G6:G10.299y 1 1 y''' = ( – x 2 + 3x 2 ) y 2 = 0.91 y 3 y'' 4 = ( x 4 – 1 ) y 4 = – 0.1y 1 y' 2 = – x 2 y 2 = – 0.873y 3 3 y''' = ( – x 4 + 3x 4 ) y 4 = 1.84 y 1 y''' = ( – x 0 + 3x 0 ) y 0 = 0 0 y''' = ( – x 1 + 3x 1 ) y 1 = 0. and using the given initial condition y 0 = 1 .592y 2 2 y''' = ( – x 3 + 3x 3 ) y 3 = 0.Taylor Series Method The values in E6:E10.0656y 4 4 4 2 4 2 4 2 4 2 4 2 3 3 3 3 3 2 2 2 2 2 (9. F6:F10.3y 1 y' 4 = – x 4 y 4 = – 0.

Third Edition Copyright © Orchard Publications .Chapter 9 Solution of Differential Equations by Numerical Methods y 1 = y 0 + 0.005y''1 + 0.00495 + 0.005 + 0.005 ( – 1 ) + 0.000004y 0 0 (4) = 1 + 0.00167 ( 0 ) + 0.x + C 2 and with the initial condition y = 1 when x = 0 .955993 y 4 = y 3 + 0. 1 ln 1 = – -.98511 ( 0.1y'0 + 0.005y''4 + 0.( 0 ) + C 2 C = 0 –x ⁄ 2 1 2 ln y = – -.005y''0 + 0.1y'3 + 0.000004 ( 3 ) = 1 – 0.000004y 1 1 = ( 1 – 0.18) 9−4 Numerical Analysis Using MATLAB® and Excel®.0048 + 0.00015 + 0.000004y 2 2 = ( 1 – 0.000012 = 0.000167y''' + 0.02 – 0.88249 ----The differential equation dy = – xy of this example can be solved analytically as follows: dx dy = – xdx ----y (4) (4) (9.1 ( 0 ) + 0.99501 (9.980194 y 3 = y 2 + 0.00001 )y 3 = 0.00019 + 0.00005 + 0.15) (4) (9.x 2 or y = e (9.923107 ) = 0.0001 + 0.00001 )y 2 = 0.1y'1 + 0.14) (4) (9.16) (9.923107 y 5 = y 4 + 0.0042 + 0.00001 )y 4 = 0.03 – 0.99501 ) = 0.9656 ( 0.17) ∫ -----y dy = – x dx ∫ 1 2 ln y = – -.95600 ( 0.000167y''' + 0.000004y 4 4 = ( 1 – 0.000167y''' + 0.13) Similarly.005y''3 + 0.01 – 0.00001 )y 1 = 0.1y'4 + 0.00455 + 0.000167y''' + 0.04 – 0.000167y''' + 0.1y'2 + 0.955993 ) = 0.000004y 3 3 = ( 1 – 0. y 2 = y 1 + 0.005y''2 + 0.97531 ( 0.980194 ) = 0.

The applicable formulas are as follows: Numerical Analysis Using MATLAB® and Excel®.( k 1 + k 2 ) 2 For Runge-Kutta Method of Order 2 (9.y i h + … 2! 3! (9.125 = 0. the following formulas are applicable.21) When higher accuracy is desired. We can verify the analytical solution of Example 9. y.18) yields y = e – 0.'x') z = exp(-1/2*x^2) The procedure used in this example. y ) at several points instead of the values of successive derivatives at a single point. Third Edition Copyright © Orchard Publications 9−5 . It differs from the Taylor series method in that we use values of the first derivative of f ( x. y' ) (9.'y(0)=1'.Runge−Kutta Method For x 5 = 0. we need to apply the additional formula 1 1 (4) 3 2 y' i + 1 = y' i + y''i h + ---.8825 and we observe that this value is in close agreement with the value of (9. y n ) k 2 = hf ( x n + h .1 with MATLAB’s dsolve(s) function using the following script: syms x y z z=dsolve('Dy=−x*y'. we can use order 3 or order 4.2 Runge−Kutta Method The Runge−Kutta method is the most widely used method of solving differential equations with numerical methods. For a Runge−Kutta method of order 2. y n + h ) 1 y n + 1 = y n + -. can be extended to apply to a second order differential equation y'' = f ( x.19) In this case.y'''i h + ---. k 1 = hf ( x n .20) 9.17).5 (9.

y n ) = 0.2 .22) (9.. y n ) = l 1 = k 1 m1 -m 2 = hf ⎛ x n + h . we use (9.2 k 2 = hf ( x n + h .( 0. Since we are given that y ( 0 ) = 1 . Third Edition Copyright © Orchard Publications .328 ) = 1.24) given the initial condition y ( 0 ) = 1 .328 2 2 and 1 1 y 1 = y 0 + -.2 ( 0 + 1 ) = 0.264 2 2 (9.( l 1 + 4l 2 + l 3 ) 6 For Runge-Kutta Method of Order 3 m 1 = hf ( x n .( k 1 + k 2 ) = 1 + -. Solution: a. and 4 Runge−Kutta methods with h = 0. y n + ---⎞ ⎝ 2 2⎠ l 3 = hf ( x n + h .21).25) 9−6 Numerical Analysis Using MATLAB® and Excel®.2 + 0.2 from the solution y ( x ) of the differential equation y' = x + y 2 (9.2 Compute the approximate value of y at x = 0. and y = 1 . y n ) = k 1 l1 h l 2 = hf ⎛ x n + -. k 1 = hf ( x n . y n + -----.. For order 2. y n + h ) = 0. y n + ------⎞ ⎝ 2 2⎠ m 4 = hf ( x n + h .2 + ( 1 + 0. we begin with x = 0 .( m 1 + 2m 2 + 2m 3 + m 4 ) 6 For Runge-Kutta Method of Order 4 (9. 3. Use order 2.23) Example 9.Chapter 9 Solution of Differential Equations by Numerical Methods l 1 = hf ( x n . y n + m 3 ) 1 y n + 1 = y n + -.2 [ 0 + 0. Then.2 ) ] = 0.⎞ = l 2 ⎝ 2 2⎠ m2 h m 3 = hf ⎛ x n + -. y n + 2l 2 – l 1 ) 1 y n + 1 = y n + -.

. y. y n ) = l 1 = k 1 = 0.262 + 0. l 1 = hf ( x n .29) The Runge−Kutta method can also be used for second order differential equations of the form y'' = f ( x.2 [ ( 0 + 0. m 1 = hf ( x n . Third Edition Copyright © Orchard Publications 9−7 .2 + 4 × 0. They can be found in differential equations and advanced mathematics texts.27) c. Then. Then.( 0.2 0.2 0 + -----.273 6 6 (9. y n + ------⎞ = 0. Numerical Analysis Using MATLAB® and Excel®.2 2 l1 1 1 h l 2 = hf ⎛ x n + --. y n + 2l 2 – l 1 ) = 0.274 6 (9.⎞ ⎝ 2 2⎠ 2 ⎝ 2 ⎠ 2 (9.22).2⎞ + ⎛ 1 + -.+ ⎛ 1 + -----------.23). For order 4.276 m 4 = hf ( x n + h .276 + 0. but these will not be discussed in this text.2 [ 0 + 0. we use (9.366 and 1 y 1 = y 0 + -.2 ) + ( 1 + 2 × 0.262 – 0.262 2 m 3 = hf ⎛ x n + -. the pair of 3rd−order formulas* are: * Third and fourth order formulas can also be used.Runge−Kutta Method b. y n + --.28) = 0.⋅ 0.30) For second order differential equations. y n + m 3 ) = 0.( 0.( m 1 + 2m 2 + 2m 3 + m 4 ) 6 1 = 1 + -.2 ⎛ 0 + -.( l 1 + 4l 2 + l 3 ) = 1 + -.26) l 3 = hf ( x n + h . y n ) = k 1 = 0. y' ) (9.262 + 2 × 0.366 ) = 1.276 ) ] = 0. we use (9. For order 3.2 ) ] = 0.391 ) = 1.⋅ 0.391 2 and 1 1 y 1 = y 0 + -.2⎞ = 0..2 + ( 1 + 0.2 + 2 × 0. y n + ------⎞ = l 2 = 0.262 ⎠ ⎝ ⎠ ⎝ ⎝ 2 2 2 2⎠ (9.262 ⎝ 2 2⎠ m2 h 0.2 m1 h m 2 = hf ⎛ x n + -.⎞ = 0.

y n . Solution: We are given the values of x 0 = 0 .33) and using (9. y' ( 0 ) = – 1 . We will use h = x 1 – x 0 = 0.. Third Edition Copyright © Orchard Publications .32) with the initial conditions y ( 0 ) = 1 . y 0 = 0 .2 . y' n ) l' 1 l 2 = h ⎛ y' n + ---. We rewrite the given equation as y'' = 2y = 0 ⋅ x + 2y 3 3 (9.( l' 1 + 4l' 2 + l' 3 ) 6 For Runge-Kutta Method of Order 3 2nd Order Differential Equation (9.( l 1 + 4l 2 + l 3 ) 6 1 y' n + 1 = y' n + -.3 Given the 2nd order non−linear differential equation y'' – 2y = 0 3 (9. y n + --.2 . compute the approximate values of y and y' at x = 0. y' 0 = – 1 and we are seeking the values of y 1 and y' 1 at x 1 = 0.2 .Chapter 9 Solution of Differential Equations by Numerical Methods l 1 = hy' n l' 1 = hf ( x n .2 .31) Example 9. y' n + 2l' 2 – l' 1 ) 1 y n + 1 = y n + -. y n + 2l 2 – l 1. Use h = 0.31) we obtain: 9−8 Numerical Analysis Using MATLAB® and Excel®.⎞ ⎝ 2⎠ l1 l' 1 h l' 2 = hf ⎛ x n + --. y' n + ----⎞ ⎝ 2 2 2⎠ l 3 = h ( y' n + 2l' 2 – l' 1 ) l' 3 = hf ( x n + h.

y 0 + 2l 2 – l 1.16 ) – 0.2726 ) = – 0.16 ) – ( – 0.2 ) ] = 0.( l 1 + 4l 2 + l 3 ) = 1 + -.6935 6 6 (9. a set of x values and the corresponding set of y values that represent points of the function y = f ( x ) .4 Use the MATLAB ode23 function to find the analytical solution of the second order nonlinear equation y'' – 2y = 0 3 (9. The second.1634 ) = 0.2 { 0 + 2 [ 1 + 2 ( – 0.( l' 1 + 4l' 2 + l' 3 ) = – 1 + -.4⎞ = – 0. y' 0 + 2l' 2 – l' 1 ) = 0. y 0 + --. y' 0 ) = 0. tspan. The syntax for ode23 is ode23(‘f’.2 0 + 2 ⎛ 1 + --------. Example 9. ode23.31). Both have the same syntax.4 ) = – 0.2 ( – 1 + 2 × 0. uses second and third−order Runge−Kutta methods. y 0.1634 l' 3 = hf ( x 0 + h. in single quotation marks. f. defines the desired time span of the interval over which we want to evaluate the function y = f ( x ) .2 [ 2 ( 1 – 0.2 [ 2 ( 1 – 0.( 0.2 l' 1 = hf ( x 0.8328 6 6 1 1 y' 1 = y' 0 + -.1 ) ] = 0. Third Edition Copyright © Orchard Publications 9−9 .2 [ 2 ( 0. uses fourth and fifth−order Runge−Kutta methods.⎞ = 0.36) Numerical Analysis Using MATLAB® and Excel®.2 3 l' 2 = hf ⎛ x 0 + --. The third argument.34) By substitution into the last two formulas of (9. The first argument.2 ⎛ – 1 + 0.2 ( 0 + 2 × 1 + 0 ) = 0. y0. is the name of the user defined MATLAB function. represents the initial condition or boundary point that is needed to determine a unique solution. The first.2 ) ] + 0 } = 0.y0). we will use the ode23 function in our subsequent discussion. The second.⎞ = 0.35) MATLAB has two functions for computing numerical solutions of Ordinary Differential Equations (ODE).2726 3 3 3 3 3 (9. y' 0 + ---.2 ( 1. ode45.2916 l 3 = h ( y' 0 + 2l' 2 – l' 1 ) = 0.2 ( – 1 ) = – 0.32 + 0. This function produces two outputs.Runge−Kutta Method l 1 = hy' 0 = 0.88 ) ] = 0.⎞ + 0 ⎝ ⎠ ⎝ 2 2 2 2 ⎠ = 0.4 l' 1 -----l 2 = h ⎛ y' 0 + ---.4 + 4 ( 0..tspan. we obtain: 1 1 y 1 = y 0 + -.2916 – 0.458 ) = 0.2916 ) + 0.16 ⎝ ⎝ 2⎠ 2⎠ l1 l' 1 h – 0.( – 0. therefore.2 + 4 ( 0.

−1]. at points y ( 0. These can be found in differential equations textbooks.2*y(1)^3]. The script is shown below.2 ) . y(:. grid The plots for y and y' are shown in Figure 9. function d2y=fex9_4(x.'x') MATLAB displays the following message: Warning: Explicit solution could not be found. Solution: If we attempt to find the analytical solution with the following MATLAB script syms x y y=dsolve('D2y=2*y^3. % Interval over which we want to evaluate y=f(x) y0=[1.2 ) and y' ( 0. in general. '+r−'.y]=ode23('fex9_4'. although few methods are available for special cases. y0). Compare values with those of Example 9.3. plot the numerical solution using the function ode23 for the tspan interval 0 ≤ x ≤ 1 . tspan=[0 1]. The numerical solution for this non−linear differential equation is obtained and plotted with the following script.Chapter 9 Solution of Differential Equations by Numerical Methods with the initial conditions y ( 0 ) = 1 and y' ( 0 ) = – 1 . x. Next.y(0)=1. % Use 2nd and 3rd Order Runge−Kutta % Plot numeric values with the statements below plot(x. non−linear differential equations cannot be solved analytically. by first writing a user defined m−file which we denote as fex9_4. Third Edition Copyright © Orchard Publications . xlabel('x').2 ) and y' ( 0.y). % Given initial conditions [x.Dy(0)=−1'.. tspan. 9−10 Numerical Analysis Using MATLAB® and Excel®. % Output must be a column This file is saved as fex9_4. We observe that the values at points y ( 0.2).3. 'Ob−−') title('Numerical Solution for Differential Equation of Example 9. y(:.1). yprime (lower curve)').2. This warning indicates that MATLAB could not find a closed−form solution for this non−linear differential equation. This is because. we write and execute the script below to obtain the plots for y and y ′ ..2 ) .4').. d2y=[y(2). ylabel('y (upper curve). Then. compare favorably with those that we found in Example 9.

Plot for Example 9. Solution: The analytical solution of (9. Third Edition Copyright © Orchard Publications 9−11 . 'x') y = 1/9*(−3*x^3*log(x)−2*x^3−7)/x y=simple(y) y = (−1/3*log(x)−2/9)*x^2−7/9/x pretty(y) 2 (. compute and plot the numerical solution using the command ode23 along with points of the analytical solution. Then. Dy(1)=0.37) is .5 Use MATLAB to find the analytical solution of x y'' – x y' – 3y = x ln x 2 2 (9.1/3 log(x) .4 Example 9. to verify the accuracy of the numerical solution.37) with the given initial conditions is found with MATLAB as follows: syms x y y=dsolve('x^2*D2y−x*Dy−3*y=x^2*log(x).37) with the initial conditions y ( 1 ) = – 1 and y' ( 1 ) = 0 . y(1)=−1'.2/9) x and therefore.2.Runge−Kutta Method Figure 9.7/9 1/x Numerical Analysis Using MATLAB® and Excel®. the analytical solution of (9.

3./(9.^2).ln x – -. % This is the first derivative of (9. x. % Produces the derivatives of Example 9. anal_yprime.*log(x)−7. tspan. Plot for Example 9.y]=ode23('fex9_5'. logx=lnx % % we let y(1) = y and y(2)=y'.38) anal_yprime=((−2. fex9_5. '−'). title('Numeric and Analytic Solutions of Differential Equation of Example 9. % Use 2nd and 3rd Order Runge−Kutta anal_y=((−1. 'O'./3).3. y(:.^2−7.. x.. we create and save a user defined m−file. % Given initial conditions [x.5 % x^2*y''−x*y'−3*y=x^2*log(x) where y''=2nd der.Chapter 9 Solution of Differential Equations by Numerical Methods 1 2 7 y = ⎛ – -. function d2y=fex9_5(x. x.*log(x)−2. y0). y'=1st der.1)..⎞ x 2 – ----⎝ 3 9⎠ 9x (9.*x). xlabel('x'). tspan=[1 4]. then y(1)'=y(2) % % and y(2)'=y(2)/x^2+3*y(1)/x^2+log(x) % d2y=[y(2)..2). % output must be a column The following MATLAB script computes and plots the numerical solution values for the interval 1 ≤ x ≤ 4 and compares these with the actual values obtained from the analytical solutions. yprime (line with O)')./9). grid The numeric and analytical solutions are shown in Figure 9. % analytic solution of the 2nd order differential equation of (9./3)... '+'.5 9−12 Numerical Analysis Using MATLAB® and Excel®.y). ylabel('y (line with +).*x. Third Edition Copyright © Orchard Publications ./(9. % This is the. y(2)/x+3*y(1)/x^2+log(x)].0].*x+7. '−'. Figure 9.*x. % Interval over which we want to evaluate y=f(x) y0=[−1.38) Next. anal_y. y(:..5').38) % Plot numeric and analytic values with the statements below plot(x./9)..

y 3. Numerical Analysis Using MATLAB® and Excel®.Adams’ Method 9.3. Adams’ method uses the formula 1 5 2 3 3 y n + 1 = y n + h f n + -. Solution: The spreadsheet of Figure 9. Third Edition Copyright © Orchard Publications 9−13 .6 correct to three decimal places using Adams’ method. y n ) Δf n = f n – f n – 1 Δ f n = Δf n – Δf n – 1 2 and so on. and y5 using the third−order Runge−Kutta method as in Example 9. These values can be found by other methods such as the Taylor series or Runge−Kutta methods. Example 9. to form a table of differences.2. 0.5 by the third − order Runge−Kutta method.2.4 and 0. the step from y n to y n + 1 is performed by a formula expressed in terms of differences of f ( x.Δ f n + -.Δ f n + … 2 12 8 (9. 0.6 Given the differential equation y' = 2y + x (9.Δf n + ----. Then.1.39) where h = xn + 1 – xn f n = ( x n.3 Adams’ Method In this method.40) with the initial condition y ( 0 ) = 1 . y ) .4 shows the results of the computations of y 1. y 4 . it is necessary to have several (4 or more) approximate values of y ( x ) in addition to the given initial condition y ( 0 ) . Obviously. find the value of y corresponding to x = 0. 0. compute the approximate values of y for x = 0. y 2.

5*L(1))]= 0.2267)= 0.1000 0.5*L(1)) h*[(0+0.yn) h*(0.4)= Next value x(0) + 4*h y(4)= From previous computation L(1)= L(2)= L(3)= 49 50 51 52 53 h*f(xn.6398 2.3000 1.yn+0.5*L(1)) h*[(0+0.5*h.1000 0.yn+2*L(2)-L(1)) h*[(0+h)+2*(1+2*L(2)-L(1))]= 0.5 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 L(1)= L(2)= L(3)= y(1)= y(0) +(L(1) + 4*L(2) + L(3))/6 h= x(2)-x(1)= x(0.6 9−14 Numerical Analysis Using MATLAB® and Excel®.0 0.5*h)+2*(1+0.8773 y(3)= y(2) +(L(1) + 4*L(2) + L(3))/6 h= x(3)-x(2)= x(0.4 0.0000 1.5*h)+2*(1+0.5*L(1)) h*[(0+0.2000 x5= h*f(xn+0.5*h)+2*(1+0.5*h.2250 h*f(xn+h.3+2*1.yn) h*(0+2*1)= 0.3)= Next value x(0) + 3*h y(3)= From previous computation L(1)= L(2)= L(3)= 39 40 41 42 43 44 45 46 47 48 h*f(xn.yn+0.5063 h*f(xn+0.8773 0.4.2267 0.5*h)+2*(1+0.5*L(1)) h*[(0+0.1+2*1. Third Edition Copyright © Orchard Publications .yn+2*L(2)-L(1)) h*[(0+h)+2*(1+2*L(2)-L(1))]= 0.2000 1.yn+0.0000 1. Spreadsheet for Example 9.5*h.1)= Next value x(0) + h y(1)= From previous computation L(1)= L(2)= L(3)= h*f(xn.1000 0.5146 y(2)= y(1) +(L(1) + 4*L(2) + L(3))/6 h= x(2)-x(1)= x(0.5*L(1))]= 0.4055 h*f(xn+0.5148 2.1000 0.3313 0.2600 x(1)-x(0)= (given) Initial condition (given) 0.5*h.yn+2*L(2)-L(1)) h*[(0+h)+2*(1+2*L(2)-L(1))]= 0.5*L(1)) h*[(0+0.yn) h*(0.5619 h*f(xn+h.3602 h*f(xn+h.5*h)+2*(1+0.5*h.yn+0.2)= Next value x(0) + 2*h y(2)= From previous computation L(1)= L(2)= L(3)= h*f(xn.yn+2*L(2)-L(1)) h*[(0+h)+2*(1+2*L(2)-L(1))]= 0.8969 y(5)= y(2) +(L(1) + 4*L(2) + L(3))/6 Figure 9.3229 h*f(xn+0.5*L(1))]= 0.1000 1.1000 0.2553 h*f(xn+0.3 0.8773)= 0.yn+0.Chapter 9 Solution of Differential Equations by Numerical Methods A 1 2 3 B C D E F Differential Equation y' = x + 2y Numerical solution by Runga-Kutte method follows h= x(0)= y(0)= x0= x1= x2= x3= x4= h*f(xn.4000 2.2859 h*f(xn+h.1 0.8773)= 0.4510 h*f(xn+h.yn) h*(0.5146)= 0.2267 0.3+2*1.4124 1.5*L(1))]= 0.5146 0.5*L(1))]= 0.2 0.3286 1.yn+2*L(2)-L(1)) h*[(0+h)+2*(1+2*L(2)-L(1))]= 0.3313 y(4)= y(2) +(L(1) + 4*L(2) + L(3))/6 h= x(4)-x(3)= x(0.2+2*1.yn) h*(0.

2 0.5534 0.43) serves as a check for the value y n + 1 = f ( x n + 1.3313 2.4 Milne’s Method Milne’s method also requires prior knowledge of several values of y .44) If y n + 1 and Y n + 1 in (9.( 0.0000 1.43) respectively.h [ 2f n – f n – 1 + 2f n – 2 ] 3 (9. we accept Y n + 1 as the best approximation.Milne’s Method Next.1 6.( 1.5146 1.1 0. do not differ considerably. Numerical Analysis Using MATLAB® and Excel®.0626 1.1496 0.2312 6.0330 0. If they differ significantly.2638 + -.5 yn 1. y n + 1 ) (9.43) The corrector formula of (9.42) and 1 Y n + 1 = y n – 1 + -.0080 5.0546 1. y. Adams’ method can also be applied to second order differential equations of the form y'' = f ( x.2267 1.599 8 12 2 (9.0406 0.3 0. Third Edition Copyright © Orchard Publications 9−15 .2292 0.39) 3 51 y 6 = 2. 0 9.42) and (9. y' ) with initial conditions y ( x 0 ) = y 0 and y'( x 0 ) = y' .0 0.41) As with the other methods.5534 2.h [ f n + 1 + 4f n + f n – 1 ] 3 (9.8773 2.( 0.1224 0.2312 ) + ----.1826 0.2232 0.0272 Δfn Δ 2 fn Δ 3 fn and by substitution into (7.39).2938 0. we compute the following values to be used in Adams’ formula of (9.0000 0. These are shown below. we must reduce the interval h . xn 0.2232 ) + -.6758 3.4 0.0406 ) = 3.8969 fn=xn+2yn 2. It uses the predictor−corrector pair 4 y n + 1 = y n – 3 + -.8254 4.8969 + 0.

Milne’s method can also be extended to second order differential equations of the form y'' = f ( x.46) and (9.7984 and 1 Y 6 = y 4 + -.6 where we found the following values: TABLE 9. Solution: This is the same differential equation as in Example 9.6 .5146 1.2292 4. we must find the value of f 6 .599 = 7. 9−16 Numerical Analysis Using MATLAB® and Excel®. this is found from f 6 = x 6 + 2y 6 where x 6 = 0. Third Edition Copyright © Orchard Publications .1 ( f 6 + 4f 5 + f 4 ) 3 1 = 2. y' ) with initial conditions y ( x 0 ) = y 0 and y'( x 0 ) = y'0 .× 0.3313 + -.8773 2.43).1 ( 7.× 0.0.2938 and using the predictor formula we find 4 y 6 = y 2 + -.0546 ) = 3.47) We see from (9.6 for the differential equation y' = 2y + x (9.0626 + 2 × 4.6 + 2 × 3.1 ( 2 × 6.7 n 2 3 4 5 xn 0.( 0. y.0626 6.5146 + -.2938 – 5.4 0.1 Table for Example 9.8969 fn=xn+2yn 3.2938 + 5. Then.3313 2.2 0.5 y 6 = 3.599 3 (9. and from Example 9.Chapter 9 Solution of Differential Equations by Numerical Methods Example 9.599 3 (9.1 ) [ 2f 5 – f 4 + 2f 3 ] 3 4 = 1.46) Before we use the corrector formula of (9.47) that the predictor−corrector pair is in very close agreement. f 6 = x 6 + 2y 6 = 0.45) with the initial condition y ( 0 ) = 1 .7984 + 4 × 6.0546 5.0626 ) = 3.3 0.599 .5 yn 1.7 Use Milne’s method to find the value of y corresponding to x = 0.

y i( 4 ) h i + 1 + … 2! 3! 4! provided that h is sufficiently small such as h = 0. • For a Runge−Kutta method of order 3 we use the relations l 1 = hf ( x n .y''' i h i + 1 + ---. y' ) using the relation 1 1 (4) 3 2 y' i + 1 = y' i + y''i h + ---. Third Edition Copyright © Orchard Publications 9−17 .Summary 9. y n + ------⎞ ⎝ 2 2⎠ m1 h m 2 = hf ⎛ x n + -. y n ) k 2 = hf ( x n + h .1 . y.5 Summary • The Taylor series method uses values of successive derivatives at a single point.. y n ) = k 1 l1 h l 2 = hf ⎛ x n + -. y ) at several points.1 . • For a Runge−Kutta method of order 2 we use the relations k 1 = hf ( x n .( l 1 + 4l 2 + l 3 ) 6 l 3 = hf ( x n + h . y n + ---⎞ ⎝ 2 2⎠ 1 y n + 1 = y n + -. y n + h ) 1 y n + 1 = y n + -. y n + -----..( k 1 + k 2 ) 2 provided that h is sufficiently small such as h = 0. y n + m 3 ) 1 y n + 1 = y n + -.y'' i h i + 1 + ---. y n ) = l 1 = k 1 m2 h m 3 = hf ⎛ x n + -.⎞ = l 2 ⎝ 2 2⎠ m 4 = hf ( x n + h .y'''i h + ---.( m 1 + 2m 2 + 2m 3 + m 4 ) 6 • The Runge−Kutta method can also be used for second order differential equations of the form Numerical Analysis Using MATLAB® and Excel®. We can use this series method to obtain approximate solutions of differential equations with the relation 1112 3 4 y i + 1 = y i + y' i h i + 1 + ---. • The Taylor series method can also be extended to apply to a second order differential equation y'' = f ( x.y i h + … 2! 3! • The Runge−Kutta method uses values of the first derivative of f ( x.. y n + 2l 2 – l 1 ) • For a Runge−Kutta method of order 4 we use the relations m 1 = hf ( x n . it is the most widely used method of solving differential equations using numerical methods.

⎞ ⎝ 2⎠ l 3 = h ( y' n + 2l' 2 – l' 1 ) yn + 1 l' 1 = hf ( x n . Third Edition Copyright © Orchard Publications .y0). y n ) Δf n = f n – f n – 1 Δ f n = Δf n – Δf n – 1 2 and so on. The first. y' ) • For second order differential equations. y n . y' n + ----⎞ ⎝ 2 2 2⎠ l' 3 = hf ( x n + h.. They can be found in differential equations texts. y n + --. y' n + 2l' 2 – l' 1 ) 1 1 = y n + -. uses second and third−order Runge−Kutta methods. defines the desired time span of the interval over which we want to evaluate the function y = f ( x ) . • MATLAB has two functions for computing numerical solutions of Ordinary Differential Equations (ODE). the pair of 3rd−order relations are: l 1 = hy' n l' 1 l 2 = h ⎛ y' n + ---. y n + 2l 2 – l 1. The first argument.Δf n + ----. f. The second. • The syntax for ode23 is ode23(‘f’. This function produces two outputs. ode45. The third argument. represents the initial condition or boundary point that is needed to determine a unique solution. The second. This method uses the formula 1 5 2 3 3 y n + 1 = y n + h f n + -.tspan.Δ f n + … 2 12 8 where h = xn + 1 – xn f n = ( x n.Chapter 9 Solution of Differential Equations by Numerical Methods y'' = f ( x. a set of x values and the corresponding set of y values that represent points of the function y = f ( x ) . y ) . y' n ) l1 l' 1 h l' 2 = hf ⎛ x n + --.( l' 1 + 4l' 2 + l' 3 ) 6 6 Third and fourth order formulas can also be used but they were not be discussed in this text. • Adams’ method provides the transition from y n to y n + 1 and the step is performed by a formula expressed in terms of differences of f ( x. Both have the same syntax. y0. y. 9−18 Numerical Analysis Using MATLAB® and Excel®. is the name of the user defined MATLAB function.( l 1 + 4l 2 + l 3 ) y' n + 1 = y' n + -. in single quotation marks.Δ f n + -. uses fourth and fifth−order Runge−Kutta methods. ode23. These values can be found by other methods such as the Taylor series or Runge−Kutta methods. it is necessary to have several (4 or more) approximate values of y ( x ) in addition to the given initial condition y ( 0 ) . tspan. To use this method.

Third Edition Copyright © Orchard Publications 9−19 . y n + 1 ) If y n + 1 and Y n + 1 do not differ considerably. we accept Y n + 1 as the best approximation. If they differ significantly. y.Summary • Milne’s method also requires prior knowledge of several values of y .h [ f n + 1 + 4f n + f n – 1 ] 3 where y n + 1 is the predictor formula and Y n + 1 is the corrector formula. It uses the predictor−corrector pair 4 y n + 1 = y n – 3 + -. It can be found in differential equations texts. Milne’s method can also be extended to second order differential equations of the form y'' = f ( x. The procedure for this method was not discussed. we must reduce the interval h .h [ 2f n – f n – 1 + 2f n – 2 ] 3 and 1 Y n + 1 = y n – 1 + -. y' ) with initial conditions y ( x 0 ) = y 0 and y' ( x 0 ) = y'0 . The corrector formula serves as a check for the value y n + 1 = f ( x n + 1. Numerical Analysis Using MATLAB® and Excel®.

compute and plot the numerical solution using the MATLAB function ode23 along with points of the analytical solution to verify the accuracy of the numerical solution for the interval 2 ≤ x ≤ 4 .1.5 . 3.0 correct to four decimal places. y' ( 0 ) = – 1 .6 Exercises 1. 9−20 Numerical Analysis Using MATLAB® and Excel®.1 and x 0 + 0. It is suggested that a spreadsheet is used to do all computations. Construct a spreadsheet for the numerical solutions of Example 9. 5. Then. using the third−order Runge−Kutta method. Use MATLAB to find the analytical solution of y' = f ( x ) = 3x 2 with the initial condition y ( 2 ) = 0. 6. 4. and x 0 = 0.2. Third Edition Copyright © Orchard Publications . Given the differential equation y'' + y' = xy compute the approximate values of y and y' at x 0 + 0.Chapter 9 Solution of Differential Equations by Numerical Methods 9. It is suggested that a spreadsheet is used to do all computations.2 given that y ( 0 ) = 1 .0 find the values of y corresponding to the values of x 0 + 0.707 using the command ode23 for the interval 0 ≤ x ≤ 10 .1 and x 0 + 0. 2.2 correct to four decimal places using the third−order Runge− Kutta method. Use the MATLAB ode23 function to verify the analytical solution of Example 9. Use MATLAB to plot the numerical solution of the non−linear differential equation y' = – y + 0. Given the differential equation y' = x – y 2 with the initial condition y ( 0 ) = 1 and x 0 = 0.2 sin x 3 with the initial condition y ( 0 ) = 0.

7 Solutions to End−of−Chapter Exercises 1.y]=ode23('func_exer9_1'.. Next.2). we write and execute the MATLAB script below. tspan. y(:. % Use 2nd and 3rd Order Runge−Kutta % Plot numeric values with the statements below plot(x. y0). '+r−'.−1]. Numerical Analysis Using MATLAB® and Excel®. % Given initial conditions [x.1'). tspan=[0 3]. xlabel('x').. % Interval over which we want to evaluate y=f(x) y0=[1.1). ylabel('y (upper curve).. grid The plot below shows the function y = f ( x ) and its derivative dy ⁄ dx . We write and save the following function file: function dy = func_exer9_1(x.Solutions to End−of−Chapter Exercises 9. 'Ob−−') title('Numeric Solution of Differential Equation of Exercise 9.y) dy = −x*y. y(:. x. yprime (lower curve)'). Third Edition Copyright © Orchard Publications 9−21 .

0000 1.2731 0.yn) 17 m(1)= h*f(xn+0. y0).5*L(1)^2)]= h*[(0+h)+(1+2*L(2)-L(1))^2]= 0.5.2)^2)= y(0)+0.5*h.5'.3906 1.5(k(1)+k(2)) 10 y(1)= 11 h*f(xn. The MATLAB script for the numerical solution is as follows: tspan=[2 4].yn) 8 k(2)= h*f(xn+h..5*h)+(1+0. Dy=3*x^2.3280 1.yn+h) 9 y(0)+0. A B 1 Differential Equation y' = x + y2 2 Numerical solution by Runga-Kutte method follows 3 h= (given) 4 x(0)= (given) 5 y(0)= Initial condition (given) 6 7 k(1)= h*f(xn. y. tspan.y). xlabel('x').5*m(2))^2]= h*[(0+h)+(1+m(3))^2]= 3.y(2)=0.'x') and MATLAB displays y = x^3-15/2 Next.yn+0.2000 0.5*m(1)) 18 m(2)= h*f(xn+0.5*h)+(1+0.2000 0.yn+m(3)) 20 m(4)= 21 y(1)= y(0) +(1/6)*(m(1) + 2*m(2)+2*m(3) + m(4)) C D 0.2+(1+0.Chapter 9 Solution of Differential Equations by Numerical Methods 2. The analytical solution is found with syms x y y=dsolve('Dy=3*x^2.. % Use 2nd and 3rd Order Runge−Kutta % Plot numeric values with the statements below plot(x.2000 0.5*h.2640 0.2000 0. % Interval over which we want to evaluate y=f(x) y0=7. Third Edition Copyright © Orchard Publications .3').y]=ode23('fexer9_3'.yn+2*L(2)-L(1)) 14 L(3)= y(0) +(L(1) + 4*L(2) + L(3))/6 15 y(1)= 16 h*f(xn. we write and save the following statements as function file fexer9_3 function Dy=fexer9_3(x.2620 0.yn+0. '+r−') title('Numeric Solution of Differential Equation of Exercise 9.0000 h*(0+1^2)= h*(0+0. ylabel('y').5*(D11+D12) h*(0+1^2)= h*[(0+0. grid 9−22 Numerical Analysis Using MATLAB® and Excel®.5*h.2620 0. % Initial condition: Since y=x^3−15/2 and y(2) = 0.3655 1..yn) 12 L(1)= h*f(xn+0.5*m(2)) 19 m(3)= h*f(xn+h.yn+0.2758 0.5. it follows that y(0) = 7.2735 h*(0+1^2)= h*[(0+0.5*h)+(1+0.5*L(1)) 13 L(2)= h*f(xn+h.5*m(1))^2]= h*[(0+0.5 [x.

Third Edition Copyright © Orchard Publications 9−23 . xlabel('x')... x0=[0..num_x..'+'. x. title('Numeric solution of non−linear differential equation dy/dx=−x^3+0..num_x.707]. The MATLAB script and the plot for the numerical solution are as follows: tspan=[0 10].num_x]=ode23('fexer4'. plot(x.y). The spreadsheet is shown on the following two pages. '−'). We write and save the following statements as function file fexer4 function Dy=fexer4(x.tspan.Solutions to End−of−Chapter Exercises 4. Numerical Analysis Using MATLAB® and Excel®. Dy=−y^3+0. [x..x0).2*sin(x). ylabel('y=f(x)'). grid 5.2sinx').

5*L(1))]= 20 L(3)= h*f(xn+h.0305 37 38 h*(0.yn+2*L(2)-L(1)) 41 42 y(4)= y(2) +(L(1) + 4*L(2) + L(3))/6 43 D E F x0= x1= x2= 0.5*L(1)) 30 h*[(0+h)+2*(1+2*L(2)-L(1))]= L(3)= h*f(xn+h.9052+2*L(2)-L(1))]= 21 22 y(2)= y(1) +(L(1) + 4*L(2) + L(3))/6 23 24 h= x(2)-x(1)= 0.1000 5 x(0)= (given) 0.9052 -0.yn+0.1+h)^2-(0.9052+0.2 -0.9052 17 18 h*(0.1000 15 x(0.2)= Next value x(0) + 2*h 0.yn+0.0895 -0.0948 -0.1^2-0.5*h.2000 35 x(0.8213 27 28 h*(0.yn+0.2000 26 y(2)= From previous computation 0.2+2*1.5*L(1))]= L(2)= h*f(xn+0.yn+2*L(2)-L(1)) 31 32 y(3)= y(2) +(L(1) + 4*L(2) + L(3))/6 33 34 h= x(3)-x(2)= -0.yn) 19 L(2)= h*f(xn+0.yn+2*L(2)-L(1)) 11 12 y(1)= y(0) +(L(1) + 4*L(2) + L(3))/6 13 14 h= x(2)-x(1)= 0.5*h.1000 25 x(0.1843 0.3)= Next value x(0) + 3*h -0.yn+0.yn) 39 h*[(0+0.0901 0.0787 0. Third Edition Copyright © Orchard Publications .1)= Next value x(0) + h 0.1 0.2922 -0.5*h)^2-(0.0305 -0.1000 16 y(1)= From previous computation 0.5*L(1)) 10 h*[(0+h)^2-(1+2*L(2)-L(1))]= L(3)= h*f(xn+h.0838 -0.0000 6 y(0)= Initial condition (given) 1.5*h)+2*(1+0.5*h.5*h)+2*(1+0.8773)= L(1)= h*f(xn.yn+2*L(2)-L(1)) h*[(0.5*L(1)) h*[(0+0.5*L(1)) 40 h*[(0+h)+2*(1+2*L(2)-L(1))]= L(3)= h*f(xn+h.9052)= L(1)= h*f(xn.2405 1.0 0.y 2 Numerical solution by Runga-Kutte method follows 3 4 h= x(1)-x(0)= 0.1000 -0.3+2*1.8063 continued on next page 9−24 Numerical Analysis Using MATLAB® and Excel®.1981 0.2138 -0.yn) 29 h*[(0+0.8213 0.6000 36 y(3)= From previous computation 1.yn) 9 h*[(0+0.0000 7 8 h*(0-1)= L(1)= h*f(xn.Chapter 9 Solution of Differential Equations by Numerical Methods A B C 1 Differential Equation is y' = x2 .5*h)^2-(1+0.5*L(1))]= L(2)= h*f(xn+0.5146)= L(1)= h*f(xn.5*h.5*L(1))]= L(2)= h*f(xn+0.2077 0.

9003 continued on next page Numerical Analysis Using MATLAB® and Excel®.0000 0.0901 0.1000 0.1000 0.3+2*1. y(0) + 2*L(2) .5*L(1))]= h*[(0+h)+2*(1+2*L(2)-L(1))]= D E F 0.0000 0.5*h)+2*(1+0.L(1).0000 0.0000 -0. y(0).0000 0.0000 -1.1000 0.0992 0.8773)= h*[(0+0.8063 h*(0.Solutions to End−of−Chapter Exercises A 44 45 46 47 48 49 50 51 52 53 h= x(0.0000 0.5*h.5*L(1)) h*f(xn+h.yn+0.1)= Next value x(0) + h 21 y(1)= From previous computation 22 y'(1)= From previous computation 23 C 0.yn) h*f(xn+0.9050 -0.4)= y(3)= L(1)= L(2)= L(3)= y(4)= B x(4)-x(3)= Next value x(0) + 4*h From previous computation h*f(xn.1000 0. y'(0))= 11 L(2)= h*(y'(0) + 0.8063 6.0950 0.yn+2*L(2)-L(1)) y(2) +(L(1) + 4*L(2) + L(3))/6 C 0. y(0) + 0.5*L(1).9050 -0.0000 1. y'(0) + 0. A B 1 Differential Equation is y''+y'=xy or y''=xy-y' 2 Numerical solution by Runga-Kutte method follows 3 4 h= x(1)-x(0)= 5 x(0)= Initial condition (given) 6 y(0)= Initial condition (given) 7 y'(0)= Initial condition (given) 8 9 L(1)= h*y'(0)= 10 L'(1)= h*f(x(0).L'(1))= 14 L'(3)= h*f(x(0) + h.0998 -0.1000 -0. Third Edition Copyright © Orchard Publications 9−25 .9003 0.5*L(1))= 13 L(3)= h*(y'(0) + 2*L'(2) .5*L'(1))= 12 L'(2)= h*f(x(0) + 0.5*h. y'(0) + 2*L'(2) .L'(1))= 15 16 y(1)= y(0) +(L(1) + 4*L(2) + L(3))/6 17 y'(1)= y'(0) + (L'(1) + 4*L'(2) + L'(3))/6= 18 19 h= x(1)-x(0)= 20 x(0.

L'(1))= y(0) +(L(1) + 4*L(2) + L(3))/6 y'(0) + (L'(1) + 4*L'(2) + L'(3))/6= C -0.5*h. y(0) + 2*L(2) .0803 0.5*L'(1))= h*f(x(0) + 0.L'(1))= h*f(x(1) + h. y(1).2)= y(2)= y'(2)= L(1)= L'(1)= L(2)= L'(2)= L(3)= L'(3)= y(3)= y'(3)= B h*y'(1)= h*f(x(1).1000 0.5*h.8023 -0.8023 0.2000 0.0991 -0.0949 -0.L(1).5*L(1))= h*(y'(0) + 2*L'(2) . y'(1) + 0.L'(1))= h*f(x(0) + h.0802 0.0900 0.5*L'(1))= h*(y'(1) + 2*L'(2) .5*L(1).0709 0.L'(1))= y(0) +(L(1) + 4*L(2) + L(3))/6 y'(0) + (L'(1) + 4*L'(2) + L'(3))/6= x(2)-x(1)= Next value x(0) + 2*h From previous computation From previous computation h*y'(0)= h*f(x(0).0851 0.5*L(1).8199 -0.7074 9−26 Numerical Analysis Using MATLAB® and Excel®. y(1) + 0.8199 -0. y'(1))= h*(y'(1) + 0.5*L'(1))= h*f(x(1) + 0. y'(0) + 0.L(1). y(0) + 0. Third Edition Copyright © Orchard Publications .0934 0.0968 0.0966 -0. y'0 + 2*L'(2) . y(1) + 2*L(2) . y(0).7444 -0.Chapter 9 Solution of Differential Equations by Numerical Methods 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 A L(1)= L'(1)= L(2)= L'(2)= L(3)= L'(3)= y(2)= y'(2)= h= x(0.0980 -0. y'(1) + 2*L'(2) .0754 0. y'(0))= h*(y'(0) + 0.

Therefore..Chapter 10 Integration by Numerical Methods T his chapter is an introduction to numerical methods for integrating functions which are very difficult or impossible to integrate using analytical means. and Simpson’s rule that computes a function f ( x ) with a set of quadratic functions. the number of points between x 0 = a and x n = b is ---------- n x 1 = a + Δx.. We will discuss the trapezoidal rule that computes a function f ( x ) with a set of linear functions.. …..... and so on. shown in Figure 10.1. Integration by the trapezoidal rule To evaluate the definite integral ∫a f ( x ) dx . x n – 1 = a + ( n – 1 )Δx . x 2 = a + 2Δx.. and finally from x n – 1 to b . Third Edition Copyright © Orchard Publications 10−1 . 10..1. the integral from a to b is the sum of the integrals from a to x 1 . Then. yn – 1 xn – 1 yn x b x2 Figure 10.1 The Trapezoidal Rule Consider the function y = f ( x ) for the interval a ≤ x ≤ b . The total area is ∫a b f ( x ) dx = ∫a x1 f ( x ) dx + ∫x x2 1 f ( x ) dx + … + ∫x b n f ( x ) dx = n–1 k=1 ∑ ∫x xk k–1 f ( x ) dx The integral over the first subinterval. f (x) P0 y0 0 a P1 P2 Pn Pn – 1 y1 x1 y2 . from x 1 to x 2 . we divide the interval a ≤ x ≤ b b into n subintervals each of length Δx = b – a . can now be approximated by the area of the trapezoid Numerical Analysis Using MATLAB® and Excel®..

3 3 3 (10.2) Compare with the exact value.( y 0 + y 1 )Δx plus the area of the trapezoid x 1 P 1 P 2 x 2 that is equal to 2 1 -.( y 1 + y 2 )Δx .3) For the trapezoidal rule approximation we have x0 = a = 1 xn = b = 2 n = 4 --------------------Δx = b – a = 2 – 1 = 1 4 4 n Then.= -. and so on.1) Example 10.1 Using the trapezoidal rule with n = 4 .y 0 + y 1 + y 2 + … + y n – 1 + -. Third Edition Copyright © Orchard Publications .= 2. estimate the value of the definite integral ∫1 x d x 2 2 (10. y = f (x) = x 2 10−2 Numerical Analysis Using MATLAB® and Excel®.( y 1 + y 2 )Δx + … + -.Chapter 10 Integration by Numerical Methods 1 aP0 P 1 x 1 that is equal to -.y n⎞ Δx ⎝2 2 ⎠ Trapezoidal Rule (10. and compute the percent error. the trapezoidal approximation becomes 2 1 1 1 T = -.– -.( y n – 1 + y n )Δx 2 2 2 or 1 1 T = ⎛ -. Solution: The exact value of this integral is ∫1 2 x x dx = ---3 2 3 2 1 8 1 7 = -.( y 0 + y 1 )Δx + -. Then.33333 .

× -.33333 (10. Numerical Analysis Using MATLAB® and Excel®.2 Use the MATLAB function trapz(x.5) The MATLAB function trapz(x.dx x 2 1 = ln x 2 1 = ln 2 – ln 1 = 0.+ ----.y) to approximate the value of the integral ∫1 -.T = ⎛ -. we find that the percent error is 2.× ----.33333 % Error = -------------------------------------------. Example 10. compute the percent error when n = 5 and n = 10 Solution: The exact value is found from ∫1 -. Third Edition Copyright © Orchard Publications 10−3 .⎞ = 36 ----⎝ 4⎠ 16 7 2 y 3 = f ( x 3 ) = ⎛ -.6) and by comparison with the exact value.34375 ⎝ 2 16 16 16 16 2 16 ⎠ 4 16 4 32 (10.= 2.+ -.0000 = 0.4) From (10.The Trapezoidal Rule x0 = a = 1 x 1 = a + Δx = 5 -4 -x 2 = a + 2Δx = 6 4 -x 3 = a + 3Δx = 7 4 x4 = b = 2 2 ----y 0 = f ( x 0 ) = 1 = 16 16 5 2 y 1 = f ( x 1 ) = ⎛ -.dx x 2 1 (10.6931 – 0.= ----. approximates the integral of a function y = f ( x ) using the trapezoidal rule.n) where y is the integral with respect to x.6931 For the approximation using the trapezoidal rule.+ ----.y.. we let x 5 represent the row vector with n = 5 .+ ----.⎞ ⎝ 4⎠ 2 = 64 ----16 and by substitution into (10.⎞ × -.4). and n (optional) performs integration along dimension n .= -------.3) and (10.× ----.45 % 2.34375 – 2. 150 1 75 1 1 16 25 36 49 1 64 .1).× 100 = 0.⎞ = 25 ----⎝4 ⎠ 16 6 2 y 2 = f ( x 2 ) = ⎛ -.⎞ = 49 ----⎝ 4⎠ 16 8 y 4 = f ( x 4 ) = ⎛ -.

The MATLAB script for this example is t=linspace(0.6931 Example 10.^2). The corresponding values of y are denoted as y 5 and y 10 .56 % 0.6931 and the percent error when Δx = 1 ⁄ 10 is used is 0.6939 – 0. that is. x10=linspace(1. Solution: We use the same procedure as in the previous example. area=trapz(t.7) where τ is a dummy variable of integration. is called the error function* and it is used extensively in communications theory.y) function to find the area under this integral with n = 10 when the upper limit of integration is t = 2 . y5=1.× 100 = 0.y10) area5 = 0.12 % 0. Δx = 1 ⁄ 5 and Δx = 1 ⁄ 10 respectively.5). We use the following MATLAB script.10).y) MATLAB displays the following result.3 The integral f( t) = ∫0 t e –τ 2 dτ (10. 2. area10=trapz(x10. and the areas under the curve as area5 and area10 respectively./x10. Use the MATLAB trapz(x. y=exp(−t.∫ e–τ dτ π 0 10−4 Numerical Analysis Using MATLAB® and Excel®.u 2 * The formal definition of the error function is erf ( u ) = -----.2.2. y10=1./x5.Chapter 10 Integration by Numerical Methods and x 10 the vector with n = 10 .y5). area5=trapz(x5.6939 The percent error when Δx = 1 ⁄ 5 is used is 0. Third Edition Copyright © Orchard Publications .6931 % Error = -------------------------------------.6970 area10 = 0.× 100 = 0.6970 – 0.6931 % Error = -------------------------------------.10).2. x5=linspace(1.

10) When this script is executed.8818 Example 10. The MATLAB script below will compute and plot the power. Third Edition Copyright © Orchard Publications 10−5 .8) where v ( t ) = sin 3t .a.1 ( e 0. Solution: a. The energy is the integral of the instantaneous power.10). W ( t 0. find a. we choose n = 100 . v=sin(3. MATLAB displays the following message. it returns a warning.2. t 1 ) dissipated in this device from t 0 = 0 to t 1 = 10 s.2*sin(3*t))−1). Next. The energy W ( t 0. For this example. t=sym('t'). we will find and sketch the power and energy by the trapezoidal rule using the MATLAB trapz(x.*(exp(0.2v ( t ) – 1) (10.9) b. For this example.1 sin 3t ( e 0.100). s=int(0. We can try the MATLAB int(f. i=0.*t). so that Δx = 1 ⁄ 100 . The instantaneous power p ( t ) b.b) function where f is a symbolic expression. MATLAB returns the following message when integration is attempted with the symbolic expression of (10. When MATLAB cannot find a solution.The Trapezoidal Rule area = 0. but it is not easy.0.10.y) function.4 The i – v (current−voltage) relation of a non−linear electrical device is given by i ( t ) = 0. By any means. and a and b are the lower and upper limits of integration respectively.2 sin 3t – 1 ) dt (10.*i.1 ∫0 10 s sin 3t ( e 0. that is. The instantaneous power is p ( t ) = v ( t )i ( t ) = 0.10) An analytical solution of the last integral is possible using integration by parts.1*sin(3*t)*(exp(0. Warning: Explicit integral could not be found. t 1 ) = ∫t t1 0 p ( t ) dt = 0.1.2 sin 3t – 1) (10. t=linspace(0. p=v.*v)−1). Numerical Analysis Using MATLAB® and Excel®.

and thus we expect the energy to be constant..4 be represented by the parabola y = αx + βx + γ 2 (10.01 0.3.Chapter 10 Integration by Numerical Methods plot(t. title('Power vs Time'). energy=trapz(t. 0.p). xlabel('seconds').2.4 The plot of Figure 10.p). '+'). grid. title('Energy vs Time'). The energy is shown in Figure 10.1013 joule.2. 10.02 0.. ylabel('watts') The power varies in a uniform fashion as shown by the plot of Figure 10. the value of the energy is 0.015 watts 0.. The MATLAB script below computes and plots the energy.025 Power vs Time 0.005 0 0 1 2 3 4 5 seconds 6 7 8 9 10 Figure 10. Third Edition Copyright © Orchard Publications . ylabel('joules') energy = 0.1013 Thus. Let the curve of Figure 10. xlabel('seconds').2 Simpson’s Rule The trapezoidal and Simpson’s rules are special cases of the Newton−Cote rules which use higher degree functions for numerical integration.2 shows that the power is uniform for all time. plot(t.energy.11) 10−6 Numerical Analysis Using MATLAB® and Excel®. Plot for the power variation in Example 10. grid.

12) 1 3 = -. ( 0. y2 ) . Simpson’s rule of integration The area under this curve for the interval – h ≤ x ≤ h is Area h –h = ∫– h ( α x 3 h 2 + β x + γ ) dx = -------.5 Energy vs Time 1 0.Simpson’s Rule 1.4.11) we have: Numerical Analysis Using MATLAB® and Excel®.β h ----------= -------.+ ------.5 -1 0 1 2 3 4 5 seconds 6 7 8 9 10 Figure 10. y 1 ) .4 y y0 y1 y2 x −h 0 h Figure 10.+ ------. by (10. and ( h.+ ------.5 joules 0 -0.3.– γ h⎞ = 2 α h . y 0 ) .h ( 2 α h + 6 γ ) 3 The curve passes through the three points ( – h. Then.+ 2 γ h ⎝ 3 ⎠ 3 2 2 3 (10.βh-------.+ γ h – ⎛ – α h . Third Edition Copyright © Orchard Publications 10−7 .+ γ x 3 2 2 3 2 αx 3 βx 2 h –h 3 αh . Plot for the energy of Example 10.

16) and by substitution into (10. A B C y0 y1 h a y2 y3 y4 yn – 1 yn b Figure 10.12) in terms of h .12) we obtain Area h –h 1 1 3 = -. the area under segment AB is 10−8 Numerical Analysis Using MATLAB® and Excel®.h ( y 0 + 4y 1 + y 2 ) 3 (10.13) into (a) and (c) and rearranging we obtain α h – β h = y0 – y1 α h + β h = y2 – y1 2 2 (10. This is done with the following procedure. Simpson’s rule of integration by successive segments From Figure 10.Chapter 10 Integration by Numerical Methods y0 = α h – β h + γ y1 = γ y2 = α h + β h + γ 2 2 (a) (b) (c) (10.15) yields 2 α h = y 0 – 2y 1 + y 2 2 (10.5. By substitution of (b) of (10. we can apply (10.13) We can now evaluate the coefficients α. we observe that each segment of width 2h of the curve can be approximated by a parabola through its ends and its midpoint. y 1 and y 2 .18) Now.5.5.14) (10. γ and express (10.h ( 2 α h + 6 γ ) = -.15) Addition of (10. y 0 .17) or 1 = -.18) to successive segments of any curve y = f ( x ) in the interval a ≤ x ≤ b as shown on the curve of Figure 10.h [ ( y 0 – 2y 1 + y 2 ) + 6y 1 ] 3 3 Area h –h (10.14) with (10. β. Thus. Third Edition Copyright © Orchard Publications .

22) Example 10. compute the approximate value of ∫1 -. and a and b are the lower and upper limits of integration respectively. Numerical Analysis Using MATLAB® and Excel®. For this example.21) Since each segment has width 2h .21) is found from b–a h = ---------n n = even (10. When the areas under each segment are added.h ( y 2 + 4y 3 + y 4 ) 3 (10.dx x 2 1 (10. The value of h for (10. This restriction does not apply to the trapezoidal rule of numerical integration.a. Third Edition Copyright © Orchard Publications 10−9 .20) and so on.5 Using Simpson’s rule with 4 subdivisions ( n = 4 ) . for convenience.b) function where f is a symbolic expression. to apply Simpson’s rule of numerical integration. syms x Area=int(1/x.1.19) Likewise. the area under segment BC is Area BC 1 = -.6.2 where we found that the analytical value of this definite integral is ln = 0.6931 .23) Solution: This is the same integral as that of Example 10. We can also find the analytical value with MATLAB’s int(f.Simpson’s Rule Area AB 1 = -.h ( y 0 + 4y 1 + 2y 2 + 4y 3 + 2y 4 + … + 2y n – 2 + 4y n – 1 + y n ) 3 Simpson′s Rule of Numerical Integration (10. To use Simpson’s rule.h ( y 0 + 4y 1 + y 2 ) 3 (10. we obtain 1 Area = -. the number n of subdivisions must be even.2) Area = log(2) We recall that log(x) in MATLAB is the natural logarithm. we construct the following table using the spreadsheet of Figure 10.

The quad8 function detects and handles irregularities more efficiently.23) By comparison of the numerical with the exact value. Third Edition Copyright © Orchard Publications .31905 0.50000 1 19 Sum of Products = 20 Area = (h/3)*(Sum of Products) = (1/12)*8. When such irregularities occur. The description of these can be seen by typing help quad or help quad8. h = (b-a)/n = Multiplier 8 x0=a= 9 1.5 2 ∫ (1/x)dx evaluated from a = 1 to b = 2 with n = 4 3 Numerical integration by Simpson's method follows a= 1 4 Given b= 2 5 n= 4 6 0.50000 8.2500 7 Then. and a and b are the lower and upper limits of –3 integration respectively.80000 4 x2=a+2h= 13 1.00000 1 x1=a+h= 11 1. we observe that the error is very small when Simpson’s method is applied. the quad and quad8. The quad function uses an adaptive form of Simpson’s rule. If tol is omitted.20000 1. MATLAB displays a warning message but still provides an answer. it is understood to be the standard tolerance of 10 .66667 2 x3=a+3h= 15 1. Both functions have the same syntax.28571 0.50000 y2=1/x2= 14 0. that is. this means that these methods can handle irregularities such as singularities.Chapter 10 Integration by Numerical Methods A B C D 1 Example 10.00000 3.tol). q=quad(‘f’. Both of these functions use adaptive quadrature methods.00000 y4=1/x4= 18 0.00000 y0=1/x0= 10 1. MATLAB has two quadrature functions for performing numerical integration.25000 y1=1/x1= 12 0.b.a.57143 4 x4=b= 17 2.33333 2. Spreadsheet for numerical integration of (10. 10−10 Numerical Analysis Using MATLAB® and Excel®.31905 = E Products 1. and integrate to a relative error tol which we must specify. The string ‘f’ is the name of a user defined function.75000 y3=1/x3= 16 0. while the quad8 function uses the so−called Newton−Cotes 8−panel rule.6.69325 Figure 10.

tol) function where tol = 10 Solution: a.a. we write and execute the following MATLAB script.24) a.tol) function where tol = 10 d. Obtain the value of this integral with the q=quad(‘f’. First. format long y_std=quad('errorfcn1'. Obtain the value of this integral with the q=quad8(‘f’.88208139076242 Numerical Analysis Using MATLAB® and Excel®.2) % Define symbolic variable x and integrate – 10 – 10 pretty(y) y = 1/2*erf(2)*pi^(1/2) 1/2 1/2 erf(2) pi erf is an acronym for the error function and we can obtain its definition with help erf b.a.b.Simpson’s Rule Example 10.10^−10) y_tol = 0.0. With this file saved as errorfcn1. syms x.2.2) We obtain the answer in standard tolerance form as y_std = 0. With the specified tolerance. the script and the answer are as follows: y_tol=quad('errorfcn1'.b.^2). Third Edition Copyright © Orchard Publications 10−11 .88211275610253 c. function y = errorfcn1(x) y = exp(−x.0.b) function c. We will use format long to display the values with 15 digits. We name it errorfcn1. y=int(exp(−x^2). Obtain the value of this integral with the q=quad8(‘f’.a.0.m.a.6 Given the definite integral y= f(x ) = ∫0 2 e –x 2 dx (10.b) function e. we need to create and save a function m−file. Obtain the value of this integral with the q=quad(‘f’.m as shown below. Use MATLAB’s symbolic int function to obtain the value of this integral b.

10−12 Numerical Analysis Using MATLAB® and Excel®.88208139076242 We observe that with the 10 Example 10. ( 1.b) where a and b are non−negative.0. The script is then saved as Example_10_7. b ) = ( 0. % Insert line a=input('Enter first point "a" (non−negative): '). then.4.25) at ( ( a. With the standard tolerance. The sqrt function in a built−in function and therefore. and (3. We will include the input function in the script. 0.8 ). both quad and quad8 produce the same result.7 Using the quad and quad8 functions with standard tolerance. 2. b=input('Enter second point "b" (non−negative): ').2. we obtain y = ∫a b x 1⁄2 x dx = --------3⁄2 3⁄2 b a 2 3⁄2 3⁄2 = -. Third Edition Copyright © Orchard Publications . y_std8=quad8('errorfcn1'. we need not write a user defined m−file.2) y_std8 = 0.Chapter 10 Integration by Numerical Methods d.( b –a ) 3 (10.8) . Use the fprintf function to display first the analytical values. evaluate the integral y = f(x) = b – 10 tolerance.10^−10) y_tol8 = 0.3 ) ). % This script displays the approximations obtained with the quad and quad8 functions % with the analytical results for the integration of the square root of x over the % interval (a.0. y_tol8=quad8('errorfcn1'. Substitution of the values of the given values of a and b will be included in the MATLAB script below. ∫a x dx (10.2. the numerical values produced by the quad and quad8 functions for each set of data. Solution: Evaluating the given integral. % fprintf(' \n').88208139076194 e.26) where a and b are non−negative values. With the specified tolerance.

620825 11. quad8: 0. quad8: 11.417396 Example_10_7 0. fprintf(' \n') % Insert two lines Now.620843 Numerical Analysis Using MATLAB® and Excel®.. fprintf(' \n'). we execute this saved file by typing its name..3 Analytical: 1.2 Enter second point "b" (non-negative): 0. Third Edition Copyright © Orchard Publications 10−13 .417399 Numerical quad. that is....b). quad8: 1.221080 Numerical quad..a. fprintf(' \n'). kq8=quad8('sqrt'.Simpson’s Rule k=2/3.k.5)).221080 Enter first point "a" (non-negative): 3 Enter second point "b" (non-negative): 8 Analytical: 11.417399 Enter first point "a" (non-negative): 1.221080 Example_10_7 1.5)−a.kq. % Insert line fprintf(' Analytical: %f \n Numerical quad.620843 Numerical quad.b).a.kq8).*(b. kq=quad('sqrt'.4 Enter second point "b" (non-negative): 2. Example_10_7 Enter first point "a" (non-negative): 0.^(1.8 Analytical: 0. quad8: %f %f \n'.^(1.

approximates the integral of a function y = f ( x ) using the trapezoidal rule. The number n of n subdivisions can be even or odd.3 Summary • We can evaluate a definite integral ∫ f ( x ) dx with the trapezoidal approximation a b 1 1 T = ⎛ -. and a and b are the lower and upper limits of integration respectively. If tol is omitted. The string ‘f’ is the name of a user defined function.b. The quad8 function detects and handles irregularities more efficiently. The quad function uses an adaptive form of Simpson’s rule. and a and b are the lower and upper limits of integration respectively.b) function where f is a symbolic expression. • We can perform numerical integration with the MATLAB function int(f. –3 10−14 Numerical Analysis Using MATLAB® and Excel®.tol). Both functions have the same syntax. it is understood to be the standard tolerance of 10 .n) where y is the integral with respect to x. and integrate to a relative error tol which we must specify. while the quad8 function uses the so−called Newton−Cotes 8− panel rule. and n (optional) performs integration along dimension n . • MATLAB has two quadrature functions for performing numerical integration.Chapter 10 Integration by Numerical Methods 10. • The trapezoidal and Simpson’s rules are special cases of the Newton−Cote rules which use higher degree functions for numerical integration. • We can evaluate a definite integral using the expression ∫a f ( x ) dx b with Simpson’s rule of numerical integration 1 Area = -.a. q=quad(‘f’.y 0 + y 1 + y 2 + … + y n – 1 + -. Third Edition Copyright © Orchard Publications .a. the quad and quad8. that is. Both of these functions use adaptive quadrature methods.y n ⎞ Δx ⎝2 2 ⎠ ---------by dividing interval a ≤ x ≤ b into n subintervals each of length Δx = b – a .h ( y 0 + 4y 1 + 2y 2 + 4y 3 + 2y 4 + … + 2y n – 2 + 4y n – 1 + y n ) 3 where the number n of subdivisions must be even. • The MATLAB function trapz(x.y.

∫ x dx 3 0 2 n = 4 c.dx 2 0 1 x +1 n = 4 Numerical Analysis Using MATLAB® and Excel®.y. ∫ ---.dx 2 1 2 x n = 4 2. a.Exercises 10. Use the trapezoidal approximation to compute the values the following definite integrals and compare your results with the analytical values. ∫ sin x dx 0 π n = 4 1 c. Third Edition Copyright © Orchard Publications 10−15 .b) function. ∫ x dx 2 0 2 n = 4 b. ∫ x dx 0 2 n = 4 b. ∫ -------------. Verify your answers with the MATLAB trapz(x. a.a. Verify your answers with the MATLAB quad(‘f’. ∫ x dx 4 0 2 n = 4 1d. Use Simpson’s rule to approximate the following definite integrals and compare your results with the analytical values.n) function.4 Exercises 1.

The exact value is 2 4 2 0 ∫0 x x dx = ---4 3 = 4 For the trapezoidal rule approximation we have 10−16 Numerical Analysis Using MATLAB® and Excel®.y) area = 2 b.× 2 ⎞ × -.T = ⎛ -.5 Solution to End−of−Chapter Exercises 1.+ -.= 2 ⎝2 ⎠ 2 2 2 2 2 x=linspace(0.× 0 + -.Chapter 10 Integration by Numerical Methods 10.y n ⎞ Δx ⎝2 2 ⎠ a.2. area=trapz(x.+ 1 + -.= 4 × -. Third Edition Copyright © Orchard Publications . 1 1 T = ⎛ -. The exact value is ∫0 2 x x dx = ---2 2 2 0 = 2 For the trapezoidal rule approximation we have x0 = a = 0 xn = b = 2 n = 4 --------------------Δx = b – a = 2 – 0 = 1 2 4 n y = f (x) = x x0 = a = 0 -x 1 = a + Δx = 1 2 x 2 = a + 2Δx = 1 3 x 3 = a + 3Δx = -2 x4 = b = 2 y0 = f ( x0 ) = 0 y1 = f ( x1 ) = 1 -2 y2 = f ( x2 ) = 1 3 y 3 = f ( x 3 ) = -2 y4 = f ( x4 ) = 2 1 1 1 1 3 1 . y=x.4).y 0 + y 1 + y 2 + … + y n – 1 + -.

2.× 0 + -.+ 1 + ----.= ----------.T = ⎛ -.y) area = 4.= -n 4 2 y = f (x) = x 4 Numerical Analysis Using MATLAB® and Excel®. y=x.4). Third Edition Copyright © Orchard Publications 10−17 .= 4.= -n 4 2 y = f (x) = x x0 = a = 0 1 x 1 = a + Δx = -2 x 2 = a + 2Δx = 1 -x 3 = a + 3Δx = 3 2 x4 = b = 2 3 y0 = f ( x0 ) = 0 1 y 1 = f ( x 1 ) = -8 y2 = f ( x2 ) = 1 y 3 = f ( x 3 ) = 27 ----8 y4 = f ( x4 ) = 8 1 1 1 7 1 27 1 .25 ⎝ ⎠ 2 ⎝2 ⎠ 2 2 8 8 2 x=linspace(0. The exact value is 2 5 2 0 ∫0 4 xx dx = ---5 = 32 = 6. area=trapz(x.⎞ × -.+ -.= ⎛ 5 + -.= ----------. c.4 ----5 For the trapezoidal rule approximation we have x0 = a = 0 xn = b = 2 n = 4 b–a 2–0 1 Δx = ---------.× 8 ⎞ × -.Solution to End−of−Chapter Exercises x0 = a = 0 xn = b = 2 n = 4 b–a 2–0 1 Δx = ---------.^3.4444 The deviations from the exact value are due to the small number of divisions n we chose.

0625 ⎝ ⎠ 2 ⎝2 ⎠ 2 8 16 16 2 x=linspace(0.× 1 + 16 + 4 + 16 + -. y=x.+ -. Third Edition Copyright © Orchard Publications .2.= ⎛ ----------.y) area = 7..⎞ × -.+ 1 + ----.⎞ × -.5090 ⎝ 1918 ⎠ 4 ⎝2 2 4⎠ 4 25 9 49 10−18 Numerical Analysis Using MATLAB® and Excel®.× 0 + ----. The exact value is ∫1 2 1 ---.= 7.-. area=trapz(x.× 16 ⎞ × -.× -.= ----------.5720 d.⎞ × -.T = ⎛ -.^4.= ⎛ 9 + ----.dx = – 1 -2 x x 2 1 1 = -2 For the trapezoidal rule approximation we have x0 = a = 1 xn = b = 2 n = 4 b–a 2–1 1 Δx = ---------..= 0.Chapter 10 Integration by Numerical Methods x0 = a = 0 1 x 1 = a + Δx = -2 x 2 = a + 2Δx = 1 -x 3 = a + 3Δx = 3 2 x4 = b = 2 y0 = f ( x0 ) = 0 1 y 1 = f ( x 1 ) = ----16 y2 = f ( x2 ) = 1 y 3 = f ( x 3 ) = 81 ----8 y 4 = f ( x 4 ) = 16 1 1 1 41 1 81 1 .4).----.= -n 4 4 y = f (x) = 1 ⁄ x x0 = a = 1 -x 1 = a + Δx = 5 4 3 x 2 = a + 2Δx = -2 -x 3 = a + 3Δx = 7 4 x4 = b = 2 2 y0 = f ( x0 ) = 1 y 1 = f ( x 1 ) = 16 ----25 4 y 2 = f ( x 2 ) = -9 y 3 = f ( x 3 ) = 16 ----49 1 y 4 = f ( x 4 ) = -4 3905 1 1 1 1 1 ----.T = ⎛ -.

5000 Multiplier 0. B C D E Exercise 10.00000 4. h = (b-a)/n = x0=a= y0=x02= x1=a+h= y1=x12= x2=a+2h= y2=x22= x3=a+3h= y3=x32= x4=b= y4=x42= 0 2 4 0. function y = exer_10_2_a(x) y = x.Solution to End−of−Chapter Exercises x=linspace(1.31905 = 1 4.m as shown below. We name it exer_10_2_a. area=trapz(x.2.0.0000 2 2.6667 3 To use Simpson’s rule we construct the following table using a spreadsheet. We write and execute the following MATLAB script: y_std=quad('exer_10_2_a'.25000 2.= 2.a ∫ x 2 dx evaluated from a = 0 to b = 2 with n = 4 Numerical integration by Simpson's method follows Given a= b= n= Then.2.0000 Products We create and save a function m−file.0000 2.0000 16.50000 0.5158 2./x.00000 1.00000 0. y=1. 1 Area = -.^2. Third Edition Copyright © Orchard Publications 10−19 .4).0000 1 0.0000 4 1.^2.25000 1.6667 Numerical Analysis Using MATLAB® and Excel®.2) y_std = 2.h ( y 0 + 4y 1 + 2y 2 + 4y 3 + 2y 4 + … + 2y n – 2 + 4y n – 1 + y n ) 3 a. The exact value is ∫0 A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2 x x dx = ---3 2 3 2 0 8 = -.00000 0.00000 1.6667 4 9.y) area = 0.50000 2.00000 Sum of Products = Area = (h/3)*(Sum of Products) = (1/12)*8.

7854 4 To use Simpson’s rule we construct the following table using a spreadsheet.8284 1 0.m as shown below. 10−20 Numerical Analysis Using MATLAB® and Excel®.78540 0.7854 Multiplier 0. C D E Exercise 10.6569 2. function y = exer_10_2_b(x) y = sin(x).00000 2.57080 1.35619 0.2. The exact value is ∫0 1 1 -------------.00000 Sum of Products = Area = (h/3)*(Sum of Products) = (1/12)*8.= 0.8284 2 2.0000 7.00000 0.14159 0.Chapter 10 Integration by Numerical Methods b.00000 0.31905 = 1 0.pi) y_std = 2.0000 4 2. We name it exer_10_2_b.0000 c.0.0046 4 2. We write and execute the following MATLAB script: y_std=quad('exer_10_2_b'.70711 3.b ∫ sinxdx evaluated from a = 0 to b = π with n = 4 Numerical integration by Simpson's method follows Given a= b= n= Then. The exact value is π ∫0 sin x dx A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 B = – cos x π 0 = –( – 1 – 1 ) = 2 To use Simpson’s rule we construct the following table using a spreadsheet. h = (b-a)/n = x0=a= y0=sinx0= x1=a+h= y1=sinx1= x2=a+2h= y2=sinx2= x3=a+3h= y3=sinx3= x4=b= y4=sinx4= 0 3. Third Edition Copyright © Orchard Publications .0000 Products We create and save a function m−file.dx = tan – 1x 2 x +1 1 0 π = -.70711 1.14159 4 0.

5600 2 1.Solution to End−of−Chapter Exercises A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 B C D E Exercise 10. h = (b-a)/n = x0=a= y0=1/(x02+1)= x1=a+h= y1=1/(x12+1)= x2=a+2h= y2=1/(x22+1)= x3=a+3h= y3=1/(x32+1)= x4=b= y4=1/(x42+1)= 0 1 4 0.^2+1).94118 0.1) y_std = 0.6000 4 3.31905 = 1 0.m as shown below.25000 0.80000 0. Third Edition Copyright © Orchard Publications 10−21 .50000 0.c ∫ (1/(x 2 +1))dx evaluated from a = 0 to b = 1 with n = 4 Numerical integration by Simpson's method follows Given a= b= n= Then.0000 Products We create and save a function m−file. function y = exer_10_2_c(x) y = 1.2500 Multiplier 0.2.64000 1.5000 9./(x. We name it exer_10_2_c. We write and execute the following MATLAB script: y_std=quad('exer_10_2_c'.7647 1 1.4247 0.7854 Numerical Analysis Using MATLAB® and Excel®.50000 Sum of Products = Area = (h/3)*(Sum of Products) = (1/12)*8.00000 0.00000 0.7854 4 2.0.75000 0.00000 1.

the difference operator E is Ef ( x k ) = f ( x k + h ) = f ( x k + h ) (11. constant coefficient difference equation has the form ( ar E + ar – 1 E r r–1 + … + a 1 E + a 0 )y = φ ( x ) (11. physics. A difference equation is a specific type of recurrence relation.. a recurrence relation is an equation which defines a sequence recursively: each term of the sequence is defined as a function of the preceding terms.3). i.3) If.e. The discussion is limited to linear difference equations with constant coefficients. 11. and the subscript k is normally omitted. The Fibonacci numbers are defined. are used in numerous applications such as engineering. that is. and this type is discussed in this chapter. and r is a positive integer that denotes the order of the difference equation. and other sciences. mathematics. are discussed in Appendix A. and Applications The difference equations discussed in this chapter. we increase the argument of f by another unit. h = 1 . we obtain the second order operator E 2 .2) is written as Ef ( x ) = f ( x + 1 ) = f x + 1 (11.Chapter 11 Difference Equations T his chapter is an introduction to difference equations based on finite differences. The E operator increases the argument of a function by one interval h . Difference equations as used with discrete type systems. (11.2 Definition.1) where a k represents a constant coefficient and E is an operator similar to the D operator in ordinary differential equations. Solutions. Third Edition Copyright © Orchard Publications 11−1 .2) The interval h is usually unity. In terms of the interval h . Thus. 11.1 Introduction In mathematics. in (11. Numerical Analysis Using MATLAB® and Excel®. The general form of a linear. and a practical example in electric circuit theory is given at the end of this chapter.

Third Edition Copyright © Orchard Publications .3) is a linear combination of terms such as kx .9) where k 1 and k 2 are constants. then. If.1). Moreover. if C [ y 1 ( x ). where k is a non−zero constant and n is a non−negative integer. the linear combination k 1 y 1 ( x ) + k 2 y 1 ( x ) is also a solution.8) then. if Y ( x ) is any solution of (11. E f ( x ) = f ( x + r ) = fx + r n r As with ordinary differential equations. y 2 ( x ) ] = y1 ( x ) Ey 1 ( x ) y2 ( x ) Ey 2 ( x ) ≠0 (11. it reduces to ( a2 E + a1 E + a0 ) y = 0 2 (11. Also. and if ϕ ( x ) ≠ 0 . any other solution of (11.10) where ϕ ( x ) ≠ 0 . cos kx . we first find the solution of the homogeneous difference equation. it is a non−homogeneous difference equation. 11−2 Numerical Analysis Using MATLAB® and Excel®.11) As with ordinary differential equations. if.7) If y 1 ( x ) and y 2 ( x ) are any two solutions of (11.Chapter 11 Difference Equations E f ( x ) = E [ Ef ( x ) ] = Ef ( x + 1 ) = f ( x + 2 ) = f x + 2 2 (11. and x . then the complete solution is y = k1 y1 ( x ) + k2 y2 ( x ) + Y ( x ) (11.10). in (11. We find Y ( x ) by the Method of Undetermined Coefficients.5) and in general. that is.7).1). in (11.7) can be expressed as y3 ( x ) = k1 y1 ( x ) + k2 y2 ( x ) (11. we obtain the second order difference equation ( a2 E + a1 E + a0 ) y = φ ( x ) 2 (11.6) and if the right side is zero. analogous to the Wronskian determinant in ordinary differential equations. we let r = 2 . if the Casorati determinant. ϕ ( x ) = 0 .4) (11. is non−zero. For the non−homogeneous difference equation ( a 2 E + a 1 E + a 0 )y = φ ( x ) 2 (11. we add the particular solution Y ( x ) to it to obtain the total solution. the equation is referred to as a homogeneous difference equation. the right side of (11.

zero. Third Edition Copyright © Orchard Publications 11−3 .Definition. then. These cases are summarized in Table 11.13) and this is the characteristic equation of a second order difference equation. Solution: The characteristic equation of (11.14) with initial conditions y 0 = y ( 0 ) = 3 and y 1 = y ( 1 ) = 2 .13) can be real and unequal.7). real and equal. or negative. compute y 5 = y ( 5 ) .12) By substitution into (11.1. Solutions. we obtain a2 M x+2 + a1 M x+1 + a0 M x = 0 (11.1 Find the solution of the difference equation ( E – 6 E + 8 )y = 0 2 (11.14) is Numerical Analysis Using MATLAB® and Excel®. the roots of (11. TABLE 11. in analogy with the solution of the differential equation of the form y = ke .1 Roots of the characteristic equation in difference equations Characteristic equation a 2 M + a 1 M + a 0 = 0 of ( a 2 E + a 1 E + a 0 )y = 0 2 2 2 Roots M 1 and M 2 Real and Unequal M1 ≠ M2 Real and Equal M1 = M2 Discriminant a 1 – 4a 2 a 0 > 0 2 General Solution x x y = k1 M1 + k2 M2 k 1 and k 2 cons tan ts a 1 – 4a 2 a 0 = 0 2 x x y = k 1 M 1 + k 2 xM 2 k 1 and k 2 cons tan ts Complex Conjugates M1 = α + j β M2 = α –j β a 1 – 4a 2 a 0 < 0 2 x y = r ( C 1 cos θx + C 2 sin θx ) r = α +β 2 2 –1 β θ = tan --α Example 11. and Applications We have assumed that the coefficients a i in (11.10) are constants. As with algebraic quadratic equations. and recalling that Ef ( x ) = f ( x + 1 ) . or complex conjugates depending on whether the discriminant a 1 – 4a 2 a 0 is positive. Then. for the homogeneous difference equation we assume a solution of the form y = M x ax (11.

Then. r = and θ = tan ( 3 ⁄ ( – 1 ) ) = 2π ⁄ 3 .2 Find the solution of the difference equation ( E + 2E + 4 ) y = 0 2 (11.17) For the second initial condition. Then. Therefore.21) ( –1 ) + ( 3 ) = 2 2 2 and its roots are M 1 = – 1 + j 3 and M 2 = – 1 – j 3 . Third Edition Copyright © Orchard Publications .20) is M + 2M + 4 = 0 2 (11.16) To make use of the first initial condition. (11.1. we obtain the solution yx = y ( x ) = k1 2 + k2 4 x x (11.19) For x = 5 . with reference to Table 11. the solution is yx = 5 ⋅ 2 – 2 ⋅ 4 x x (11.15) and its roots are M 1 = 2 and M 2 = 4 . the solution is –1 11−4 Numerical Analysis Using MATLAB® and Excel®.1.Chapter 11 Difference Equations M –6 M + 8 = 0 2 (11. (11.16) becomes y0 = 3 = k1 2 + k2 4 0 0 or k1 + k2 = 3 (11. we obtain y 5 = 5 ⋅ 2 – 2 ⋅ 4 = 5 × 32 – 2 × 1024 = – 1888 5 5 Example 11. Thus.16) becomes y1 = 2 = k1 2 + k2 4 1 1 or 2k 1 + 4k 2 = 2 (11. we let x = 0 .20) Solution: The characteristic equation of (11. we let x = 1 .18) Simultaneous solution of (11. From Table 11.17) and (11. Therefore.18) yields k 1 = 5 and k 2 = – 2 .

Definition.23) The characteristic equation of (11. we start with a linear combination of all the terms of the right side.2 shows the form of the particular solution for different terms of φ ( x ) .2 Form of the particular solution for a non−homogeneous difference equation Non−homogeneous difference equation ( a 2 E + a 1 E + a 0 )y = φ ( x ) φ (x) α (constant) α x (k = positive integer) αk x k k 2 Form of Particular Solution Y ( x ) A (constant) Ak x + Ak – 1 x Ak x k–1 + … + A1 x + A0 α cos mx or α sin m x α x l cos mx or α x l sin m x k x k x A 1 cos mx + A 2 sin mx ( Akx + Ak – 1 x k k k–1 + … + A 1 x + A 0 ) l cos mx + … + B 1 x + B 0 ) l sin m x x x + ( Bk x + Bk – 1 x k–1 Example 11.x⎞ ⎝ 3 3 ⎠ (11. this choice must be multiplied by x until there is no duplication of terms. TABLE 11. we combine the particular solution with the solution of the homogeneous equation shown in (11. that is. Solutions. If any of the terms in the initial choice duplicates a term in the solution of the homogeneous equation.3 Find the solution of the difference equation Solution: ( E –5 E + 6 ) y = x + 2 2 x (11. Table 11.22) The constants C 1 and C 2 can be evaluated from the initial conditions.10).11). Third Edition Copyright © Orchard Publications 11−5 .23) is M –5 M + 6 = 0 2 (11. and we apply the operator E . For the particular solution.x + C 2 sin ----. and Applications x 2π 2π y = 2 ⎛ C 1 cos ----.24) Numerical Analysis Using MATLAB® and Excel®. For non−homogeneous difference equations of the form of (11. φ ( x ) .

**Chapter 11 Difference Equations
**

and its roots are M 1 = 2 and M 2 = 3 . From Table 11.1, the solution Y H of the homogeneous difference equation is

YH = k1 2 + k2 3

x x

(11.25)

x x x,

For the particular solution we refer Table 11.2. For the first term x of the right side of (11.23), we use the term A 1 x + A 0 , or Ax + B . For the second term 2 , we obtain A2 or C2 particular solution has the form

Y P = Ax + B + C2

x x

and thus, the

(11.26)

But the term C2 in (11.26), is also a term in (11.25). Therefore, to eliminate the duplication, we multiply the term C2 by x . Thus, the correct form of the particular solution is

Y P = Ax + B + Cx2

x x

(11.27)

To evaluate the constants

A,

**B , and C , we substitute (11.27) into (11.23). Then,
**

x+2

[A(x + 2) + B + C(x + 2) ⋅ 2

m+n

] – 5[A(x + 1) + B + C(x + 1) ⋅ 2 ] x x + 6 [ Ax + B + Cx2 ] = x + 2

m n

x+1

(11.28)

Using the law of exponents W

= W

**× W , simplifying, and equating like terms, we obtain
**

x

2Ax + ( – 3A + 2B ) – 2C2

= x+2

x

(11.29)

**Relation (11.29) will be true if
**

2A = 1 – 3A + 2B = 0 B = 0.75 – 2C = 1 C = – 0.5

or

A = 0.5

**By substitution into (11.28), we obtain the particular solution
**

Y P = 0.5x + 0.75 – 0.5 x2

x

(11.30)

**Therefore, the total solution is the sum of (11.25) and (11.30), that is,
**

y total = Y H + Y P = k 1 2 + k 2 3 + 0.5x + 0.75 – 0.5 x2

x x x

(11.31)

11−6

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Fibonacci Numbers 11.3 Fibonacci Numbers
**

The Fibonacci numbers are solutions of the difference equation

yx + 2 = yx + 1 + yx

(11.32)

that is, in a series of numbers, each number after the second, is the sum of the two preceding numbers. Example 11.4 Given that y 0 = 0 and y 1 = 1 , compute the first 12 Fibonacci numbers. Solution: For x = 0, 1, 2, 3 and so on, we obtain the Fibonacci numbers

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, …

We will conclude this chapter with an application to electric circuit analysis. Example 11.5 For the electric network of Figure 11.1, derive an expression for the voltage V x at each point P x where x = 0, 1, 2, …, n , given that the voltage V 0 at point P 0 is known.

P0 R P1

+

P2 R V1 2R

+

P3 R 2R

+

Pn – 3

+

Pn – 2

+

Pn – 1 R

+

Pn R

+

+

V0

−

2R

−

−

V2

−

V3

2R

−

R V n – 3 2R

−

V n – 2 2R

−

Vn – 1

Vn

−

. Solution:

Figure 11.1. Electric network for Example 11.5

We need to derive a difference equation that relates the unknown voltage V x to the known voltage V 0 . We start by drawing part of the circuit as shown in Figure 11.2, and we denote the voltages and currents as indicated.

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

11−7

**Chapter 11 Difference Equations
**

Px

+

Px + 1

R 2R

+

Px + 2

R

+

2R

−

Vx

−

V x + 1 2R

−

Vx + 2

Figure 11.2. Part of the circuit of Figure 11.1

**By application of Kirchoff’s Current Law (KCL) at node P x + 1 of Figure 11.2, we obtain
**

Vx + 1 – Vx Vx + 1 Vx + 1 – Vx + 2 -------------------------- + ------------- + -------------------------------- = 0 R R 2R

(11.33)

**and after simplification,
**

2 --- ( V x + 2 – 2.5 V x + 1 + V x ) = 0 R

**Of course, the term 2 ⁄ R cannot be zero. Therefore, we must have
**

V x + 2 – 2.5 V x + 1 + V x = 0

(11.34)

Relation (11.34) is valid for all points except P 1 and P n – 1 * as shown in Figure 11.1; therefore, we must find the current relations at these two points. Also, by application of Kirchoff’s current law (KCL) at node P 1 of Figure 11.1, we obtain

V1 – V0 V1 V1 – V2 ------------------ + ------ + ------------------ = 0 R R 2R

**and after simplification,
**

V 2 – 2.5V 1 + V 0 = 0

(11.35)

**Likewise, at node P n – 1 of Figure 11.1, we obtain
**

Vn – 1 – Vn – 2 Vn – 1 Vn – 1 – Vn -------------------------------- + ------------ + ------------------------- = 0 2R R R

**Observing that V n = 0 , and simplifying, we obtain
**

2.5V n – 1 – V n – 2 = 0

(11.36)

* The voltages at nodes P 0 and P n are V 0 and Vn respectively.

11−8

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

Fibonacci Numbers

Relation (11.35) is a difference equation of the form

( E – 2.5E + 1 ) y = 0

2

**where y = V x . Its characteristic equation is
**

M – 2.5M + 1 = 0

2

(11.37)

**The roots of the characteristic equation of (11.37) are M 1 = 0.5 and M 2 = 2 . Thus, the solution is
**

y = V x = k 1 ( 0.5 ) + k 2 ( 2 )

x x

(11.38)

The constant coefficients k 1 and k 2 in (11.38), are found by substitution of this relation into (11.35) and (11.36). Thus, from (11.37) and (11.38), we obtain

k 1 ( 0.5 ) + k 2 ( 2 ) – 2.5 ( k 1 ( 0.5 ) + k 2 ( 2 ) ) + V 0 = 0

2 2 1 1

or

0.25k 1 + 4k 2 – 1.25k1 – 5k 2 + V 0 = 0

or

k1 + k2 = V0

(11.39)

**Likewise, from (11.38) and (11.36) we obtain
**

n – 1⎞ n–2 1 n–1 1 n–2 2.5 ⎛ k 1 ⎛ -- ⎞ + k2 ( 2 ) – k 1 ⎛ -- ⎞ – k2 ( 2 ) = 0 ⎝ ⎝2⎠ ⎠ ⎝2⎠

or

k1 2.5k 1 n–1 n–2 ------------ + 2.5k 2 ( 2 ) – ----------- – k 2 ( 2 ) = 0 n–2 n–1 2 2

or

2 ( 2.5 )k 1 2.5k 2 ( 2 ) 4k 1 k 2 ( 2 ) -------------------- + ----------------------- – ------- – --------------- = 0 n n 2 4 2 2 k1 n ----- + k 2 ( 2 ) = 0 n 2

n n

or

(11.40)

**Simultaneous solution of (11.39) and (11.40) yields
**

2 k 1 = ---------------- V 0 2n 2 –1

2n

–1 k 2 = ---------------- V 0 2n 2 –1

(11.41)

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

11−9

**Chapter 11 Difference Equations
**

Finally, substitution of (11.41) into (11.38) yields a solution of the difference equation in terms of V 0 , that is,

x 2 1 x –1 y = V x = ---------------- V 0 ⎛ -- ⎞ + ---------------- V 0 ( 2 ) ⎝2⎠ 2n 2n 2 –1 2 –1

2n

or

⎛ 2 2n x⎞ V 0 y = V x = ⎜ ------- – 2 ⎟ ---------------⎝ 2x ⎠ 22 n – 1

(11.42)

**We observe that when x = 0 ,
**

2n V0 2 y = V x = ⎛ ------- – 1⎞ ---------------- = V 0 ⎝ 1 ⎠ 2n 2 –1

and when x = n ,

⎛ 2n V0 n⎞ V 0 n n ------y = V x = ⎜ 2 - – 2 ⎟ ---------------- = ( 2 – 2 ) ---------------- = 0 2n 2n n ⎝2 ⎠2 – 1 2 –1

11−10

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

Summary 11.4 Summary

• The general form of a linear, constant coefficient difference equation has the form

( ar E + ar – 1 E

r r–1

+ … + a 1 E + a 0 )y = φ ( x )

where a k represents a constant coefficient and E is an operator similar to the D operator in ordinary differential equations. As with ordinary differential equations, the right side is a linear combination of terms such as kx , cos kx , and x , where k is a non−zero constant and n is a non−negative integer. If ϕ ( x ) = 0 , the equation is referred to as a homogeneous difference equation, and if ϕ ( x ) ≠ 0 , it is a non−homogeneous difference equation. • The difference operator E is

Ef ( x k ) = f ( x k + h ) = f ( x k + h )

n

**The interval h is usually unity, i.e., h = 1 , and the subscript k is normally omitted. Thus, (11.3) is written as
**

Ef ( x ) = f ( x + 1 ) = f x + 1

and in general,

E f ( x ) = f ( x + r ) = fx + r

r

• If y 1 ( x ) and y 2 ( x ) are any two solutions of a homogeneous difference equation, the linear combination k 1 y 1 ( x ) + k 2 y 1 ( x ) , where k 1 and k 2 are constants, is also a solution. • If the Casorati determinant, analogous to the Wronskian determinant in ordinary differential equations, is non−zero, that is, if

C [ y 1 ( x ), y 2 ( x ) ] = y1 ( x ) Ey 1 ( x ) y2 ( x ) Ey 2 ( x ) ≠0

**then, any other solution of the homogeneous difference equation can be expressed as
**

y3 ( x ) = k1 y1 ( x ) + k2 y2 ( x )

**• For the non−homogeneous difference equation
**

( a 2 E + a 1 E + a 0 )y = φ ( x )

2

**where ϕ ( x ) ≠ 0 , if Y ( x ) is any solution of (11.11), then the complete solution is
**

y = k1 y1 ( x ) + k2 y2 ( x ) + Y ( x )

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

11−11

**Chapter 11 Difference Equations
**

As with ordinary differential equations, we first find the solution of the homogeneous difference equation; then, we add the particular solution Y ( x ) to it to obtain the total solution. We find Y ( x ) by the Method of Undetermined Coefficients. • In analogy with the solution of the differential equation of the form y = ke , for the homogeneous difference equation, we assume a solution of the form

y = M

x ax

**• Since Ef ( x ) = f ( x + 1 ) , the characteristic equation of a second order difference equation is
**

a2 M

x+2

+ a1 M

x+1

+ a0 M

x

= 0

and as with algebraic quadratic equations, the roots can be real and unequal, real and equal, or complex conjugates depending on whether the discriminant a 1 – 4a 2 a 0 is positive, zero, or negative. These cases are summarized in Table 11.1. • For non−homogeneous difference equations we combine the particular solution with the solution of the homogeneous equation. For the particular solution, we start with a linear combination of all the terms of the right side, that is, φ ( x ) , and we apply the operator E . If any of the terms in the initial choice duplicates a term in the solution of the homogeneous equation, this choice must be multiplied by x until there is no duplication of terms. The form of the particular solution for different terms of φ ( x ) is shown in Table 11.2. • The Fibonacci numbers are solutions of the difference equation

yx + 2 = yx + 1 + yx

2

that is, in a series of numbers, each number after the second, is the sum of the two preceding numbers.

11−12

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

Exercises 11.5 Exercises

Find the total solution of the following difference equations. 1. ( E + 7E + 12 ) y = 0 2. ( E + 2E + 2 ) y = 0 3. ( E – E – 6 ) y = x + 3 4. ( E + 1 ) y = sin x

2 2 2 2

x

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

11−13

**Chapter 11 Difference Equations 11.6 Solutions to End−of−Chapter Exercises
**

1. The characteristic equation is

( E + 7E + 12 ) y = 0 M + 7M + 12 = 0

2 2

**and its roots are M 1 = – 3 and M 2 = – 4 . Therefore, with reference to Table 11.1, we obtain the solution
**

yx = y ( x ) = k1 ( –3 ) + k2 ( –4 )

x x

(1)

The constants k 1 and k 2 can be evaluated from the initial conditions. Since they were not given, let us assume that y 0 = y ( 0 ) = 1 and y 1 = y ( 1 ) = 2 . To make use of the first initial condition, we let x = 0 . Then, (1) becomes

y0 = 1 = k1 ( –3 ) + k2 ( –4 )

0 0

or

k 1 + k 2 = 1 (2)

**For the second initial condition, we let x = 1 . Then, (1) becomes
**

y1 = 2 = k1 ( –3 ) + k2 ( –4 )

1 1

or

– 3 k 1 – 4k 2 = 2 (3)

**Simultaneous solution of (2) and (3) yields k 1 = 6 and k 2 = – 5 . Thus, the solution is
**

yx = y ( x ) = 6 × ( – 3 ) –5 × ( –4 )

x x

**2. The characteristic equation is
**

( E + 2E + 2 ) y = 0 M + 2M + 2 = 0

2 2

**and its roots are M 1 = – 1 + j and M 2 = – 1 – j . From Table 11.1, r =
**

θ = tan 1 ⁄ ( – 1 ) = – π ⁄ 4 . Therefore, the solution is y = 2 ( C 1 cos ( – π ⁄ 4 )x + C 2 sin ( – π ⁄ 4 )x )

x

–1

( –1 ) + ( 1 ) =

2

2

2 and

11−14

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

**Solutions to End−of−Chapter Exercises
**

The constants C 1 and C 2 can be evaluated from the initial conditions. For this exercise, they were not given. 3. The characteristic equation is

(E – E – 6) y = x + 3 M –M – 6 = 0

2 2

x

**and its roots are M 1 = – 2 and M 2 = 3 From Table 11.1, the solution Y H of the homogeneous difference equation is
**

Y H = k 1 ( – 2 ) + k 2 3 (1)

x x

For the particular solution we refer Table 11.2. For the first term x of the right side of the given equation we use the term A 1 x + A 0 , or Ax + B . For the second term 3 , we obtain A3 or C3

x, x x

**and thus, the particular solution has the form
**

Y P = Ax + B + C3

x x x

But the term C3 is also a term in the given equation. Therefore, to eliminate the duplication, we multiply the term C3 by x . Thus, the correct form of the particular solution is

Y P = Ax + B + Cx3

x

(2)

To evaluate the constants equation. Then,

A,

**B , and C , we substitute the last expression above into the given
**

x+2 x+1

[A(x + 2) + B + C(x + 2) ⋅ 3

m+n

] –[ A ( x + 1 ) + B + C ( x + 1 ) ⋅ 3 ] x x – 6 [ Ax + B + Cx3 ] = x + 3

m

Using the law of exponents W obtain

= W

× W , simplifying, and equating like terms, we

n

– 6 Ax + ( A – 6 B ) + 15C3

x

= x+3

x

**This relation will be true if
**

– 6A = 1 A –6 B = 0 B = 1 ⁄ 36 15C = 1 C = 1 ⁄ 15

or

A = –1 ⁄ 6

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

11−15

**Chapter 11 Difference Equations
**

By substitution into (2), we obtain the particular solution

Y P = ( – 1 ⁄ 6 )x + 1 ⁄ 36 + ( 1 ⁄ 15 )x2

x

(3)

**Therefore, the total solution is the sum of (1) and (3), that is,
**

y total = Y H + Y P = k 1 ( – 2 ) + k 2 3 + ( – 1 ⁄ 6 )x + 1 ⁄ 36 + ( 1 ⁄ 15 )x2

x x x

**4. The characteristic equation is
**

( E + 1 ) y = sin x (1) M +1 = 0

2 2

**and its roots are M 1 = j and M 2 = – j From Table 11.1, r = of the solution is
**

( 1 ) = 1 and θ = tan 1 ⁄ 0 = π ⁄ 2 . Therefore, the homogeneous part Y H = C 1 cos ( π ⁄ 2 )x + C 2 sin ( π ⁄ 2 )x (2)

2 –1

For the particular solution we refer Table 11.2 where we find that the solution has the form A 1 cos mx + A 2 sin mx , and for this exercise

Y P = A cos x + B sin x

Since the cosine and sine terms appear in the complimentary solution, we multiply the terms of the particular solution by x and we obtain

Y P = Ax cos x + Bx sin x (3)

To evaluate the constants we obtain Using the trig identities

A,

B , and C , we substitute the last expression above into (1) and

A ( x + 2 ) cos ( x + 2 ) + B ( x + 2 ) sin ( x + 2 ) + Ax cos x + Bx sin x = sin x

cos ( a + b ) = cos acos b – sin asin b sin ( a + b ) = sin acos b – sin b cos a

**expanding, rearranging, equating like terms, and combining the complimentary and particular solutions we obtain
**

π π sin x + sin ( x – 2 ) y = C 1 cos -- x + C 2 sin -- x + ----------------------------------------2 2 2 ( 1 + cos 2 )

11−16

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

Chapter 12

Partial Fraction Expansion

his chapter is an introduction to partial fraction expansion methods. In elementary algebra we learned how to combine fractions over a common denominator. Partial fraction expansion is the reverse process and splits a rational expression into a sum of fractions having simpler denominators.

T

**12.1 Partial Fraction Expansion
**

The partial fraction expansion method is used extensively in integration and in finding the inverses of the Laplace, Fourier, and Z transforms. This method allows us to decompose a rational polynomial into smaller rational polynomials with simpler denominators, from which we can easily recognize their integrals or inverse transformations. In the subsequent discussion we will discuss the partial fraction expansion method and we will illustrate with several examples. We will also use the MATLAB residue(r,p,k) function which returns the residues (coefficients) r of a partial fraction expansion, the poles p and the direct terms k. There are no direct terms if the highest power of the numerator is less than that of the denominator. Let

----------F(s) = N(s) D(s)

(12.1)

**where N ( s ) and D ( s ) are polynomials and thus (12.1) can be expressed as
**

bm s + bm – 1 s + bm – 2 s + … + b1 s + b0 N(s) F ( s ) = ----------- = ------------------------------------------------------------------------------------------------------------------n n–1 n–2 D(s) an s + an – 1 s + an – 2 s + … + a1 s + a0

m m–1 m–2

(12.2)

The coefficients a k and b k for k = 0, 1, 2, …, n are real numbers and, for the present discussion, we have assumed that the highest power of N ( s ) is less than the highest power of D ( s ) , i.e., m < n . In this case, F ( s ) is a proper rational function. If m ≥ n , F ( s ) is an improper rational function. It is very convenient to make the coefficient a n of s in (12.2) unity; to do this, we rewrite it as

1 ---- ( b m s m + b m – 1 s m – 1 + b m – 2 s m – 2 + … + b 1 s + b 0 ) an N(s) F ( s ) = ----------- = -----------------------------------------------------------------------------------------------------------------------------a1 D(s) a0 n an – 1 n – 1 an – 2 n – 2 + ---------- s + … + ---- s + ---s + ---------- s an an an an

n

(12.3)

Numerical Analysis Using MATLAB® and Excel®, Third Edition Copyright © Orchard Publications

12−1

8) 12−2 Numerical Analysis Using MATLAB® and Excel®. (12.7) below.1 Use partial fraction expansion to simplify F 1 ( s ) of (12. then. However.+ ----------------.3) . To evaluate the residue r k . or repeated.3) can be real and distinct. p 2. The roots of the denominator are called the poles of F ( s ) and are found by letting D(s) = 0 .5) by ( s – p k ) . we can factor the denominator of F ( s ) in the form N(s) F ( s ) = ------------------------------------------------------------------------------------------------( s – p1 ) ⋅ ( s – p2 ) ⋅ ( s – p3 ) ⋅ … ⋅ ( s – pn ) (12.= --------------. p 3. …. that is. and are found by letting N ( s ) = 0 in (12.Chapter 12 Partial Fraction Expansion The roots of the numerator are called the zeros of F ( s ) . we multiply both sides of (12.4) where p k is distinct from all other poles. The zeros and poles of (12.+ ----------------.= -------------------------------. …. Then. the partial fraction expansion method allows us to express (12. r 2. r n are the residues of F ( s ) . or combinations of real and complex conjugates. We will consider the nature of the poles for each case.5) where r 1. 3s + 2 F 1 ( s ) = ------------------------2 s + 3s + 2 (12. Third Edition Copyright © Orchard Publications .7) Solution: r2 r1 3s + 2 3s + 2 F 1 ( s ) = ------------------------.6) r k = lim ( s – p k )F ( s ) = ( s – p k )F ( s ) s → pk s = pk Example 12.+ --------------2 (s + 1) (s + 2) (s + 1)(s + 2) s + 3s + 2 3s + 2 r 1 = lim ( s + 1 )F ( s ) = --------------(s + 2) s → –1 = –1 s = –1 (12. or complex conjugates. we let s → p k . in most engineering applications we are interested in the nature of the poles.4) as r2 r3 rn r1 F ( s ) = ----------------. Case I: Distinct Poles If all the poles p 1. r 3.+ … + ----------------( s – p1 ) ( s – p2 ) ( s – p3 ) ( s – pn ) (12. p n of F ( s ) are distinct (different from each another).

and k vectors. poles. we observe that the highest power of the denominator is s 2 whereas the highest power of the numerator is s and therefore. [r.9) We can us the MATLAB residue(r. These expressions are * Of course. k] = residue(Ns. MATLAB displays the r. p. the direct term k is empty. 2].* This function returns an expression that contains the prime factors of a polynomial.= --------------.+ --------------2 (s + 1) (s + 2) s + 3s + 2 (12. Numerical Analysis Using MATLAB® and Excel®. p. these represent the residues. this function is used with symbolic expressions.10) Solution: First. and it is always empty (has no value) whenever F ( s ) is a proper rational function. The first value of the vector r is associated with the first value of the vector p. the second value of r is associated with the second value of p. we obtain 4 3s + 2 –1 F 1 ( s ) = ------------------------.p. and direct terms respectively. 3s 2 + 2s + 5 F 2 ( s ) = -----------------------------------------------s 3 + 12s 2 + 44s + 48 (12. we will use the MATLAB function factor(s) to express the denominator polynomial of F 2 ( s ) in factored form. we can use the roots(p) function. and so on.8). However.Partial Fraction Expansion 3s + 2 r 2 = lim ( s + 2 )F ( s ) = --------------(s + 1) s → –2 = 4 s = –2 Therefore. Third Edition Copyright © Orchard Publications 12−3 . Ds = [1. 2]. by substitution into (12.2 Use partial fraction expansion to simplify F 2 ( s ) of (12. 3.k) function to verify our answers with the following script: Ns = [3.10) below. The factor(s) function is a good alternative. Ds) r = 4 -1 p = -2 -1 k = [] where we have denoted Ns and Ds as two vectors that contain the numerator and denominator coefficients of F 1 ( s ) . Example 12. The vector k is referred to as the direct term. For this example.

we can use the syms function to define one or more symbolic variables with a single statement.= --------------.+ --------------. sin x 2 e – αt d. we find the residues r 1 . r 2 . they produce numerical results. and r 3 . a1 and k2 . on the other hand.+ --------------2 3 (s + 2) (s + 4) (s + 6) s + 12s + 44s + 48 2 12−4 Numerical Analysis Using MATLAB® and Excel®. like roots(p). they are discussed in detail in MATLAB User’s Manual. The functions. For the present. These are 3s + 2s + 5 r 1 = -------------------------------( s + 4 )( s + 6) 2 s = –2 9 = -8 3s + 2s + 5 r 2 = -------------------------------(s + 2)(s + 6) 2 s = –4 37 =– ----4 3s + 2s + 5 r 3 = -------------------------------(s + 2)(s + 4) 2 s = –6 89 = ----8 Therefore. Some examples of symbolic expressions are given below.+ --------------. syms x y z a1 k2 defines the symbolic variables x . For example.= --------------. 2 2 r1 r2 r3 3s + 2s + 5 3s + 2s + 5 F 2 ( s ) = -----------------------------------------------. Third Edition Copyright © Orchard Publications . s . which we have used before. are display numeric expressions. Before using symbolic expressions. This is a collection of tools (functions) which are used in solving symbolic expressions. y .3 2 y = -----. t etc.10) as a product of simple factors. that is. z . s = sym (‘s’) creates the symbolic variable s . factor(den) ans = (s+4)*(s+2)*(s+6) and thus. For example.2 and using MATLAB we have: syms s.= ------------------------------------------------. This is done with the sym function. Alternately. Symbolic expressions. Returning to Example 12. our interest is in using the factor(s) to express the denominator of (12.Chapter 12 Partial Fraction Expansion explained below. y . den=s^3+12*s^2+44*s+48.+ --------------2 3 (s + 2)(s + 4)(s + 6) (s + 2) (s + 4) (s + 6) s + 12s + 44s + 48 Next. can manipulate mathematical expressions without using actual numbers.dx x 1 MATLAB contains the so-called Symbolic Math Toolbox. we must create a symbolic variable x . 9⁄8 – 37 ⁄ 4 89 ⁄ 8 3s + 2s + 5 F 2 ( s ) = -----------------------------------------------.( 3t – 4t + 5t + 8 ) 2 dt 2 u = ∫ -.

the poles of a proper rational function F ( s ) are complex. s+3 s+3 F 3 ( s ) = -----------------------------------------. roots_p=roots(p) roots_p = -2. we express the denominator in factored form to identify the poles of F 3 ( s ) . the factor(s) function does not seem to work with complex numbers.+ -----------------------2 3 ( s + 1 ) ( s + 2 + j2 ) ( s + 2 – j 2 ) s + 5s + 12s + 8 (12. Thus if p k is a complex pole.3 Use partial fraction expansion to simplify F 3 ( s ) of (12.0000i Then.+ --------------------------. and since complex poles occur in complex conjugate pairs.= --------------. Third Edition Copyright © Orchard Publications 12−5 . then its complex conjugate p k∗ is also a pole. p=[1 4 8]. The partial fraction expansion method can also be used in this case.11) Solution: As a first step. we will use the roots(p) function to find its roots by treating it as a polynomial.Partial Fraction Expansion Case II: Complex Poles Quite often. factor(s^3 + 5*s^2 + 12*s + 8) we obtain ans = (s+1)*(s^2+4*s+8) Since the factor(s) function did not factor the quadratic term*.12) and the residues are * For some undocumented reason.0000i -2. s+3 F 3 ( s ) = -----------------------------------------3 s + 5s 2 + 12s + 8 (12.0000+2. as illustrated by the following example.0000-2. Numerical Analysis Using MATLAB® and Excel®. Example 12.11) below. the number of complex poles is even.= -----------------------------------------------------------------------2 3 ( s + 1 ) ( s + 2 + j2 ) ( s + 2 – j2 ) s + 5s + 12s + 8 r1 r2 r3 s+3 = -----------------------------------------. Using the MATLAB script syms s.

= ----------------– 8 – j4 ( – 1 + j2 ) ( j4 ) 3) ( 1 – j2 ) .= ( – 16 ) – j 12 = – 1 – j ----------------------------( – 8 – j4 ) ( – 8 + j4 ) 5 20 80 Of course.= – -. F ( s ) has simple poles but one of the poles.= -----------------------.15) and denoting the m residues corresponding to multiple pole p 1 as r 11.+ ---------------------------------(s + 2) ( s + 2 + j2 ) ( s + 2 –j 2 ) (12. Third Edition Copyright © Orchard Publications . r 12. Then. N(s) F ( s ) = ------------------------------------------------------------------------------------------m ( s – p 1 ) ( s – p 2 )… ( s – p n – 1 ) ( s – p n ) (12.14) Case III: Multiple (Repeated) Poles In this case. Then.– -.Chapter 12 Partial Fraction Expansion s+3 r 1 = ------------------------2 s + 4s + 8 2 = -5 1 – j2 1 – j2 = -----------------------------------. the partial fraction expansion of (12.F 3 ( s ) = --------------. … r 1m .---------------------.15) can be expressed as 12−6 Numerical Analysis Using MATLAB® and Excel®.13) We can express (12.– j ----⎝ 5 20⎠ 5 20 and this is always true since complex roots occur in conjugate pairs.( – 8 + j4 = ---------------------.12).---------------------. This is done by combining the last two terms on the right side of (12.13) to form a single term and now is written as 2⁄5 1 ( 2s + 1 ) . the last evaluation was not necessary since r 3 = r 2∗ or 3 * 3 1 1 r 3 = ⎛ – -. by substitution into (12.+ j ----( – 8 + j4 ) ( – 8 – j4 ) 80 5 20 s+3 r 3 = -------------------------------------------( s + 1 ) ( s + 2 + j2 ) s = – 2 + j2 1 – j2 1 – j2 = --------------------------------.13) in a different form if we want to eliminate the complex presentation.+ j -----⎞ = – -.⋅ -----------------------------( s + 2 ) 5 ( s 2 + 4s + 8 ) (12.+ ----------------------------------. we obtain 2⁄5 – 1 ⁄ 5 + j3 ⁄ 20 – 1 ⁄ 5 – j3 ⁄ 20 F 3 ( s ) = --------------. has a multiplicity m . say p 1 .= -----------------( – 1 – j2 ) ( – j4 ) – 8 + j4 s = –1 s+3 r 2 = ----------------------------------------( s + 1 ) ( s + 2 –j 2 ) s = – 2 – j2 3 ( 1 – j2 ) ( – 8 – j4 ) – 16 + j12 1 = ---------------------.

( s – p 1 ) F ( s ) = r 11 + ( s – p 1 )r 12 + ( s – p 1 ) r 13 + … + ( s – p 1 ) m 2 m–1 r 1m r2 r3 rn m + ( s – p 1 ) ⎛ ----------------. Then. that is.18) with respect to s .21) Numerical Analysis Using MATLAB® and Excel®.+ ----------------.18) twice with respect to s .+ ----------------( s – p2 ) ( s – p3 ) ( s – pn ) (12.⎞ ⎝(s – p ) (s – p ) ( s – p n )⎠ s → p1 2 3 or r 11 = lim ( s – p 1 ) F ( s ) s → p1 m (12.+ … + ----------------m m–1 m–2 ( s – p1 ) ( s – p1 ) ( s – p1 ) ( s – p1 ) r3 rn r2 + ----------------.+ ----------------.20) To find the third residue r 13 of the repeated pole p 1 .17). we let s → p 1 .⎞ ⎝(s – p ) (s – p ) ( s – p n )⎠ 2 3 (12.[ ( s – p 1 ) F ( s ) ] s → p 1 ds (12.+ ---------------------------.16) by ( s – p 1 ) . To find the second residue r 12 of the second repeated pole p 1 .Partial Fraction Expansion r 11 r 12 r 13 r 1m F ( s ) = --------------------. we first differentiate the relation of (12. Third Edition Copyright © Orchard Publications 12−7 . we obtain s → p1 lim ( s – p 1 ) F ( s ) 2 m–1 s → p1 m = r 11 + lim [ ( s – p 1 )r 12 + ( s – p 1 ) r 13 + … + ( s – p 1 ) r 1m ] (12. then. m d r 12 = lim ---. … p n we proceed as before. we differentiate (12.+ … + ----------------. m d r 13 = lim ------.[ ( s – p1 ) F ( s ) ] s → p 1 ds 2 2 (12.+ ----------------.16) For the simple poles p 1. r k = lim ( s – p k )F ( s ) = ( s – p k )F ( s ) s → pk s = pk m To find the first residue r 11 of the repeated pole.19) and thus (12. p 2.19) yields the residue of the first repeated pole.17) Next. we multiply both sides of (12. that is.18) r3 rn r2 m + lim ( s – p 1 ) ⎛ ----------------.+ ---------------------------. then. taking the limit as s → p 1 on both sides of (12.+ … + ----------------. we let s → p 1 . that is.

26).s + 3 r 22 = ---.= --------------. s+3 1 2 –1 F 4 ( s ) = ----------------------------------. Third Edition Copyright © Orchard Publications .23) or d m 1 r 1k = lim -----------------.= --------------. s+3 F 4 ( s ) = ----------------------------------2 (s + 2)(s + 1) (12. by substitution into (12.[ ( s – p 1 ) F ( s ) ] s → p 1( k – 1 )! ds k – 1 k–1 (12.25) Solution: We observe that there is a pole of multiplicity 2 at s = – 1 and thus.+ -----------------.25) below.+ --------------2 2 (s + 2) (s + 1) (s + 1) (s + 2)(s + 1) (12.------------. In general.26) The residues are s+3 r 1 = -----------------2 (s + 1) s + 3r 21 = --------------(s + 2) = 1 s = –2 = 2 s = –1 d.⎛ ---------.[ ( s – p 1 ) F ( s ) ] k–1 s → p 1 ds k–1 (12.Chapter 12 Partial Fraction Expansion This process is continued until all residues of the repeated poles have been found.24) Example 12. (12.+ --------------2 ( s + 2 ) ( s + 1 )2 ( s + 1 ) (s + 2)(s + 1) 12−8 Numerical Analysis Using MATLAB® and Excel®.4 Use partial fraction expansion to simplify F 4 ( s ) of (12. for repeated poles the residue r 1k can be derived from the relation ( s – p 1 ) F ( s ) = r 11 + r 12 ( s – p 1 ) + r 13 ( s – p 1 ) + … m 2 (12.25) in partial fraction expansion form is r 21 r1 r 22 s+3 F 4 ( s ) = ----------------------------------.22) whose ( m – 1 )th derivative of both sides is d m ( k – 1 )!r 1k = lim ------------.+ -----------------.⎞ ds ⎝ s + 2 ⎠ s = –1 (s + 2) – (s + 3) = -------------------------------------2 (s + 2) = –1 s = –1 Then.

k]=residue(Ns.Ds) r = 1.0000 -1.0000 2. we will use the expand(s) function. % Multiplies polynomials d1 and d2 to express denominator D(s) as polynomial [r. it is true for any value of s. % Coefficients of the numerator N(s) d1 = [1 2 1].p. the residue r 22 could be found by substitution of the already known values of r 1 and r 21 into (12. % Coefficients of (s + 1)^2 = s^2 + 2*s + 1 term in D(s) d2 = [0 1 2]. Third Edition Copyright © Orchard Publications 12−9 .0000 p = -2. Its description can be displayed with the help expand command. and letting s = 0 *. expand(s) is used with symbolic expressions. that is. s+3 ----------------------------------2 (s + 1) (s + 2) 1 = --------------(s + 2) 2 + -----------------2 (s + 1) s=0 r 22 + --------------(s + 1) s=0 s=0 s=0 or 3 ⁄ 2 = 1 ⁄ 2 + 2 + r 22 from which r 22 = – 1 as before.0000 -1.0000 k = [] Example 12.45) is an identity. To check our answers with MATLAB.27) below. % Coefficients of (s + 2) term in D(s) Ds=conv(d1. *We must remember that (2.26).Partial Fraction Expansion Instead of differentiation. Check with MATLAB: syms s expand((s + 1)^2) % Create symbolic variable s % Express it as a polynomial ans = s^2+2*s+1 Ns = [1 3].d2). Like the factor(s) function. and as such.5 Use partial fraction expansion to simplify F 5 ( s ) of (12.0000 -1. Numerical Analysis Using MATLAB® and Excel®.

and a pole of multiplicity 2 at s = – 2 .30) s = –1 ( s + 2 ) ( 2s + 3 ) – 2 ( s + 2 ) ( s + 3 s + 1 ) = --------------------------------------------------------------------------------------------4 (s + 2) s+4 = -----------------.+ -----------------. Third Edition Copyright © Orchard Publications .⎜ ------------------------.⎟ ds ⎝ ( s + 2 ) 2 ⎠ 2 s = –1 2 (12.⎛ -----------------.28) We find the residue r 11 by evaluating F 5 ( s ) at as s = – 1 r 11 = s + 3 s + 1 ------------------------2 (s + 2) 2 = –1 s = –1 (12. Then.--------------------------------------------------------------6 2 (s + 2) –s–5 = -----------------4 (s + 2) = –4 s = –1 (12. in partial fraction expansion form r 21 r 11 r 12 r 13 r 22 F 5 ( s ) = -----------------. 12−10 Numerical Analysis Using MATLAB® and Excel®.29) The residue r 12 is found by first taking the first derivative of F 5 ( s ) .---. 2 d.s + 4 = -.⎟ 2! ds 2 ⎝ ( s + 2 ) 2 ⎠ 2 1 d d ⎛ s + 3 s + 1⎞ .⎛ s + 3 s + 1⎞ r 12 = ---.⎜ ------------------------. and the residue r 22 is found by first taking the first derivative of F 5 ( s ) and evaluating it at s = – 2 .27) Solution: We observe that there is a pole of multiplicity 3 at s = – 1 .⎞ 2 ds ⎝ ( s + 2 ) 3 ⎠ s = –1 1 (s + 2) – 3(s + 2) (s + 4) = -.+ --------------.⎜ -------------------------⎟ 2 ds ds ⎝ ( s + 2 ) 2 ⎠ 3 2 s = –1 s = –1 1 d..⎞ 4 ⎠ 2⎝ (s + 2) s = –1 Similarly.r 13 = ---.Chapter 12 Partial Fraction Expansion s2 + 3 s + 1 F 5 ( s ) = ------------------------------------( s + 1 )3 ( s + 2 )2 (12.+ --------------3 2 ( s + 1 ) ( s + 2 )2 ( s + 2 ) (s + 1) (s + 1) (12. Thus.= 3 3 (s + 2) The residue r 13 is found by taking the second derivative of F 5 ( s ) and evaluating it at s = – 1 .= -. the residue r 21 if found by evaluating F 5 ( s ) at s = – 2 .+ -----------------. 2 2 1 d ⎛ s + 3 s + 1⎞ .---. and evaluating it at s = – 1 .---. Then.31) 1 s + 2 – 3s – 12 = -. Therefore.⎛ ---------------------------------.------.

⎜ ------------------------.+ -----------------. We must remember that the conv(p.p.k]=residue(Ns. Third Edition Copyright © Orchard Publications 12−11 .⎟ ds ⎝ ( s + 1 ) 3 ⎠ 3 s = –2 2 2 = ( s + 1 ) ( 2s + 3 ) – 3 ( s + 1 ) ( s + 3 s + 1 ) -------------------------------------------------------------------------------------------------6 (s + 1) ( s + 1 ) ( 2s + 3 ) – 3 ( s + 3 s + 1 ) r 22 = ---------------------------------------------------------------------------4 (s + 1) 2 s = –2 2 s = –2 – s – 4s = -------------------4 (s + 1) = 4 s = –2 By substitution of these residues into (12.+ -----------------. % We must first define the variable s in symbolic form % The function "collect" below multiplies (s+1)^3 by (s+2)^2 Ds=collect(((s+1)^3)*((s+2)^2)) Ds = s^5+7*s^4+19*s^3+25*s^2+16*s+4 % We now use this result to express the denominator D(s) as a % polynomial so we can use its coefficients with the "residue" function % Ns=[1 3 1]. syms s. The MATLAB script for this example is as follows.0000 1.q) function is used with numeric expressions. we obtain F 5 ( s ) in partial fraction expansion as –1 3 –4 1 4 F 5 ( s ) = -----------------. we introduce the collect(s) function that we can use to multiply two or more symbolic expressions to obtain the result in a polynomial form.32) We will now verify the values of these residues with MATLAB.28).e.Ds) r = 4. Its description can be displayed with the help collect command. Before we do this.+ --------------..0000 -4.0000 Numerical Analysis Using MATLAB® and Excel®.0000 -1. Ds=[1 7 19 25 16 4].+ --------------3 2 ( s + 1 ) ( s + 2 )2 ( s + 2 ) (s + 1) (s + 1) (12. [r. polynomial coefficients only. i.Partial Fraction Expansion s + 3s + 1 r 21 = ------------------------3 (s + 1) 2 = 1 s = –2 2 d ⎛ s + 3 s + 1⎞ r 22 = ---.0000 3.

m > n and thus we need to express F 6 ( s ) in the form of (12.. the highest power m of the numerator is less than the highest power n of the denominator.33) so that m < n . Ds = [1 1]. Third Edition Copyright © Orchard Publications 12−12 .35) Check with MATLAB: Ns = [1 2 2]. F ( s ) is an improper rational function. Example 12.+ s + 1 s+1 s+1 2 (12.0000 -2.33). was based on the condition that F ( s ) is a proper rational function.= ---------. i. p. k] = residue(Ns. 1 s + 2s + 2 F 6 ( s ) = ------------------------. If m ≥ n .0000 k = [] Case for m ≥ n Our discussion thus far. Ds) r = 1 p = -1 k = 1 1 Numerical Analysis Using MATLAB® and Excel®.34) below in partial expansion form. we must divide the numeraror N ( s ) by the denominator D ( s ) to obtain an expression of the form F ( s ) = k0 + k1 s + k2 s + … + km – n s 2 m–n N(s) + ----------D(s) (12. that is. [r. s + 2s + 2 F 6 ( s ) = ------------------------s+1 2 (12.34) Solution: In (12.e. and before we apply the partial fraction expansion. m < n .0000 -1. By long division.0000 -1.6 Express F 6 ( s ) of (12.Chapter 12 Partial Fraction Expansion p = -2.0000 -1.34).

3.2 Alternate Method of Partial Fraction Expansion The partial fraction expansion method can also be performed by the equating the numerators procedure thereby making the denominators of both sides the same. We multiply each term of the right side by the appropriate factor to make the denominators of (12. we first perform a long division and then work with the quotient and the remainder as before. Then.7 Express F 7 ( s ) of (12.54). To this factor. we assign the sum of n partial fractions as shown below. 4. We set the given F ( s ) equal to the sum of these partial fractions. We solve the resulting equations for the residues. we let s – a be a linear factor of D ( s ) and we suppose that ( s – a ) is the highest power of s – a that divides D ( s ) . We assume that the degree on the numerator N ( s ) is less than the degree of the denominator. 7. let s 2 + αs + β be a quadratic factor of D ( s ) and suppose that ( s 2 + αs + β ) is the highest power of this factor that divides F ( s ) . r2 s + k2 r1 s + k1 rn s + kn -------------------------. Example 12.+ --------------------------------.+ ----------------. Third Edition Copyright © Orchard Publications 12−13 . Numerical Analysis Using MATLAB® and Excel®. 5. We repeat Step 1 for each of the distinct linear and quadratic factors of D ( s ) . We also assume that the denominator D ( s ) can be expressed as a product of real linear and quadratic factors. If not. We equate the coefficients of corresponding powers of s.38) below as a sum of partial fractions using the equating the numerators procedure. If these assumptions prevail. Now. we can express F ( s ) as rm r1 r2 ----------F ( s ) = N ( s ) = ---------. and then equating the numerators.+ … -----------------2 D(s) s – a (s – a) ( s – a )m n m (12. 6.36) Next. we perform the following steps: 1.37) both sides equal. We arrange the terms of both sides in decreasing powers of s . 12.+ … + --------------------------------2 2 n 2 s + αs + β ( s 2 + αs + β ) ( s + αs + β ) 2.Alternate Method of Partial Fraction Expansion The direct terms k = [ 1 1 ] are the coefficients of the s term and the constant in (2.

we obtain 4 = 2r 1 or r 1 = 2 (12.= -----------------. we obtain 0 = 2 + r 22 or r 22 = – 2 (12.Chapter 12 Partial Fraction Expansion – 2s + 4 F 7 ( s ) = ------------------------------------2 2 (s + 1)(s – 1) (12. we obtain 0 = r 1 + r 22 0 = – 2r 1 + A – r 22 + r 21 – 2 = r 1 – 2A + r 22 4 = A – r 22 + r 21 (12.45) and using the fourth equation of (12.43) and by substitution into the first equation of (12.42) Subtracting the second equation from the fourth in (12. – 2s + 4 = ( r 1 + r 22 )s 3 + ( – 2r 1 + A – r 22 + r 21 )s 2 + ( r 1 – 2A + r 22 ) s + ( A – r 22 + r 21 ) (12.42. the coefficients of each power of s on the left and right sides are equal.– --------------2 2 2 2 (s – 1) (s + 1)(s – 1) (s + 1) (s – 1) 12−14 Numerical Analysis Using MATLAB® and Excel®.+ ----------------. Accordingly. and 7.42). – 2s + 4 = ( r 1 s + A ) ( s – 1 ) 2 + r 21 ( s + 1 ) + r 22 ( s – 1 ) ( s + 1 ) 2 2 (12.43) and (12. we obtain: 4 = 1 + 2 + r 21 or r 21 = 1 (12.= -----------------.42).41) is an identity in s . r 21 r1 s + A r 22 – 2s + 4 F 7 ( s ) = ------------------------------------.38) Solution: By Steps 1 through 3 above. yields – 2 = 2 – 2A – 2 or A = 1 (12.+ --------------2 2 2 2 (s – 1) (s + 1)(s – 1) (s + 1) (s – 1) (12. 6.39) By Step 4.44) into the third equation of (12. substitution of (12. Third Edition Copyright © Orchard Publications . by equating like powers of s .40) and by Steps 5.42). therefore.44) Next.+ ----------------.46) Therefore F 7 ( s ) in partial fraction expansion form becomes 1 – 2s + 4 2s + 1 2 F 7 ( s ) = ------------------------------------.41) Relation (12.

51).3. we obtain 2 ⁄ 5 1 ( 2s + 1 ) .52) With r 1 = 2 ⁄ 5 . where we found that the denominator can be expressed in factored form of a linear and a quadratic factor.+ ------------------------2 2 s + 1 s + 4s + 8 ( s + 1 ) ( s + 4s + 8 ) (12.k) function.50) s = –1 To compute r 2 and r 3 . we obtain 0 = r1 + r2 (12. which is zero. r2 s + r3 r1 s+3 F 7 ( s ) = ----------------------------------------------.51) Since r 1 is already known. we only need two equations in r 2 and r 3 .48) and in partial fraction expansion form.F 7 ( s ) = --------------. we use the equating the numerators procedure and we obtain ( s + 3 ) = r 1 ( s + 4s + 8 ) + ( r 2 s + r 3 ) ( s + 1 ) 2 (12. Numerical Analysis Using MATLAB® and Excel®. We will conclude the partial fraction expansion topic with a few more examples. (12.49) As in Example 12. with the coefficients of s 2 on the right side of (12. we first find the residue of the linear factor as s+3 r 1 = ------------------------2 + 4s + 8 s 2 = -5 (12.– -.8 Use the equating the numerators procedure to obtain the partial fraction expansion of F 8 ( s ) in (12.3. and with r 1 = 2 ⁄ 5 . s+3 F 7 ( s ) = ----------------------------------------------2 ( s + 1 ) ( s + 4s + 8 ) (12.= ---------. that is.47) below. using the residue(r.p.3. The remaining steps are the same as in Example 12. that is.47) Solution: This is the same rational function as that of Example 12. we equate the constant terms of (12. s+3 F 8 ( s ) = -----------------------------------------2 3 s + 5s + 12s + 8 (12. by substitution into (12. we obtain r 3 = – 1 ⁄ 5 . Then. Equating the coefficient of s 2 on the left side.51). Third Edition Copyright © Orchard Publications 12−15 .52) yields r 2 = – 2 ⁄ 5 . To find the third residue r 3 . 3 = 8r 1 + r 3 .-----------------------------( s + 2 ) 5 ( s 2 + 4s + 8 ) as before.Alternate Method of Partial Fraction Expansion Example 12.49).

Chapter 12 Partial Fraction Expansion Example 12. F 9 ( s ) in partial fraction expansion form is written as r2 r1 14 –6 F 9 ( s ) = ------------. not necessary.k) function to compute the poles and residues of the function 8s + 2 F 9 ( s ) = ------------------------2 s + 3s + 2 (12. and p 3 be the poles (the denominator roots) and r 1 .and r 3 be the residues of F 10 ( s ) . r 2 .p. F 9 ( s ) can be written as r2 r1 F 9 ( s ) = ------------.+ ---------s + p1 s + p2 s+2 s+1 (12.den) r = 14 -6 p = -2 -1 k = [] Therefore.10 Use the residue(r.56) Solution: Let p 1 .9 Use the residue(r. Then.= ---------. Then. p 2 .p.53) Solution: Let p 1 and p 2 be the poles (the denominator roots) and r 1 and r 2 be the residues.55) Example 12. but recommended den=[1 3 2].k) function to compute the poles and residues of F 10 ( s ) in (12.56) below. s+3 F 10 ( s ) = ----------------------------------------------2 ( s + 1 ) ( s + 4s + 8 ) (12. % The semicolon suppress the display of the row vector typed % and zero is typed to make the numerator have same number % of elements as the denominator. Third Edition Copyright © Orchard Publications .p.54) The MATLAB script for this example is as follows: num=[0 8 2].+ ------------. [r.+ ------------s + p1 s + p2 (12.k]=residue(num. it can be written as 12−16 Numerical Analysis Using MATLAB® and Excel®.

Third Edition Copyright © Orchard Publications 12−17 .0000i 2.– 0.0000i Therefore. Example 12.5x – 1 3 2 (12.56).15j 0.1500i 0. [r.= – 0. den).den) c = 1 r = -0. c. b=[1 4 8].b) to multiply the two factors of the denominator of (12. x + 2x + 1 f 1 ( x ) = ----------------------------0. We also recall that commas will display the results.2 – 0. Then. whereas semicolons will suppress the display.b).p.Alternate Method of Partial Fraction Expansion r1 r2 r3 F 10 ( s ) = ------------.2000+ 0. den=c.den) function to express the following rational polynomial as a polynomial with four terms.1500i 2.+ ------------. num=[1.57) The poles and the residues can be found with the statement [r.2 + 0. c=conv(a.p.11 Use the deconv(num.4F 10 ( s ) = ------------.59) Numerical Analysis Using MATLAB® and Excel®.4000 p = -2.+ ---------s+1 s + 2 + 2j s + 2 – 2j s + p1 s + p2 s + p3 (12.0000+ -2.k]=residue(num.den) function.+ ------------. F 10 ( s ) in partial fraction expansion form is r2 r3 r1 ----------------------------. where the last term is a rational polynomial whose order of the numerator is less than that of the denominator as illustrated by the following example.0000 k = [] 5 12 8 0.0000-1. We recall that we can write two or more statements on one line if we separate them by commas or semicolons.15j + -----------------------------. We will use the function conv(a.3]. we need to express the denominator as a polynomial.+ ------------.2000-0. we can reduce a rational polynomial to simple terms of a polynomial.58) By repeated use of the deconv(num. Before we use this statement.+ ------------s + p1 s + p2 s + p3 (12.k]=residue(num. a=[1 1].

Page 1−27.r]=deconv(num.5x + 6. and x0 is a required initial value. [q. Third Edition Copyright © Orchard Publications .3x + 4.5 −1]. f 1 ( x ) can now be written as (12.x0).35 1 f 2 ( x ) = ------------------------------------------------------------. This is discussed in Chapter 1.den) q = 2 r = 0 0 0 17 2 17 f 1 ( x ) = 2x + 8x + 16 + ------------------0. We can approximate this value by first plotting f 2 ( x ) to find out where it crosses the x −axis.60) It is important to remember that the function roots(p) is used with polynomials only. where function is a pre−defined string.75 ( 12x + 2x + 13x + 25 ) ( 23x + 16x + 7.11x + 2. den=[0 0 0.61) we must use the function fzero(‘function’.+ ----------------------------6 4 2 6 3 4.5x ) 3 2 5 2 (12.+ --------------------------------------------------.5x – 1 8 16 Therefore. such as the function f 2 ( x ) defined as 3x + 7x + 9 0. 12−18 Numerical Analysis Using MATLAB® and Excel®. If we want to find the zeros of any function.Chapter 12 Partial Fraction Expansion Solution: num=[1 2 0 1].

n are real numbers. • The zeros and poles can be real and distinct. we rewrite this function as 1---. 1. If m ≥ n . p 3. …. • The roots of the numerator are called the zeros of F ( s ) . 2. p n of F ( s ) are distinct we can factor the denominator of F ( s ) in the form Numerical Analysis Using MATLAB® and Excel®.= ------------------------------------------------------------------------------------------------------------------n n–1 n–2 D(s) + an – 2 s + … + a1 s + a0 an s + an – 1 s m m–1 m–2 is a proper rational function where a n is a non−zero integer other than unity. • Partial fraction expansion applies only to proper rational functions. and are found by letting N ( s ) = 0 . …. • If the function bm s + bm – 1 s + bm – 2 s + … + b1 s + b0 N(s) F ( s ) = ----------. • If all the poles p 1.= -----------------------------------------------------------------------------------------------------------------------------a1 D(s) a0 n an – 1 n – 1 an – 2 n – 2 s + ---------. If F ( s ) is an improper rational function we divide the numeraror N ( s ) by the denominator D ( s ) to obtain an expression of the form F ( s ) = k0 + k1 s + k2 s + … + km – n s 2 m–n + N(s) ----------D(s) so that m < n .3 Summary • The function + bm – 2 s + … + b1 s + b0 bm s + bm – 1 s N(s) F ( s ) = ----------. F ( s ) is an improper rational function. Third Edition Copyright © Orchard Publications 12−19 . and the roots of the denominator are called the poles of F ( s ) and are found by letting D(s) = 0 . is a proper rational function if the highest power of the numerator N ( s ) is less than the highest power of of the denominator D ( s ) . In most engineering applications we are interested in the nature of the poles..= ------------------------------------------------------------------------------------------------------------------n n–1 n–2 D(s) + an – 2 s + … + a1 s + a0 an s + an – 1 s m m–1 m–2 where the coefficients a k and b k for k = 0.Summary 12.( b s m + b m – 1 s m – 1 + b m – 2 s m – 2 + … + b 1 s + b 0 ) an m N(s) F ( s ) = ----------.s + … + ---. i.e. or combinations of real and complex conjugates.s + ---------. m < n . or repeated. or complex conjugates. p 2.s + ---an an an an to make a n unity.

say p 1 .k) function to verify our answers. the partial fraction expansion can be expressed as r 12 r 13 r 1m r 11 F ( s ) = --------------------. then its complex conjugate p k∗ is also a pole. has a multiplicity m .+ ---------------------------. the function is expressed as N(s) F ( s ) = ------------------------------------------------------------------------------------------m ( s – p 1 ) ( s – p 2 )… ( s – p n – 1 ) ( s – p n ) and denoting the m residues corresponding to multiple pole p 1 as r 11. For proper rational functions there is no direct term. The first residue of a repeated pole is found from r 11 = lim ( s – p 1 ) F ( s ) s → p1 m The second repeated pole is found from 12−20 Numerical Analysis Using MATLAB® and Excel®. ….p. • The partial fraction expansion can also be used if the poles are complex. Third Edition Copyright © Orchard Publications . say p 1 . the partial fraction expansion method allows us to write the above expression as r2 r3 rn r1 F ( s ) = ----------------.+ … + ----------------( s – p1 ) ( s – p 2 ) ( s – p3 ) ( s – pn ) where r 1. r 2. and a direct term.Chapter 12 Partial Fraction Expansion N(s) F ( s ) = ------------------------------------------------------------------------------------------------( s – p1 ) ⋅ ( s – p 2 ) ⋅ ( s – p 3 ) ⋅ … ⋅ ( s – p n ) where p k is distinct from all other poles. r 3.+ ----------------. Since complex poles occur in conjugate pairs. we let s → p k . that is. if p k is a complex pole. has a multiplicity m .+ ----------------( s – p2 ) ( s – p3 ) ( s – pn ) • If a rational function F ( s ) has simple poles but one of the poles.+ ---------------------------.+ ----------------. r n are the residues of F ( s ) . … r 1m . then. r k = lim ( s – p k )F ( s ) = ( s – p k )F ( s ) s → pk s = pk • We can use the MATLAB residue(r.+ ----------------.5) by ( s – p k ) . • If a rational function F ( s ) has simple poles but one of the poles. This function returns the residues. their associated poles.+ … + ----------------m m–1 m–2 ( s – p1 ) ( s – p1 ) ( s – p1 ) ( s – p1 ) r3 rn r2 + ----------------. for the simple poles we use the same procedure as for distinct poles. To evaluate the residue r k . we multiply both sides of (12. Then. r 12.

[ ( s – p 1 ) F ( s ) ] s → p 1 ds 2 2 and this process is continued until all residues of the repeated poles have been found. We assume that the denominator D ( s ) can be expressed as a product of real linear and quadratic factors.[ ( s – p 1 ) F ( s ) ] s → p 1 ds the third from m d r 13 = lim ------. Third Edition Copyright © Orchard Publications 12−21 . and then equating the numerators. • With the alternate method of partial fraction expansion we use the equating the numerators procedure thereby making the denominators of both sides the same.Summary m dr 12 = lim ---. Numerical Analysis Using MATLAB® and Excel®.

------------------------2 s + 4s – 5 s 3. 11. ----------------------------2 s(s + s + 1) (s + 1)(s + 1 ) 12−22 Numerical Analysis Using MATLAB® and Excel®. ---------------------2 s –2 s – 3 2 s 5. ------------------------2 s + 2s + 1 s(s + 1) 1 6.Chapter 12 Partial Fraction Expansion 12.4 Exercises Perform partial fraction expansion for the following. ---------------------2 s –2 s – 3 5s – 3 4. ---------2 1 –s 1 2. --------------------2 1 7. Third Edition Copyright © Orchard Publications . Use MATLAB to simplify and to verify your results. ----------------------------------2 1 8.

−5]. 4. k] = residue(Ns. Ns = [0.+ ---------2 2 (s + 1)(s – 1) s+1 s–1 s –1 1 –s –1 r 1 = ---------s+1 = –1 ⁄ 2 s=1 –1 r 2 = ---------s–1 = 1⁄2 s = –1 Then. r1 r2 –1 –1 1---------. −1]. [r. p.= -------------------------------. –1 1⁄2 1⁄2 -----------.= – ---------. 0. −1].+ ---------2 s–1 s+5 (s – 1)(s + 5) s + 4s – 5 1r 1 = ---------s+5 = 1⁄6 s=1 1r 2 = ---------s–1 = –1 ⁄ 6 s = –5 Then.= ---------.= ---------. 0. Ds = [1. [r.5000 p = -1 1 k = [] 2. 1 ⁄ 6 1 ⁄ 61 ------------------------.= -------------------------------. p.Solutions to End−of−Chapter Exercises 12. k] = residue(Ns.5 Solutions to End−of−Chapter Exercises 1.– ---------2 s–1 s+5 s + 4s – 5 format rat.+ ---------2 s+1 s–1 s –1 Ns = [0.= -----------.= ---------. r2 r1 1 1 ------------------------. Ds) r = -1/6 1/6 p = -5 1 k = [] Numerical Analysis Using MATLAB® and Excel®.5000 -0. 1]. Third Edition Copyright © Orchard Publications 12−23 . Ds) r = 0. 0. Ds = [1.

= ---------. −2.= -------------------------------. Ds) r = 3 2 p = 3 -1 k = [] 12−24 Numerical Analysis Using MATLAB® and Excel®. s 1⁄4 3⁄4 ---------------------. −3]. [r. Ds = [1.+ ---------2 s+1 s–3 s –2 s – 3 Ns = [0. 0]. −3]. p.+ ---------2 s+1 s–3 s –2 s – 3 format rat. Ds) r = 3/4 1/4 p = 3 -1 k = [] 4. r2 r1 5s – 3 5s – 3 ---------------------. −3]. Ns = [0. 1.+ ---------2 ( s + 1 )( s – 3) s+1 s–3 s –2 s – 3 s r 1 = ---------s–3 = 1⁄4 s = –1 s r 2 = ---------s+1 = 3⁄4 s=3 Then.= ---------.+ ---------2 s+1 s–3 ( s + 1 )( s – 3) s –2 s – 3 5s – 3 r 1 = ------------s–3 = 2 s = –1 5s – 3 r 2 = ------------s+1 = 3 s=3 Then. k] = residue(Ns.= ---------. r1 r2 s s ---------------------.= -------------------------------.= ---------. 5. k] = residue(Ns. [r. Ds = [1.Chapter 12 Partial Fraction Expansion 3. 325s – 3 ---------------------. p. −2. Third Edition Copyright © Orchard Publications .

r 21 r1 r 22 1 -------------------. Third Edition Copyright © Orchard Publications 12−25 .+ --------------2 2 2 2 (s + 1) s + 2s + 1 (s + 1) s + 2s + 1 (s + 1) -2 -1 r1 r2 –2 s – 1 -----------------. [r. Ds) 2 r = -2 1 p = -1 -1 k = 1 6. 2. [q. This is an improper rational function. we must divide the numeraror N ( s ) by the denominator D ( s ) to obtain an expression of the form F ( s ) = k0 + k1 s + k2 s + … + km – n s 2 m–n + N(s) ----------D(s) We could perform long division but we will use the MATLAB deconv(num.+ --------------2 s ( s + 1 )2 ( s + 1 ) s(s + 1) Numerical Analysis Using MATLAB® and Excel®.= 1 – -----------------. k] = residue(Ns. den=[1 2 1]. s –2 –2 s – 1 1 ------------------------.= -----------------. 0].= 1 + -----------------.= 1 + ------------------------.+ --------------2 2 2 (s + 1) s + 2s + 1 s + 2s + 1 (s + 1) Ns = [1.den) function to express the following rational polynomial as a polynomial with four terms.= --. p.r]=deconv(num.= 1 – -----------------. and before we apply the partial fraction expansion. num=[1 0 0 ]. Ds = [1.+ --------------2 2 (s + 1) (s + 1) (s + 1) r2 = –2 –2 s – 1 = r1 + r2 ( s + 1 ) r1 = 1 r1 + r2 = –1 Then.Solutions to End−of−Chapter Exercises 5.+ -----------------.= 1 + ------------------------.den) q = 1 r = 0 and thus 2 r1 r2 s –2 s – 1 2s + 1 ------------------------. 0. 1].

0]. eq2.= ----------------------------------.⎛ -.2 2 2 2 s + 1 s2 + 1 (s + 1)(s + 1) (s + 1 )(s + 1) (s + 1)(s + 1 ) 2 Equating numerators and like terms we obtain 1 = r1 s + r1 + r2 s + r2 s + r3 s + r3 r1 + r2 = 0 syms r1 r2 r3 eq1=r1+r2−0 eq2=r2+r3−0 eq3=r1+r3−1 S=solve(eq1. 1. [r. 1].+ -------------------------------------. Ds) r = -1 -1 1 p = -1 -1 0 k = [] 7.+ --------------2 s ( s + 1 )2 ( s + 1 ) s(s + 1) syms s. Ds = [1. k] = residue(Ns. Third Edition Copyright © Orchard Publications .⎞ ds ⎝ s ⎠ s = –1 1= – --2 s = –1 s = –1 Then. r1 r1 ( s + 1 ) r s + r3 ( r2 s + r3 ) ( s + 1 ) 1 ----------------------------------.+ -----------------.1 r 22 = ---.Chapter 12 Partial Fraction Expansion 1r 1 = ---------s+1 = 1 s=0 -r 21 = 1 s = –1 s = –1 d. 1 1 –1 –1 -------------------. 0.+ ----------------. p. expand(s*(s+1)^2) ans = s^3+2*s^2+s Ns = [0. eq3) r2 + r3 = 0 r1 + r3 = 1 2 2 eq1 = r1+r2 eq2 = 12−26 Numerical Analysis Using MATLAB® and Excel®. 2.= ---------.= -. 0.

and r 3 = 1 ⁄ 2 .1/4i -1/4 + 1/4i p = -1 -1/6004799503160662 + 1i -1/6004799503160662 . 1]. p. 1]. 1. eq3.1i k = [] Numerical Analysis Using MATLAB® and Excel®.r2 ans = -1/2 S.Solutions to End−of−Chapter Exercises r2+r3 eq3 = r1+r3-1 S = r1: [1x1 sym] r2: [1x1 sym] r3: [1x1 sym] S. 1 1 ⁄ 2 ( – 1 ⁄ 2 )s + 1 ⁄ 2 ----------------------------------. 1. Then. [r. Thus.eqN) returns the solutions in the structure S whose named fields hold hold the solution for each variable. k] = residue(Ns.r3 ans = 1/2 The statement S=solve(eq1. .. Ds) r = 1/2 -1/4 . r 2 = – 1 ⁄ 2 . expand((s+1)*(s^2+1)) ans = s^3+s+s^2+1 Ns = [0.. 0. eq2. r 1 = 1 ⁄ 2 . Ds = [1.+ -----------------------------------2 2 s+1 (s + 1 )(s + 1 ) s +1 syms s. 0. Third Edition Copyright © Orchard Publications 12−27 .= ---------.r1 ans = 1/2 S.

p. expand(s*(s^2+s+1)) ans = s^3+s^2+s Ns = [0.1170/1351i 0 k = [] As in Exercise 7. 1]. ( r 2 s + r 3 )s r2 s + r3 r1 r1 ( s + s + 1 ) 1 ----------------------------. and r 3 = 1 . r 2 = – 1 .= 1 + ---------------------2 s s2 + s + 1 (s + 1 )(s + 1 ) syms s. 0. the partial fraction expansion of a ratio of polynomials represents an ill-posed problem. 0]. 8. Then. 0. Third Edition Copyright © Orchard Publications . –s+3 1 -----------------------------------. is near a polynomial with multiple roots. The MATLAB help residue command displays the following: Warning: Numerically. Ds) r = -1/2 -1/2 1 p = -1/2 + 1170/1351i -1/2 .+ ----------------------------2 2 2 2 s s +s+1 s(s + s + 1) s(s + s + 1) s(s + s + 1) 2 Equating numerators and like terms we obtain 1 = r1 s + r1 s + r1 + r2 s + r3 s r1 + r2 = 0 r2 + r3 = 0 r1 = 1 2 2 By inspection. Problem formulations making use of state-space or zero-pole representations are preferable. 1.= ------------------------------. these values are inconsistent with those we’ve found.+ ---------------------. A(s). If the denominator polynomial. [r. k] = residue(Ns. Ds = [1.Chapter 12 Partial Fraction Expansion These values are inconsistent with those we’ve found. can make arbitrarily large changes in the resulting poles and residues. + 390/1351i 390/1351i 12−28 Numerical Analysis Using MATLAB® and Excel®. including roundoff errors. r 1 = 1 .= --. 1. then small changes in the data.

1) by performing integration by parts using the relation ∫ u dv Letting u = e –x = uv – v du and dv = x n–1 ∫ (13. 13.Chapter 13 The Gamma and Beta Functions and Distributions T his chapter is an introduction to the gamma and beta functions and their distributions used with many applications in science and engineering.1 The Gamma Function The gamma function.1) and this improper* integral converges (approaches a limit) for all n > 0 . a a b b Numerical Analysis Using MATLAB® and Excel®.5) we obtain –x xdu = – e dx and v = ---n n Then. It is defined as Γ(n) = ∫0 x ∞ n – 1 –x e dx (13. with (13. We will derive the basic properties of the gamma function and its relation to the well known factorial function n! = n ( n – 1 ) ( n – 2 )…3 ⋅ 2 ⋅ 1 (13.1) as * Improper integrals are two types and these are: a. ∫ f ( x ) dx where the limits of integration a or b or both are infinite b.3) (13.3). Third Edition Copyright © Orchard Publications 13−1 . we write (13. They are also used in probability. and in the computation of certain integrals.2) We will evaluate the integral of (13. ∫ f ( x ) dx where f ( x ) becomes infinite at a value x between the lower and upper limits of integration inclusive. is also known as generalized factorial function.4) (13. denoted as Γ ( n ) .

we observe that ) -------------------Γ(n) = Γ(n + 1n (13.6) reduces to 1 Γ ( n ) = -n ∫0 x e ∞ n –x dx ∞ (13. dx dx x→a ddf(x) lim ---------.= lim ----------------------------------. then. and if the limit ----. and we wish to find this limit..= -. for x = 0 . if it exists.10) or nΓ ( n ) = Γ ( n + 1 ) (13. d n –x n x→∞ m x e dx dx x lim -----------. To work around this problem.g ( x ) as x approaches a exists. where m ≥ n .9).f ( x ) ⁄ ----. results in the indeterminate form g( x) f(a) 0 f(x ) ---------. say a . we consider the limit lim ---------.7) Therefore. L’Hôpig( a) 0 x → a g(x) ddtal’s rule states that if f ( a ) = g ( a ) = 0 . the ratio of two functions. such as ---------.g ( x )⎞ ⎠ dx g(x) x → a ⎝ dx 13−2 Numerical Analysis Using MATLAB® and Excel®. This can be proved with L’ Hôpital’s rule* by differentiating both numerator and denominator m times..Then.= 0 ------------------------------------------------------------------m–n x x→∞ x e n–m x m n d m–1 m–1 nx n–1 (13.f ( x ) ⁄ ----.1) we have Γ(n) = ∫0 ∞ x n – 1 –x 1 e dx = -n ∫0 x e n –x dx (13. for some value of x ..8) and with (13.11) f(x) * Quite often.= lim ------.6) vanishes at the lower limit.= lim -----------------. It also vanishes at the upper limit as x → ∞ .9) By comparing the two integrals of (13. that is.6) With the condition that n > 0 .Chapter 13 The Gamma and Beta Functions and Distributions x e Γ ( n ) = -----------n n –x ∞ 1 + -n x=0 ∫0 x e ∞ n –x dx (13. (13. the first term on the right side of (13.= lim ⎛ ----.= … x m–1 n x → ∞ ne x x → ∞ dm x→∞ d x ne ne m m–1 dx dx n ( n – 1 ) ( n – 2 )… ( n – m + 1 )x = lim -----------------------------------------------------------------------------------x x→∞ ne ) = lim ( n – 1 ) ( n – 2 )… ( n – m + 1 . Third Edition Copyright © Orchard Publications .

g). axis([−4 4 −6 6]).1) yields Γ(1) = ∞ –x –x ∞ 0 ∫0 e dx = – e = 1 (13.11) for n > 0 .12) Thus. the Γ ( n ) function is defined for all positive integers and positive fractional values. we see that Γ ( n ) becomes infinite as n → 0 .1 shows the plot of the function Γ ( n ) versus n .13) From the recurring relation of (13. we have derived the important relation.5 . For instance. and so on.11). – 1.15) The formula of (13. From (13. For n = 1 . xlabel('n'). plot(n.14) and in general Γ ( 4 ) = 3 ⋅ Γ ( 3 ) = 3 ⋅ 2 = 3! Γ ( n + 1 ) = n! for n = 1. and for all negative fractional. 3.10) for n < 0 . but not negative integer values. it establishes the relationship between the Γ ( n ) function and the factorial n! . g=gamma(n). – 3 . when n = – 0. we can find Γ ( – 0. Stated in other words. grid. Γ(1) = 1 (13. that is. – 2. Third Edition Copyright © Orchard Publications 13−3 . 2. whereas the factorial n! is defined only for zero (recall that 0! = 1 ) and positive integer values. the gamma function exists (is continuous) everywhere except at 0 and negative integer numbers.10). we obtain values which are not consistent with the definition of the Γ ( n ) function.The Gamma Function It is convenient to use (13. we obtain Γ(2) = 1 ⋅ Γ(1) = 1 Γ ( 3 ) = 2 ⋅ Γ ( 2 ) = 2 ⋅ 1 = 2! (13. … (13. This is done with the script below which produces the plot shown in Figure 13.05: 4. – 2.5 ) . as defined in that relation. (13. title('The Gamma Function').5 ) in terms of Γ ( 0. and (13. but if we substitute the numbers 0. ylabel('Gamma(n)') Figure 13. Numerical Analysis Using MATLAB® and Excel®.11).1. – 1. – 3 and so on in (13. n=−4: 0. We can use MATLAB’s gamma(n) function to plot Γ ( n ) versus n .15) is a very useful relation. We must remember that.

11) to compute values outside this range.8953 ) = 3.5 + 1 ) Γ ( 0.6 ) ( 0.6 ) ( 1.Chapter 13 The Gamma and Beta Functions and Distributions 6 The Gamma Function 4 2 Gamma(n) 0 -2 -4 -6 -4 -3 -2 -1 0 n 1 2 3 4 Figure 13.6 ) b.1.6Γ ( 2.5 ) Γ ( n + 1 ) = nΓ ( n ) Γ ( 3. Γ ( 0. Γ ( 3.5 0.6 ) ( 1. Plot of the gamma function Numerical values of Γ ( n ) for 1 ≤ n ≤ 2 .10) Γ(n + 1) Γ ( n ) = -------------------n a. Third Edition Copyright © Orchard Publications .6 ) = ( 2.5 13−4 Numerical Analysis Using MATLAB® and Excel®. From (13.6 ) Γ ( 1. we can use MATLAB to find any valid values of n . Γ ( 1. b.5 ) c.6 ) = ( 2.5 ) = -----------------------.11) Then.10) or (13.8953 Γ ( 3. Γ ( – 0.6 ) = 2. can be found in math tables.6 ) = 0. and from math tables Therefore. Example 13.717 Then.1 Compute: Solution: a.5 ) Γ ( 0.= --------------0. but we can use (13.6 )Γ ( 1. From (13. Of course.

5724 #NUM! exp(gammaln(x))= gamma(x) 3.5 -0. ) ) ------------------------------------------Γ ( – 0.2.5 ) – 0.7170 1.6 0.= – 2Γ ( 0.5 – 0.= Γ ( 0. x 3.The Gamma Function and from math tables Therefore.772 Then.5 ) = Γ ( – 0.544 We can verify these answers with MATLAB as follows: a=gamma(3.8862 Γ ( 0. It does. Third Edition Copyright © Orchard Publications 13−5 . we can use the EXP(GAMMALN(n)) function to evaluate Γ ( n ) at some positive value of n .5449 Excel does not have a function which evaluates Γ ( n ) directly.8862 ) = 1. Γ ( – 0. have the GAMMALN(x) function.2.5) a = 3. Using Excel to find Γ ( n ) Numerical Analysis Using MATLAB® and Excel®.5 ) = 0. Therefore.7725 #NUM! Figure 13.5 ) = ( 2 ) ( 0. however.5 + 1 .7170 b = 1.10) Γ(n + 1) Γ ( n ) = -------------------n Γ ( 1.5 ) = ( – 2 ) ( 1. c.7725 c = -3. From (13. But because it first computes the natural log.5 and using the result of (b). c=gamma(−0.3129 0.6). it does not produce an answer if n is negative as shown in Figure 13.5 .772 ) = – 3. b=gamma(0.5).5 ) = – 2 Γ ( 0.5 gammaln(x) 1.

24) Then.⎞ = ⎝2⎠ ∫0 ∞ x 0. Proof: From (13.19) into (13.1).18). Γ ( n + 1 ) = nΓ ( n ) Γ ( n ) = ( n – 1 )Γ ( n – 1 ) (13. the relation Γ ( n ) = ( n – 1 )! (13. Third Edition Copyright © Orchard Publications .18) Next. we obtain Γ ( n ) = ( n – 1 ) ( n – 2 ) ( n – 3 )…1Γ ( 1 ) (13. 1 Γ ⎛ -.23) Example 13.25) 13−6 Numerical Analysis Using MATLAB® and Excel®.5 – 1 – x e dx = ∫0 x – 0. we obtain Γ ( n – 1 ) = ( n – 2 )Γ ( n – 2 ) (13.21) and since Γ ( 1 ) = 1 .11). replacing n with n – 1 on the left side of (13.5 – x e dx (13.17) (13.3 Use the definition of the Γ ( n ) function to compute the exact value of Γ ( 1 ⁄ 2 ) Solution: From (13.19) Substitution of (13.22) (13. we have or Γ ( n ) = ( n – 1 ) ( n – 2 ) ( n – 3 )…1 Γ ( n ) = ( n – 1 )! (13. Γ(n) = ∫0 x ∞ n – 1 –x e dx ∞ (13.18) yields Γ ( n ) = ( n – 1 ) ( n – 2 )Γ ( n – 2 ) (13.16) is true.20) By n repeated substitutions.Chapter 13 The Gamma and Beta Functions and Distributions Example 13.2 Prove that when n is a positive integer. Then.

the total area of a region is found by either one of the double integrals A = ∫ ∫ dx dy = ∫ ∫ r dr dθ (13.⎞ = 2 ⎝2⎠ ∫0 ∫0 2 ∞ e –x 2 dx (13.25). we obtain 1 Γ ⎛ -.30) and by recalling that: 1.28) yields 1 Γ ⎛ -.e 2 (13.28) ∞ e –y 2 dy Multiplication of (13. we let 1 Γ ⎛ -.⎞ ⎝2⎠ 2 = 4 ∫0 ∞ e –x 2 dx ∫0 ∞ e –y dy = 4 ∫0 ∫0 e ∞ ∞ –( x + y ) 2 2 dx dy (13.e u = e u ----.u 2 = 2ue u du du (13. ∫ρ ρ2 1 ρe –ρ 2 1 –ρ 2 dρ = – -.29) to polar coordinates by making the substitution ρ 2 = x +y 2 2 (13.The Gamma Function Letting x = y2 we obtain dx ----.33) We observe that as x → ∞ and y → ∞ .29) Now.26) Next.= 2y dy or dx = 2ydy By substitution of the last three relations into (13.32) Then. we convert (13. Third Edition Copyright © Orchard Publications 13−7 . we define Γ ( 1 ⁄ 2 ) as a function of both x and y .⎞ = 2 ⎝2⎠ 1 Γ ⎛ -. from differential calculus 2 2 d d 2 ----. that is. Numerical Analysis Using MATLAB® and Excel®.⎞ = ⎝2⎠ ∫0 ∞ y 2 ( – 0.5 ) – y e 2 2ydy = 2 ∫0 ∞ y ye –1 –y 2 dy = 2 ∫0 e ∞ –y 2 dy (13.31) 2.27) by (13.27) (13.

5 – 1. Γ ( – 2.34) Substitution of (13.= – ----. for n = – 2. Γ ( – 1.= --------. Third Edition Copyright © Orchard Publications . 4 -.5 ) c.⎞ = ⎝2⎠ π (13.5 ) = ---------------.π – 2.5 + 1 ) Γ ( – 1.37) for any n ≠ negative integer 13−8 Numerical Analysis Using MATLAB® and Excel®.= ---------. (13.= -. Γ ( 0.and Γ ( 0. 4 Γ ( – 1.5 .π 3 8 Γ ( – 2.35) Example 13.π 3 – 1.30).5 15 – 2. Γ ( – 0.Chapter 13 The Gamma and Beta Functions and Distributions ρ → ∞ and θ → π ⁄ 2 (13.5 .⎞ ⎝2⎠ 2 = –2 ∫0 π⁄2 ⎛ e–ρ ⎝ 2 ⎞ dθ = – 2 ρ = 0⎠ ∞ ∫0 π⁄2 ( 0 – 1 ) dθ = 2 ∫0 π⁄2 dθ = 2 θ π⁄2 0 = π and thus.= – 2 π – 0.5 ) π Γ ( – 0.5 ) = n π b.5 .5 + 1 ) Γ ( – 0.= ------------------.5 ) b .36) -Γ ( n )Γ ⎛ n + 1 ⎞ = ⎝ 2 ⎠ πΓ ( 2n ) (13.5 ) Γ (n + 1) Γ ( n ) = --------------------.5 Other interesting relations involving the Γ ( n ) function are: π Γ ( n )Γ ( 1 – n ) = ------------sin nπ for 0 < n < 1 2 2n – 1 (13.5 – 2. for n = – 1.34) into (13.= ------------------.5 – 0.33) and (13.5 ) = -----------------------------. for n = – 0.5 c.5 ) Γ ( – 2.5 a.4 Compute: Solution: Using the relations we obtain: a. we have obtained the exact value 1 Γ ⎛ -.29) yields 1 Γ ⎛ -.5 – 1.= ------------.5 ) –2 π Γ ( – 1.5 ) = -----------------------------.

⎞ = ---------⎝ 3⎠ ⎝ ⎠ 3 sin π -3 or Numerical Analysis Using MATLAB® and Excel®.⎞ ⎝2⎠ 2 = π Therefore.⎞ = ⎝2⎠ π Proof: 1 1 1 π-Γ ⎛ -.⎞ Γ ⎛ -.39) Example 13. If n is a positive integer.38) Relation (13. Third Edition Copyright © Orchard Publications 13−9 .The Gamma Function Γ ( n + 1 ) = n! = ⎫ n –n ⎧ 1 1139 571 2πnn e ⎨ 1 + -------.⎞ Γ ⎛ 1 – -.⎞ = ⎝2⎠ π Example 13. the factorial n! can be approximated as n! ≈ 2πnn e n –n (13. we obtain 1 1 π Γ ⎛ -.38) is referred to as Stirling’s asymptotic series for the Γ ( n ) function.⎞ = ---------⎝ 2 ⎠ ⎝ 2⎠ ⎠ ⎝2⎠ ⎝ π 2 sin -2 or 1 Γ ⎛ -. 1 Γ ⎛ -.⎞ Γ ⎛ -.– ------------------------.36).36) to prove that 1 Γ ⎛ -.– ------------------.6 Compute the product 1 2 Γ ⎛ -.+ ------------.5 Use (13.⎞ ⎝3⎠ ⎝3⎠ Solution: Using (13.+ … ⎬ 12n 288n 2 51840n 3 2488320n 4 ⎩ ⎭ (13.⎞ Γ ⎛ 1 – 1 ⎞ = Γ ⎛ -.

gamma(50+1) ans = 3.37) to find 3 Γ ⎛ -. we use the relation Γ ( n + 1 ) = n! and the MATLAB gamma(n) function.Chapter 13 The Gamma and Beta Functions and Distributions 1 2 2π 2 3π π Γ ⎛ -. that is.= ----------.0363e+064 This is an approximation.= -----.04141E+64 13−10 Numerical Analysis Using MATLAB® and Excel®.⎞ = ------------.⎞ Γ ( 2 ) = ⎝2⎠ 3 πΓ ⎛ 2 ⋅ -.= ------------⎝ 3⎠ ⎝ 3⎠ 3 3⁄2 3 Example 13. Third Edition Copyright © Orchard Publications .+ -.⎞ = . that is.= -----⎝2⎠ 4Γ ( 2 ) 4⋅1 2 Example 13.7 Use (13. Then.39) to compute 50! Solution: 50! ≈ 2 π × 50 × 50 50 ×e – 50 We use MATLAB as a calculator. To find the exact value.⎝ 2 ⎠ ⎝2 2 ⎠ 3 2 2 Γ ⎛ -.0414e+064 We can check this answer with the Excel FACT(n) function.⎞ = -----------------. we type and execute the expression sqrt(2*pi*50)*50^50*exp(−50) ans = 3.8 Use (13.⎞ Γ ⎛ -.⎞ ⎝ 2⎠ πΓ ( 3 ) 3 2! π πΓ(3) π Γ ⎛ -.⎞ ⎝2⎠ Solution: 2 3–1 3 3 1 Γ ⎛ -.⎞ Γ ⎛ -. =FACT(50) and Excel displays 3.

∫0 x e 5 – 2x dx = ∫0 ∞ 5 1 ⎛ y ⎞ e – y dy = --------6 ⎝2⎠ 2 2 ∫0 ∞ y e dy 5 –y Γ ( 6 ) 5! 120 15 = ----------. and then moves towards the positively charged side with a force inversely proportional to its distance from it. Solution: Let the center of attraction 0 be the point zero on the x −axis.3. dx = dy ⁄ 2 . It is initially at rest. Example 13. ∞ ∞ x e dx = Γ ( 5 ) = 4! = 24 4 –x Let 2x = y .9 Using the definition of the Γ ( n ) function. Assuming that the particle moves towards the center of the positively charged side.The Gamma Function The Γ ( n ) function is very useful in integrating some improper integrals.= ----64 64 64 8 Example 13. derive an expression for the time required the negatively charged particle to reach 0 in terms of the distance α and its mass m . Some examples follow.10 A negatively charged particle is α meters apart from the positively charged side of an electric field. Third Edition Copyright © Orchard Publications 13−11 . Numerical Analysis Using MATLAB® and Excel®.= ----. 4 –x ∫0 ∞ x e 5 – 2x dx ∫0 x Then. considered to be the center of attraction 0 . ∫0 ∞ x e dx b. evaluate the integrals a. ∞ n – 1 –x e dx = Γ ( n ) ∫0 b. as indicated in Figure 13. and by substitution.= -------. then. a. Solution: By definition.

Then. At t = 0 .42) Substitution of (13.( dx ) x (13. Let the velocity of the particle be v . 13−12 Numerical Analysis Using MATLAB® and Excel®. and it is evaluated from the initial condition that v = 0 when x = α .45) where C represents the constants of integration of both sides. dx ----.40) yields dv -mv ----.= v dt 2 dv dv dx dx dv .42) into (13.= – k dx x k mvdv = – -. and moves towards the origin at x = 0 .----.------.44) Integrating both sides of (13. Third Edition Copyright © Orchard Publications .40) where m = mass of particle x = distance (varies with time) k = positive constant of proportionality and the minus (−) sign indicates that the distance x decreases as time t increases.3.= v ----2 dx dx dt dt dt (13. dx k m ------.44). we obtain mv --------.Chapter 13 The Gamma and Beta Functions and Distributions movement of particle 0 Figure 13.43) or (13.10 α x By Newton’s law. Then.= ----.= ----. Sketch for Example 13.41) and (13. the particle is assumed to be located on the x −axis at point x = α .= – k ln x + C 2 2 (13.= – -2 x dt 2 (13.

= k ln α – k ln x = k ln -2 x 2 (13.The Gamma Function C = k ln α (13.= ± ----.48) Since x decreases as t increases. and dx = – α e dy α α lim ln ⎛ -.⎞ = 0 and lim ln ⎛ -. T = ∫ m dτ = – ----2k 0 t ∫α ------------------------ln ( α ⁄ x ) y 0 dx (13. noting that the integration on the right side is with respect to the distance x where at t = 0 .53) x→α the lower and upper limits of integration in (13.ln -m x dt 2 (13.49) Solving (13. dx = – 2k ln -----. then e ⎝x⎠ α α = -x –y (13. since x = α e . we express (13.52) or Also.45).50) We are interested in the time required for the particle to reach the origin 0 . are being replaced with 0 and ∞ respectively. that is.v = ----.----m x dt (13. it is found from the relation below. and at τ = t .-----------------------2k ln ( α ⁄ x ) (13. Third Edition Copyright © Orchard Publications 13−13 .α .⎞ = ∞ ⎝ x⎠ x→0 ⎝ x⎠ –y (13.51).⎞ .51) To simplify (13. We denote this time as T . Then.51). x = α . Therefore. we let y = ln ⎛ -. x = 0 .49) for dt we obtain dx mdt = – ----. mv α --------.46) and by substitution into (13.47) Solving for v and taking the square root of both sides we obtain 2k α dx . we choose the negative sign.51) as Numerical Analysis Using MATLAB® and Excel®.

= α π ----. using the definition of the Γ ( n ) function.57) yields Γ ( m )Γ ( n ) = ∫0 ∞ u m – 1 –u e du ∫0 v ∞ n – 1 –v e dv (13.58) it written as Γ ( m )Γ ( n ) = ∫0 ∞ x 2 (m – 1) 2xe –x 2 dx ∫0 e ∞ y 2 2 (n – 1) 2ye –y 2 dy = 4 ∫0 ∞ x 2m – 2 xe –x 2 dx ∫0 y ∞ 2n – 2 ye –y 2 dy = 4 ∫0 ∫ 0 ∞ ∞ x 2m – 1 2n – 1 – ( x + y ) y 2 (13. relation (13.55) From the definition of the Γ ( n ) function.56) by (13.59) dx dy Next.57) For m > 0 and n > 0 .54) Example 13. with these substitutions. we obtain du = 2xdx and dv = 2ydy . multiplication of (13.59) to polar coordinates by letting x = ρ cos θ and y = ρ sin θ Then. Γ(n) = ∫0 x ∞ ∞ n – 1 –x e dx (13. we convert (13.11 Evaluate the integrals ∫0 Solution: π⁄2 cos θ dθ and n ∫0 π⁄2 sin θ dθ n (13. Γ(m) = ∫0 x m – 1 –x e dx (13.= α ------⎝ 2 ⎠ 2k 2k 2k (13. Third Edition Copyright © Orchard Publications .56) Also. Then.⎞ ----. we obtain 1 m πm m T = α Γ ⎛ -. 13−14 Numerical Analysis Using MATLAB® and Excel®. letting u = x 2 and v = y 2 .= α ----2k y –y ∫0 y ∞ –1 ⁄ 2 –y e dy Finally.58) where u and v are dummy variables of integration.Chapter 13 The Gamma and Beta Functions and Distributions m T = – ----2k ∫0 ∞ – α e dy m -------------------. Next.

64) We observe that (13. and 1 2n – 1 with 0 .⎝2 ⎠ ⎝ 2 2⎠ (13. Then.-----. we replace 2m – 1 with 0 and 2n – 1 with m .63) and (13.60) is written as Γ ( m )Γ ( n ) = 2 = 2 ∫0 ∫0 π⁄2 cos cos 2m – 1 θ ⋅ sin θ ⋅ sin 2n – 1 θ dθ ∫0 w ∞ m + n – 1 –w e dw π⁄2 (13.⎞ ⎝ 2 ⎠ π ⎝2 ⎠ ⎝ 2 ⎠ m .⎞ ⎝ 2 ⎠ π ⎝ 2 ⎠ ⎝2⎠ n cos θ dθ = -----------------------------------------.sin θ dθ = ⎛ n + 1⎞ 2 Γ -⎝2 ⎠ ∫0 π⁄2 cos θ dθ = n ∫0 π⁄2 n > –1 (13.⎞ Γ ⎛ -.-.⎞ ⎝ 2 ⎠ π n ---------------------. we obtain the special case of (13.------------⎝ 2 ⎠ ⎝2 2 ⎠ (13. we let ρ2 = w .-----⎛ m +1⎞ 2 ⎛ 1+m+1⎞ Γ --2Γ -. we obtain the integral of the sin θ function as n ∫0 π⁄2 m+1 m+1 1 Γ ⎛ ------------.62). that is.⎞ Γ ⎛ ----------.= -------------------------.61) 2m – 1 2n – 1 θ dθ ⋅ Γ ( m + n ) Rearranging (13.62) ---------------and this expression can be simplified by replacing 2m – 1 with n .60) 2 ρ dρ e To simplify (13. that is.64) are equal since m and n can be interchanged.The Gamma Function Γ ( m )Γ ( n ) = 4 = 2 ∫0 ∫0 ∫0 π⁄2 π⁄2 ∞ ( ρ cos θ ) 2m – 1 2m – 1 ( ρ sin θ ) θ dθ 2n – 1 – ρ 2 e ρ dρ dθ 2 cos θ ⋅ sin 2n – 1 ∫0 ρ ∞ 2m + 2n – 2 – ρ (13.sin θ dθ = --------------------------------------------.= ------------------------.60). Third Edition Copyright © Orchard Publications 13−15 . dw = 2 ρ d ρ and thus relation (13. n = -.62) as 2 π⁄2 ∫0 n+1 n+1 1 Γ ⎛ ----------. m = ( n + 1 ) . Therefore.61) we obtain ∫0 π⁄2 cos 2m – 1 θ ⋅ sin 2n – 1 θ dθ = ------------------------- Γ ( m )Γ ( n ) 2Γ ( m + n ) 2 (13.⎞ Γ ⎛ -. n+1 Γ ⎛ ----------.65) Numerical Analysis Using MATLAB® and Excel®.⎞ Γ ⎛ ------------. in (13. then.63) If..-----⎛ n +1⎞ 2 ⎛ n+1+1⎞ Γ -2Γ ----------.

0 β 2.15 f(x) 0. When n is a positive integer. Science.0268 0.0608 0.2 2.0 β^n 8.beta.0 0.0379 Probability Density Function of the gamma distribution for n = 3 and β = 2 0. Figure 13. ISBN 0−9709511− 0−8. n. We can evaluate the gamma distribution with the Excel GAMMADIST function whose syntax is GAMMADIST(x. 13−16 Numerical Analysis Using MATLAB® and Excel®.1084 0.0082 0.8 2. and Technology.1007 0.6 1.0823 0. β > 0 n β Γ(n) (13.4 0.cumulative) where: x = value at which the distribution is to be evaluated alpha = the parameter n in (13. x 0.0023 0.10 0.2 0.0 Γ(n) 2.8 1.Chapter 13 The Gamma and Beta Functions and Distributions The relations of (13.65) are known as Wallis’s formulas.0167 0.4 n 3.alpha. β ) = ------------------------.66) beta = the parameter β in (13.0494 0.4 shows the probability density function (pdf) of the gamma distribution for n = 3 and β = 2 .20 0.0920 0.0 f(x) 0.00 0 2 4 6 x 8 10 12 Figure 13.0719 0.4 1. The pdf for the gamma distribution.4.66) * Several probability distributions are presented in Mathematics for Business. it is referred to as Erlang distribution.2 1.0000 0. 13.0 2.0 1.6 0.x > 0.05 0. it will suffice to say that it is used in reliability and queuing theory.2 The Gamma Distribution One of the most common probability distributions* is the gamma distribution which is defined as n – 1 –x ⁄ β e x f ( x.66) A detailed discussion of this probability distribution is beyond the scope of this book. Third Edition Copyright © Orchard Publications . n.

and β = 2 b. We observe that as x → 0 .FALSE) returns 0. if TRUE.13 Prove that B ( m. Example 13. and if FALSE.3.4. is defined as B ( m. that is. Therefore.0925 We observe that these values are consistent with the plot of Figure 13. y → 1 and as x → 1 . n ) = ∫0 x 1 m–1 (1 – x) n–1 dx (13. n ) . n = 3 .2.FALSE) returns 0.1353 =GAMMADIST(7. GAMMADIST returns the cumulative distribution function (cdf). Numerical Analysis Using MATLAB® and Excel®. the pdf of the gamma distribution if: a. n ) = B ( n. Example 13. a.68) Proof: Let x = 1 – y . y → 0 . and β = 2 Solution: Since we are interested in the probability density function (pdf) values.3 The Beta Function The beta function.2. dx = – dy .67) where m > 0 and n > 0 . denoted as B ( m. x = 4 .3. n = 3 . m ) (13. x = 7 . 13.12 Use Excel’s GAMMADIST function to evaluate f ( x ) . Then. then. b. * Several probability density functions are also presented on the text mentioned on the footnote of the previous page. we specify the FALSE condition. =GAMMADIST(4.The Beta Function cumulative = a TRUE / FALSE logical value. Third Edition Copyright © Orchard Publications 13−17 . it returns the probability density function* (pdf).

70) ∫0 π⁄2 2m – 1 θ ) ( cos 2m – 1 θ ) dθ Example 13. B ( m. θ → 0 and as x → 1 . n ) = = ∫0 ∫0 1 x m–1 (1 – x) y n–1 dx = – dy = ∫1 ( 1 – y ) n–1 0 m–1 [1 – (1 – y)] n–1 dy 1 (1 – y) m–1 n–1 ∫0 y 1 (1 – y) m–1 dy = B ( n.15 Prove that Γ ( m )Γ ( n ) B ( m.69) Proof: We let x = sin 2θ .62) and (13. n ) = -----------------------Γ(m + n) (13.70). n ) = 2 ∫0 π⁄2 cos 2m – 1 θ ⋅ sin 2n – 1 θ dθ (13.Chapter 13 The Gamma and Beta Functions and Distributions B ( m. Third Edition Copyright © Orchard Publications . Example 13. The B ( m. m ) and thus (13. n ) function is also useful in evaluating certain integrals as illustrated by the following examples. 13−18 Numerical Analysis Using MATLAB® and Excel®. Then.14 Prove that B ( m. θ → π ⁄ 2 .71) Proof: The proof is evident from (13. then.68) is proved. dx = 2 sin θ cos θ d θ . We observe that as x → 0 . n ) = ∫0 x ∫0 1 m–1 (1 – x) 2 n–1 dx 2 n–1 = 2 = 2 π⁄2 ( sin θ ) ( sin m–1 ( cos θ ) sin θ cos θ dθ (13.

n ) function directly. However.74) Numerical Analysis Using MATLAB® and Excel®. format rat.72) Solution: By definition B ( m. 4 ) = ----------------------.5.16 Evaluate the integral ∫0 x ( 1 – x ) dx 4 3 1 (13.5.73) We can also use MATLAB’s beta(m.00 Γ(m+n) exp(gammaln(m+n)) 40320. Example 13.= --------. ∫0 x ( 1 – x ) d x 4 3 1 = B ( 5. p g Γ(m) exp(gammaln(m)) 24.= -------Γ(9) 8! 40320 40320 280 (13. For this example.The Beta Function Example 13.4) z = 1/280 Excel does not have a function that computes the B ( m.17 Evaluate the integral ∫ x --------------.= -------------.n)= Γ(m) x Γ(n) / Γ(m+n) 1/280 m= 5 Figure 13. % display answer in rational format z=beta(5. we can use (13.= -------------. n ) = ∫0 x 1 m–1 (1 – x) n–1 dx and thus for this example. 4 ) Using (13.dx 0 2–x 2 2 (13. Third Edition Copyright © Orchard Publications 13−19 .71) we obtain Γ ( 5 )Γ ( 4 ) 4!3! 24 × 6 144 1 B ( 5.71) for its computation as shown in Figure 13.00 n= 4 Γ(n) exp(gammaln(n)) 6. Computation of the beta function with Excel.n) function.00 Beta(m.

74). Third Edition Copyright © Orchard Publications .dv = 4 2 1–v 2 ∫0 v ( 1 – v ) 2 1 –1 ⁄ 2 dv 1 Γ ( 3 )Γ ( 1 ⁄ 2 ) = 4 2 ⋅ B ⎛ 3. n > 0 (13. v → 1 . eating times and places. n ) m–1 n–1 (13.Chapter 13 The Gamma and Beta Functions and Distributions Solution: Let x = 2v . and dx = 2dv . m. m. (13.75) and (13. and as x → 2 . We observe that as x → 0 .75) Γ(1⁄2) = π Γ ( 7 ⁄ 2 ) = ( 7 ⁄ 2 – 1 )Γ ( 7 ⁄ 2 – 1 ) = ( 5 ⁄ 2 ) Γ ( 5 ⁄ 2 ) = ( 5 ⁄ 2 ) ( 5 ⁄ 2 – 1 )Γ ( 5 ⁄ 2 – 1 ) = 5 ⁄ 2 ⋅ 3 ⁄ 2 ⋅ ( 3 ⁄ 2 – 1 )Γ ( 3 ⁄ 2 – 1 ) = ( 15 ⁄ 8 )Γ ( 1 ⁄ 2 ) = 15 π ⁄ 8 (13. then x = 4v . v → 0 . etc. from (13.dx = 4 2 ⋅ 2! ⋅ π = 64 2 -----------------------------------------15 15 π ⁄ 8 0 2–x 2 2 (13. Using (13.71) we can express the beta distribution as Γ(m + n) .79) 13−20 Numerical Analysis Using MATLAB® and Excel®. Then.⋅ x Γ ( m )Γ ( n ) x < 0 < 1.78) A plot of the beta probability density function (pdf) for m = 3 and n = 2 . n ) = -----------------------.m – 1 ( 1 – x )n – 1 f ( x. driving habits.4 The Beta Distribution The beta distribution is defined as x (1 – x) f ( x. is shown in Figure 13.2 dv = -----2 2 – 2v 2 ∫0 1 v --------------.x < 0 < 1. m. m.77) 13. As with the gamma probability distribution.76) we obtain ∫ x --------------.74) becomes 2 2 ∫0 where Γ ( 3 ) = 2! 1 4v 8 -----------------. it will suffice to say that it is used in computing variations in percentages of samples such as the percentage of the time in a day people spent at work. (13.76) Then. n > 0 B ( m.6. -. n ) = -------------------------------------. a detailed discussion of the beta probability distribution is beyond the scope of this book.⎞ = 4 2 -----------------------------⎝ 2⎠ Γ(7 ⁄ 2) (13.

2580 0.7200 0.9400 0.28 0.34 m 3.The Beta Distribution x 0.18 0.6.0 0.9156 Probability Density Function 0.04 0.9600 0.8400 0.10 0.3188 0.6600 f(x.20 0.beta.4530 0.0784 0.0047 0. we see that when x = 1 .7400 1.0196 0.0 Γ(n) 1.n) 0. The pdf of the beta distribution We can evaluate the beta cumulative distribution function (cdf) with Excels’s BETADIST function whose syntax is BETADIST(x. However.0000 0.0 Γ(m+n) 24.2023 0.22 0.0 0.79) beta = the parameter n in (13.0707 0.4 0. is zero.24 0.6 0.1080 0.0144 2.0400 0.8 0.0484 0.alpha.8000 0.0016 (1-x)(n-1) 1.0676 0.1156 Figure 13.0 x(m-1) 0.14 0.02 0. the cumulative distribution (the area under the curve) at this point is 100% or unity since this is the upper limit of the x −range.7800 0.16 0.n) 1.0 n 2.06 0.30 0.0036 of the Beta Distribution 0.0406 0.00 0.12 0.1) which returns 1.0184 0.9000 0.9200 0. f ( x.08 0.m.4 x 0.6 1. This value can be verified by =BETADIST(1.0064 for m = 3 and n = 20. Third Edition Copyright © Orchard Publications 13−21 .8800 0.7000 0.0 0.3840 0.9800 0.3.2 0.2 0.0324 0.0000 0.0004 0.32 0.8356 0.B) where: x = value between A and B at which the distribution is to be evaluated alpha = the parameter m in (13.7560 0.6774 0.6.0100 0.79) A = the lower bound to the interval of x B = the upper bound to the interval of x From the plot of Figure 13.1024 0.0000 Numerical Analysis Using MATLAB® and Excel®.8 f(x. m.0000 0.A.6003 0.2.7600 0.m.8200 0.6800 0.26 0.8600 0.0.0256 0.0 0.0576 0. n ) which represents the probability density function.0900 0.5253 0.0 Γ(m) 2.1521 0.

If n is a positive integer. but not negative integer values.– ------------------.+ … ⎬ 12n 288n 2 51840n 3 2488320n 4 ⎩ ⎭ is referred to as Stirling’s asymptotic series for the Γ ( n ) function.Chapter 13 The Gamma and Beta Functions and Distributions 13. 2. 3.5 Summary • The gamma function. Third Edition Copyright © Orchard Publications .– ------------------------. Γ ( n ) = ( n – 1 )! Γ(1⁄2 ) = π π Γ ( n )Γ ( 1 – n ) = ------------sin nπ for 0 < n < 1 2 2n – 1 Γ(n) π = πΓ ( 2n ) • The relation Γ ( n + 1 ) = n! = for any n ≠ negative integer ⎫ n –n ⎧ 1 1139 571 2πnn e ⎨ 1 + -------.+ ------------. • To evaluate Γ ( n ) when n is a positive integer. • We can use the EXP(GAMMALN(n)) function to evaluate Γ ( n ) at some positive value of n . … • We can use MATLAB’s gamma(n) function to obtain values of Γ ( n ) . It is defined as Γ(n) = ∫0 x ∞ n – 1 –x e dx • It is convenient to use the relation Γ(n) = Γ(n + 1) -------------------n for n < 0 and the relation nΓ ( n ) = Γ ( n + 1 ) for n > 0 . and for all negative fractional. the 13−22 Numerical Analysis Using MATLAB® and Excel®. • The Γ ( n ) function and the factorial n! are related as Γ ( n + 1 ) = n! for n = 1. denoted as Γ ( n ) . is also known as generalized factorial function. we can use the relation • Other useful relations are shown below. • The Γ ( n ) function is defined for all positive integers and positive fractional values.

x < 0 < 1. • The gamma distribution which is defined as n – 1 –x ⁄ β x e f ( x. n. β > 0 n β Γ(n) • The beta function. n ) and gamma function Γ ( n ) are related by Γ ( m )Γ ( n ) .-----⎛ n + 1⎞ 2 Γ -⎝2 ⎠ ∫0 π⁄2 cos θ dθ = n ∫0 π⁄2 n > –1 are known as Wallis’s formulas. n ) = ------------------------Γ(m + n) • The beta B ( m. n ) function is also useful in evaluating certain integrals. n > 0 B ( m. n ) where m > 0 and n > 0 is defined as B ( m. Third Edition Copyright © Orchard Publications 13−23 . β ) = ------------------------.sin θ dθ = ---------------------. m. n ) = -------------------------------------. n ) m–1 n–1 Numerical Analysis Using MATLAB® and Excel®. n. • We can use MATLAB’s beta(m. • The relations n+1 Γ ⎛ ----------. n ) = ∫0 x 1 m–1 (1 – x) n–1 dx • The beta function B ( m. B ( m.Summary factorial n! can be approximated as n! ≈ 2πnn e n –n • The Γ ( n ) function is very useful in integrating some improper integrals.⎞ ⎝ 2 ⎠ π n . n ) function. B ( m.n) function to evaluate the beta B ( m. • The beta distribution is defined as (1 – x) x f ( x.x > 0. m.

e. compute B ( m. Third Edition Copyright © Orchard Publications . b.25 .6 Exercises 1. c.5 and n = – 1. Given that m = 2. Evaluate the following integrals a. n ) Verify your answer with MATLAB and Excel 3.Chapter 13 The Gamma and Beta Functions and Distributions 13. compute Γ(m + n) -----------------------Γ ( m )Γ ( n ) Verify your answer with MATLAB and Excel 2. Given that m = 10 and n = 8 . ∫0 ∞ e –x 3 dx 3 ∫0 ∞ xe –x dx ∫0 -----------------4 1–x 1 dx d. ∫0 π⁄2 tan θ dθ dx ∫0 --------------------2 3x – x 3 13−24 Numerical Analysis Using MATLAB® and Excel®.

5 )Γ ( – 1.25. n ) = -----------------------. Γ ( m )Γ ( n ) Γ ( 10 ) ⋅ Γ ( 8 ) ( 9! ) × ( 7! ) B ( m. n=−1.= 5.5.= 0.= -------------------------------------.25 ) Γ(5 ⁄ 4) -----------------------.= ---------------------------------------.= ----.= -----------------------------.25 ) ) Γ ( 1.Solutions to End−of−Chapter Exercises 13. we obtain their approximate values from tables.⋅ --------------------------. Then. by substitution into (1) we obtain: 3. -------------------By repeated use of the relations nΓ ( n ) = Γ ( n + 1 ) for n > 1 and Γ ( n ) = Γ ( n + 1 ) for n < 1 . where we find that Γ ( 1 ⁄ 4 ) = 3.1419e-006 Numerical Analysis Using MATLAB® and Excel®.= --------------------------------------------------------------------------------Γ ( –5 ⁄ 4 + 1 ) 3 ⁄ 2 ⋅ Γ ( 3 ⁄ 2 ) ⋅ ( –4 ⁄ 5 ) ⋅ Γ ( –1 ⁄ 4 ) Γ ( 3 ⁄ 2 + 1 ) ⋅ -----------------------------(1) ( –5 ⁄ 4 ) 5 Γ(1 ⁄ 4) 1 ⁄ 4 ⋅ Γ(1 ⁄ 4) = --------------------------------------------------------------------------------------------.2254 Γ ( m )Γ ( n ) Check with MATLAB: m=2.1739 48 π ⋅ 1. n we obtain Γ(m + n) Γ ( 2.1739 We cannot check the answer with Excel because it cannot compute negative values.25 ) Γ ( 5 ⁄ 2 ) ⋅ Γ ( –5 ⁄ 4 ) Γ(1 ⁄ 4 + 1) 1 ⁄ 4 ⋅ Γ( 1 ⁄ 4 ) = --------------------------------------------------------------.25 ) Γ ( 2.1419 × 10 17 ⋅ 16 ⋅ 15 ⋅ 14 ⋅ 13 ⋅ 12 ⋅ 11 ⋅ 10 980179200 Check with MATLAB: beta(10.= -------------------------------------------Γ ( m )Γ ( n ) Γ ( 2.8) ans = 5.= ------------------------17! Γ(m + n) Γ ( 18 ) 9⋅8⋅7⋅6⋅5⋅4⋅3⋅2⋅7⋅6⋅5⋅4⋅3⋅2 = -----------------------------------------------------------------------------------------------------------------------------------------17 ⋅ 16 ⋅ 15 ⋅ 14 ⋅ 13 ⋅ 12 ⋅ 11 ⋅ 10 ⋅ 9 ⋅ 8 ⋅ 7 ⋅ 6 ⋅ 5 ⋅ 4 ⋅ 3 ⋅ 2 –6 7⋅6⋅5⋅4⋅3⋅2 5040 = -----------------------------------------------------------------------------.= -------------------------.5 )Γ ( – 1.6256 and Γ ( 3 ⁄ 4 ) = 1. gamma(m+n)/(gamma(m)*gamma(n)) ans = 0.⋅ -----------------------------Γ ( 3 ⁄ 4 ) 48 π ⋅ Γ ( 3 ⁄ 4 ) 3 ⁄ 2 ⋅ 1 ⁄ 2 ⋅ Γ ( 1 ⁄ 2 ) ⋅ ( – 4 ⁄ 5 ) ⋅ -----------------–1 ⁄ 4 There are no exact values for Γ ( 1 ⁄ 4 ) and Γ ( 3 ⁄ 4 ) . therefore. Third Edition Copyright © Orchard Publications 13−25 .2254 .= ----.5 + ( – 1.6256 5Γ ( m + n )-----------------------.7 Solutions to End−of−Chapter Exercises 1. 2.

∫0 π⁄2 tan θ dθ = ∫0 π⁄2 sin θ 1 ⁄ 2 ⎛ ----------. 4 ∞ xe –x 3 dx = x 2 – 1 –x e dx = Γ ( 2 ) = 1! = 1 ( –3 ⁄ 4 ) 1 We let x = y or x = y 1⁄4 1 .⎞ dθ = ⎝ cos θ ⎠ ∫0 π⁄2 ( sin θ ) 1⁄2 ( cos θ ) –1 ⁄ 2 ( dθ ) From (13. Then. Third Edition Copyright © Orchard Publications .⋅ y dy = -.Γ ⎛ -.⎞ 3 3 ⎝3⎠ 3 ∫0 c. then x = y 3 1⁄3 1 ( –2 ⁄ 3 ) . Let x = y .⋅ -------------------------------4 2π ⁄ Γ ( 1 ⁄ 4 ) 4 Γ(3 ⁄ 4) 2 π 2 {Γ(1 ⁄ 4)} = ------------.⋅ ----------------------------------------4 Γ(3 ⁄ 4) (1) or π π Γ ( 3 ⁄ 4 ) ⋅ Γ ( 1 – 3 ⁄ 4 ) = ------------------------. ∫0 13−26 π⁄2 cos 2m – 1 θ ⋅ sin 2n – 1 θ dθ = ------------------------- Γ ( m )Γ ( n ) 2Γ ( m + n ) Numerical Analysis Using MATLAB® and Excel®.⋅ { Γ ( 1 ⁄ 4 ) } = --------------------------4 2π 4 2π d. 1 1 dx ----------------. ∞ e –x 3 ∫0 e ∫0 ∞ ∞ –y 1 1⁄3–1 1 1 ⋅ -. a.⋅ y dy . Γ ( 3 ⁄ 4 ) = -----------------Γ(1 ⁄ 4) and by substitution into (1) ∫0 -----------------4 1–x 1 dx 1 Γ(1 ⁄ 4) ⋅ π 1 Γ(1 ⁄ 4) ⋅ Γ(1 ⁄ 2) = -.= -4 4 1–x 1 = -4 ∫0 1 --------------.= -. dx = -. so 3 dx = ∫0 b.⋅ ----------------------------------------.⋅ y ( – 3 ⁄ 4 ) dy = 1 -4 1–y 1⁄2–1 ∫0 ( 1 – y ) ⋅y ( –3 ⁄ 4 ) dy ∫0 ( 1 – y ) 1 ⋅y 1⁄4–1 1 Γ(1 ⁄ 4) ⋅ Γ(1 ⁄ 2) dy = -.= ------------sin ( 3π ⁄ 4 ) 2⁄2 Γ(3 ⁄ 4) ⋅ Γ(1 ⁄ 4) = 2π 2π . dx = ( 1 ⁄ 4 )y dy and thus ( –1 ⁄ 2 ) ∫0 Also.Chapter 13 The Gamma and Beta Functions and Distributions 3.62).

= 2 3x – x ∫0 dx ----------------------.= ---------2Γ ( 3 ⁄ 4 + 1 ⁄ 4 ) 2Γ ( 1 ) 2 3 3 ∫0 3 dx --------------------. y = 0 and ∫0 1 y –1 ⁄ 2 ⋅ ( 3 – 3y ) –1 ⁄ 2 dy = = 3 1 ∫0 y 1 –1 ⁄ 2 –1 ⁄ 2 1 ⋅ -----.= B ⎛ --. n – 1 = – 1 ⁄ 2 .⋅ 3 3 –1 ⁄ 2 . then dx = 3dy . Third Edition Copyright © Orchard Publications 13−27 . x when x = 3 . m = 1 ⁄ 2 and thus ∫0 3 2 1 1 Γ(1 ⁄ 2) ⋅ Γ(1 ⁄ 2) {Γ(1 ⁄ 2)} dx .⎞ = ----------------------------------------. m = 1 ⁄ 2 .( 1 – y ) dy 3 –1 ⁄ 2 (2) ∫0 y –1 ⁄ 2 (1 – y) dy Recalling that B ( m. -. When x = 0 .--------------------. and the integral of (1) becomes 3 -----.= --------------------------.Solutions to End−of−Chapter Exercises Letting 2m – 1 = 1 ⁄ 2 and 2n – 1 = – 1 ⁄ 2 we obtain m = 3 ⁄ 4 and n = 1 ⁄ 4 . n ) = ∫0 x 1 m–1 (1 – x) n–1 Γ(m) ⋅ Γ(n) dx = ----------------------------Γ(m + n) it follows that m – 1 = – 1 ⁄ 2 . y = 1 . π⁄2 Γ ( 3 ⁄ 4 )Γ ( 1 ⁄ 4 ) 2π 2π tan θ dθ = ------------------------------------.Then.= -------------.= π ⎝2 2⎠ Γ(1 ⁄ 2 + 1 ⁄ 2) Γ(1) 2 3x – x Numerical Analysis Using MATLAB® and Excel®.= x(3 – x) –1 ⁄ 2 ∫0 x –1 ⁄ 2 –1 ⁄ 2 ⋅ (3 – x) –1 ⁄ 2 dx (1) = ( 3y ) = ( 3 ⁄ 3 )y Let x = 3y . ∫0 e.

orthogonal vectors.1. QR. orthogonal trajectories.1 Orthogonal Functions Orthogonal functions are those which are perpendicular to each other.Chapter 14 Orthogonal Functions and Matrix Factorizations T his chapter is an introduction to orthogonal functions. Figure 14. Third Edition Copyright © Orchard Publications 14−1 .1. and Singular Value Decomposition. y slope = m 1 slope = m 2 m1 ⋅ m2 = –1 x Figure 14. 14. This is shown in Figure 14. Mutually orthogonal systems of curves and vectors are of particular importance in physical problems. From analytic geometry and elementary calculus we know that two lines are orthogonal if the product of their slopes is equal to minus one.2 shows the angle between two curves C 1 and C 2 . Orthogonal curves Numerical Analysis Using MATLAB® and Excel®. Orthogonal lines Orthogonality applies also to curves. Cholesky. We begin with orthogonal lines and functions.2. Figure 14. and we conclude with the factorization methods LU.

14.= – -dx x (14. Other orthogonal functions are the cos x and sin x functions as we’ve learned in Chapter 6.2) are orthogonal trajectories of the curves of (14. Example 14. then.Chapter 14 Orthogonal Functions and Matrix Factorizations By definition. 14−2 Numerical Analysis Using MATLAB® and Excel®.4) we see that these two curves are orthogonal since their slopes are negative reciprocals of each other. the angle between the curves C 1 and C 2 is the angle β between their tangent lines L 1 and L 2 .2.3. If m 1 and m 2 are the slopes of these two lines.1 Prove that every curve of the family xy = a a≠0 (14. Third Edition Copyright © Orchard Publications . y ) on any curve of (14.1) is orthogonal to every curve of the family x –y = b 2 2 b≠0 (14. the slope is xdy + ydx = 0 or dy y ----. in Figure 14.3) On any curve of (14. L 1 and L 2 are orthogonal if m 2 = – 1 ⁄ m 1 .1). The cases where x = 0 or y = 0 cannot occur because we defined a ≠ 0 and b ≠ 0 .3) and (14. the curves of (14.2 Orthogonal Trajectories Two families of curves with the property that each member of either family cuts every member of the other family at right angles are said to be orthogonal trajectories of each other.1).4) From (14.2) Proof: At a point P ( x.2) the slope is 2xdx – 2ydy = 0 or dy = x -----y dx (14. The two families of these curves are shown in Figure 14. Thus.

Orthogonal Trajectories Figure 14. c = y ⁄ x and thus we rewrite (14.9) Numerical Analysis Using MATLAB® and Excel®.x2 ---.2 Find the orthogonal trajectories of the family of parabolas y = cx 2 Solution: The slope of (14.x = ----2 dx x x 2 (14.8) or 2ydy + xdx = 0 2 y dy + x dx = 0 2 y .6) as y dy 2y ----.= 2 ---.3.5) is c≠0 (14.7) Therefore.5) dy = 2cx ----dx (14. Third Edition Copyright © Orchard Publications 14−3 . Orthogonal trajectories Example 14.= k ( cons tan t ) 2 2 2 ∫ ∫ x + 2y = C ( cons tan t ) 2 2 (14.5).6) From (14.+ ---. the slope of the orthogonal family we are seeking must be xdy = – --------2y dx (14.

3 Given that X = [ 1 1 1 ] and Y = [ 2 1 2 ] find the dot product X ⋅ Y Solution: X ⋅ Y = (1) ⋅ (2) + (1) ⋅ (1) + (1) ⋅ (2) = 5 Definition:Two vectors X 1 and X 2 are said to be orthogonal if their dot product is zero. Orthogonal trajectories for families of parabolas and ellipses. Third Edition Copyright © Orchard Publications . Figure 14.3 Orthogonal Vectors Let X = [ x 1 x 2 x 3 … x n ] and Y = [ y 1 y 2 y 3 … y n ] be two vectors of the same length. Example 14.4.4 Test the vectors X 1 = [ 1 1 1 ] and X 2 = [ 1 – 2 1] for orthogonality.4.9) represents a family of ellipses and the trajectories are shown in Figure14. 14−4 Numerical Analysis Using MATLAB® and Excel®.10) Example 14. Their inner (dot) product is defined as X ⋅ Y = x 1 y 1 + x 2 y 2 + x 3 y 3 + … + x n y n (a scalar ) (14.Chapter 14 Orthogonal Functions and Matrix Factorizations Relation (14. 14.

T Numerical Analysis Using MATLAB® and Excel®.. 1 2 2 2 4 4 . For this example.-.. the vectors X 1 and X 2 are orthogonal to each other. Third Edition Copyright © Orchard Publications 14−5 . the matrix A is orthogonal and A⋅A = I T (14. the basis is called orthonormal basis.U X = -.Orthogonal Vectors Solution: X1 ⋅ X2 = ( 1 ) ⋅ ( 1 ) + ( 1 ) ⋅ ( –2 ) + ( 1 ) ⋅ ( 1 ) = 0 Therefore.-2 3 3 6 6 6 A basis that consists of mutually orthogonal vectors is referred to as an orthogonal basis. X = 2 +4 +4 = 6 2 2 2 To compute the unit vector U X we divide each element of X by the magnitude X . Thus.= -. If these vectors are also unit vectors. we compute the magnitude X .-. If the column (or row) vectors of a square matrix A are mutually orthogonal unit vectors.11) where A is the transpose of A and I is the identity matrix..5 Given that X = [2 4 4] compute the unit vector U X . This process is called normalization.-. Example 14. With any vector X ≠ 0 we may associate a unique unit vector U which is obtained by dividing each component of X by each magnitude X defined as X = x1 + x2 + … + xn 2 2 2 where x i represents an element of the vector X . Solution: First.

Third Edition Copyright © Orchard Publications .6 Given that A = 1⁄2 1⁄4 1⁄2 1⁄2 find an orthonormal set of eigenvectors* and verify that the result satisfies (14. To find a 2 × 2 square matrix Z such that we begin with z1 z2 –z1 z2 ⋅ Z⋅Z = I z1 –z1 z2 z2 2 2 T = 1 0 0 1 (14. Solution: First.Chapter 14 Orthogonal Functions and Matrix Factorizations Example 14.13) Equating like terms we obtain z1 + z2 = 1 2 2 2 2 –z1 + z2 = 0 2 2 2 From the second equation we obtain z 1 = z 2 and by substitution into the first we obtain 2z 1 = 1 or * It is strongly suggested that the reader reviews the definitions of eigenvalues and eigenvectors in Chapter 5 at this time. we find the eigenvalues of the matrix A from the relation det ( A – λI ) = 0 where for this example ⎛ ⎞ det ⎜ 1 ⁄ 2 1 ⁄ 4 – λ 1 0 ⎟ = 0 ⎝ 1⁄2 1⁄2 0 1 ⎠ det 1 ⁄ 2 – λ 1⁄2 2 1⁄4 1⁄2–λ = 0 λ – λ + 3 ⁄ 16 = 0 from which λ 1 = 1 ⁄ 4 and λ 2 = 3 ⁄ 4 and as we’ve learned in Chapter 5.11).12) or z1 + z2 2 –z1 2 2 –z1 + z2 2 z1 + 2 z2 + 2 z2 = 1 0 0 1 (14. 14−6 Numerical Analysis Using MATLAB® and Excel®. with these eigenvalues we can obtain an infinite number of eigenvectors.

⋅ Y 1 Ym – 1 ⋅ Ym – 1 Y1 ⋅ Y1 (14. We must remember that the products in (14.14) below are the inner (dot) products and if X = [ x 1 x 2 x 3 … x n ] and Y = [ y 1 y 2 y 3 … y n ] are two vectors of the same length their dot product is defined as X ⋅ Y = x 1 y 1 + x 2 y 2 + x 3 y 3 + … + x n y n (a scalar ) .14) the dot products on the numerator and denominator must be found first and the result must be from the dot product of it and Y 1 Y1 = X1 Y1 ⋅ X2 Y 2 = X 2 – ----------------.4 The Gram-Schmidt Orthogonalization Procedure Let X 1. …X m be some column vectors.⋅ Y 1 Y1 ⋅ Y1 Y1 ⋅ X3 Y2 ⋅ X3 Y 3 = X 3 – ----------------. Thus in the second equation in (14. We can find an orthogonal basis Y 1.⋅ Y 1 Y2 ⋅ Y2 Y1 ⋅ Y1 … Ym – 1 ⋅ Xm Y1 ⋅ Xm Y m = X m – -------------------------------. X 2.We choose the value 1 ⁄ 2 and then the first (left most) matrix in (14. …Y m using the following relations.⋅ Y 2 – ----------------.The Gram-Schmidt Orthogonalization Procedure z1 = z2 = 1 ⁄ ( ± 2 ) This result indicates that we can choose either 1 ⁄ 2 or 1 ⁄ ( – 2 ) for the values of z 1 and z 2 .12) is Z = 1⁄ 2 1⁄ 2 1 ⁄ (– 2) 1 ⁄ 2 and as a check. 1 ⁄ 2 ⋅ 1 ⁄ 2 1 ⁄ (– 2) = 1 0 0 1 1 ⁄ (– 2) 1 ⁄ 2 1⁄ 2 1⁄ 2 1⁄ 2 The computations for finding orthonormal sets of eigenvectors for larger size ( 3 × 3 or higher) matrices using the above procedure becomes quite involved. Third Edition Copyright © Orchard Publications 14−7 . Y 2. A simpler procedure is the GramSchmidt orthogonalization procedure which is discussed on the next section.⋅ Y m – 1 – … – -----------------. the unit vectors Numerical Analysis Using MATLAB® and Excel®. 14.14) Also.

[ 1 1 1 ] 3 Y2 ⋅ Y2 Y1 ⋅ Y1 6 = [ 1 2 3 ] – [ 2 2 2 ] = [ –1 0 1 ] T T T and from (14.= [ – 1 ⁄ 2 0 1 ⁄ 2 ] Y3 and denoting the matrix whose elements are the unit vectors as A . I=A*A' 14−8 Numerical Analysis Using MATLAB® and Excel®.15) Y1 T U 1 = -------.= [ 1 ⁄ 3 1 ⁄ 3 1 ⁄ 3 ] Y1 Y2 T U 2 = -------.⋅ Y 1 = [ 1 2 3 ] – -. we have: 1⁄ 3 A = 1⁄ 3 1⁄ 3 T 1⁄ 6 –2 ⁄ 6 1⁄ 6 –1 ⁄ 2 0 1⁄ 2 We can verify that A ⋅ A = I with the MATLAB script below. Solution: From (14.7 Given that X 1 = [ 1 1 1 ] .⋅ Y 2 – -.⋅ Y 2 – ----------------. … .Chapter 14 Orthogonal Functions and Matrix Factorizations Yi U i = ------Yi i = 1.= [ 1 ⁄ 6 – 2 ⁄ 6 1 ⁄ 6 ] Y2 Y3 T U 3 = -------.⋅ Y 1 = [ 1 – 2 1 ] 3 Y1 ⋅ Y1 Y1 ⋅ X3 Y2 ⋅ X3 6 T 0 T Y 3 = X 3 – ----------------. X 2 = [ 1 – 2 1 ] . 2. 1/sqrt(3) 1/sqrt(6) 1/sqrt(2)]. In our subsequent discussion the column vectors will be denoted as row vectors transposed. 1/sqrt(3) −2/sqrt(6) 0. Example 14. m (14.⋅ Y 1 = [ 1 – 2 1 ] – -. A=[1/sqrt(3) 1/sqrt(6) −1/sqrt(2).15) are mutually orthogonal and form an orthonormal basis.14) Y1 = X1 = [ 1 1 1 ] T T T T Y1 ⋅ X2 T 0 T Y 2 = X 2 – ----------------. find an orthonormal basis. Third Edition Copyright © Orchard Publications . and X 3 = [ 1 2 3 ] .

L 11 0 0 x1 x3 b1 b3 L 21 L 22 0 L 31 L 32 L 33 ⋅ x2 = b2 The unknowns are found from Numerical Analysis Using MATLAB® and Excel®.0000 -0.0000 0 1. In Chapter 4 we saw how the method of Gaussian elimination proceeds by systematically removing the unknowns from a system of linear equations.0000 14.0000 -0. that is. the vectors produced by MATLAB also satisfy the condition C ⋅ C = I .0000 0.9153 0. Consider the following 3 × 3 lower triangular case.0000 -0.0000 0.0000 -0. The LU factorization method decomposes a matrix A into a lower triangular matrix L and an upper triangular matrix U so that A = L ⋅ U . The reason for this difference is that the orthogonalization process is not unique. 1 −2 1.0000 0.4027 0. Third Edition Copyright © Orchard Publications 14−9 .The LU Factorization I = 1.0000 0 0.0000 -0.0000 -0. 1 2 3]. we may find different values depending on the process being used.0000 1.4027 We observe that the vectors of the C matrix produced by MATLAB are different from those we derived with the Gram-Schmidt orthogonalization procedure. computers use the so-called matrix factorization methods to decompose a matrix A into a product of other smaller matrices.5 The LU Factorization In matrix computations. As shown below. I=C*C' T I = 1.0000 1.0000 0 1. B=[1 1 1.9153 0.0000 1.0000 0.0000 0 0.0000 We can also use the MATLAB function orth(A) to produce an orthonormal basis as shown below. C=orth(B) C = -0.

19) To find the three unknowns.16) provided that L 11 ⋅ L 22 ⋅ L 33 ≠ 0 . Likewise. Third Edition Copyright © Orchard Publications .18) provided that U 11 ⋅ U 22 ⋅ U 33 ≠ 0 . With these two reductions we obtain 2v 1 – v 2 + 3v 3 = 5 – 5v 2 + 4v 3 = 18 2. For the upper triangular case. The substitution order in (14. x 3 = b 3 ⁄ U 33 x 2 = ( b 2 – U 23 x 3 ) ⁄ U 22 x 1 = ( b 1 – U 12 x 2 – U 13 x 3 ) ⁄ U 11 (14. Example 14. we multiply the first equation by 3 ⁄ 2 and we subtract it from the third equation.Chapter 14 Orthogonal Functions and Matrix Factorizations x 1 = b 1 ⁄ L 11 x 2 = ( b 2 – L 21 x 1 ) ⁄ L 22 x 3 = ( b 3 – L 31 x 1 – L 31 x 2 ) ⁄ L 33 (14. The substitution order in (14. to solve U 11 U 12 U 13 0 0 U 33 x1 x3 b1 0 U 22 U 23 ⋅ x 2 = b 2 b3 (14.8 Let us review the example given in Chapter 4 which consists of the following equations.16) is referred to as forward substitution.20) 14−10 Numerical Analysis Using MATLAB® and Excel®. the unknowns are written in reverse order. This removes v 1 from the second equation. Thus. 2v 1 – v 2 + 3v 3 = 5 – 4v 1 – 3v 2 – 2v 3 = 8 3v 1 + v 2 – v 3 = 4 (14.5 (14.18) is referred to as backward substitution.5 v 3 = – 3.17) we start from the bottom to the top as shown below. we begin by multiplying the first equation by – 2 and subtracting it from the second equation.5v 2 – 5.

The elements of matrix U are the coefficients of v 1 .5 (14. L=A*inv(U) L = Numerical Analysis Using MATLAB® and Excel®. 0 −5 4.20). and v 3 in (14. v 2 . Thus. let us use the relations of (14.16) and (14.18) to find the lower and upper triangular matrices of our example where 2 –1 3 A = –4 –3 –2 3 1 –1 We want to find L ij and U ij such that L 11 0 0 ⋅ U 11 U 12 U 13 2 –1 3 0 U 22 U 23 = A = – 4 – 3 – 2 3 1 –1 0 0 U 33 L 21 L 22 0 L 31 L 32 L 33 (14.22) where the first matrix on the left side is the lower triangular matrix L and the second is the upper triangular matrix U . U 11 U 12 U 13 0 U 22 U 23 0 0 U 33 2 –1 3 = 0 –5 4 0 0 – 3.The LU Factorization Next we multiply the second equation of (14. To find the elements of matrix L we use MATLAB to multiply matrix A by the inverse of matrix U . Thus.21) We see that the eliminations have transformed the given square system into an equivalent upper triangular system that gives the same solution which is obtained as follows: v 3 = – 11 ⁄ 7 v 2 = ( 18 – 4v 3 ) ⁄ ( – 5 ) = – 34 ⁄ 7 v 1 = ( 5 + v 2 – 3v 3 ) ⁄ 2 = 17 ⁄ 7 The elements of the upper triangular matrix U are the coefficients of the unknowns in (14. −4 −3 −2. 2v 1 – v 2 + 3v 3 = 5 – 5v 2 + 4v 3 = 18 – 3. 0 0 −3.5].5 v 3 = 5. U=[2 −1 3. Third Edition Copyright © Orchard Publications 14−11 .20) by – 1 ⁄ 2 and we subtract it from the third equation of (14.21). 3 1 −1].5 Now. A=[2 −1 3.20) and we obtain the system of equations below.

−2 1 0. Third Edition Copyright © Orchard Publications . These values are the multipliers that we’ve used in the elimination process in succession.5]. L 31 = 3 ⁄ 5 . and L 32 = – 1 ⁄ 2 . 0 −5 4.U]=lu(A) to decompose the matrix 2 –3 1 A = –1 5 –2 3 –8 4 14−12 Numerical Analysis Using MATLAB® and Excel®. Was this necessary? The answer is no. we found the elements of the lower triangular matrix L by first computing the inverse of the upper triangular matrix U and performing the matrix multiplication but not L = U ⋅ A . the matrix A has been decomposed to a lower triangular matrix L and an upper matrix U as shown below.Chapter 14 Orthogonal Functions and Matrix Factorizations 1 -2 3/2 0 1 -1/2 0 0 1 Therefore. U=[2 −1 3. Example 14. 3/2 −1/2 1]. the lower triangular matrix has the form L = A⋅U 1 0 0 L = L 21 1 0 L 31 L 32 1 –1 –1 and in our example we found that the values of the subdiagonal elements are L 21 = – 2 . For a square matrix where none of the diagonal elements are zero.5 Check with MATLAB: L=[1 0 0. A=L*U A = 2 -4 3 -1 -3 1 3 -2 -1 In the example above.9 Use the MATLAB function [L. 0 0 −3. 2 –1 3 1 0 = –2 –4 –3 –2 1 3 1 –1 3 ⁄ 2 –1 ⁄ 2 0 2 –1 3 ⋅ 0 –5 4 0 1 0 0 – 3.

To find out how MATLAB performs LU factorization. To put L in the proper structure. 0 7/3 −2/3. let us interchange the first and third rows. the lower triangular matrix L lacks structure.e. −1/3 1 0. Let us now use MATLAB to see if L' ⋅ U = A .23) The new matrix L' has now the proper structure. When a matrix lacks structure we say that it is permuted.U] = lu(X) stores an upper triangular matrix in U and a "psychologically lower triangular matrix" (i. U=[3 −8 4. let us invoke the help lu command. 1 0 L' = – 1 ⁄ 3 1 2⁄3 1 0 0 1 (14. a product Numerical Analysis Using MATLAB® and Excel®.The LU Factorization into a lower and an upper triangular. To put it in the given form we need to make the same interchanges in rows as with the lower triangular matrix. [L. L1=[1 0 0. 2/3 1 1]. −1 5 −2. that is. A1=L1*U A1 = 3 -1 2 -8 5 -3 4 -2 1 We observe that matrix A is now permuted. 0 0 −1]. 3 −8 4]. Then. help lu LU LU factorization. [L.U]=lu(A) L = 2/3 -1/3 1 U = 3 0 0 -8 7/3 0 4 -2/3 -1 1 1 0 1 0 0 We observe that while the upper triangular matrix U has the proper structure. Third Edition Copyright © Orchard Publications 14−13 . we must interchange the first and third rows. Solution: format rat. Only part of the display is shown below. A=[2 −3 1.

and permutation matrix P so that P*X = L*U. the identity matrix 1 0 0 I = 0 1 0 0 0 1 If we interchange the first and third rows of the identity matrix I above. for example.P]=lu(A) to decompose the matrix 2 –3 1 A = –1 5 –2 3 –8 4 into a lower and an upper triangular and show that P ⋅ A = L ⋅ U .9. Example 14. [L. X can be rectangular.P]=lu(A) L = 1 -1/3 2/3 0 1 1 0 0 1 14−14 Numerical Analysis Using MATLAB® and Excel®. Solution: This is the same matrix as in Example 14. [L. so that X = L*U.U. 3 −8 4].24) and matrix P indicates the same interchanges as with the lower triangular matrix in Example 14. 0 0 1 P = 0 1 0 1 0 0 (14.Chapter 14 Orthogonal Functions and Matrix Factorizations of lower triangular and permutation matrices) in L. Thus.U. upper triangular matrix U.9. A=[2 −3 1. Third Edition Copyright © Orchard Publications . Consider. we obtain the permutation matrix P below.10 Use the MATLAB function [L. The permutation matrix P is an identity matrix that is permuted so that the rows of this matrix indicate the interchanges. −1 5 −2.P] = lu(X) returns unit lower triangular matrix L.U.

]. % The function ExchRows interchanges rows i and j % of a matrix or vector X % function X = ExchRows(X. X(i.:) = temp. LU=L*U PA = 3 -1 2 LU = 3 -1 2 -8 5 -3 4 -2 1 -8 5 -3 4 -2 1 We observe that P ⋅ A = L ⋅ U with the first and second rows interchanged when compare with the given matrix A .. i = {first row # to be interchanged}.m % To run this program. Third Edition Copyright © Orchard Publications 14−15 . The user−defined function ExchRows below. % This file is saved as ExchRows.:).:) = X(j. Also.j) % temp = X(i.. PA=P*A.The LU Factorization U = 3 0 0 P = 0 0 1 0 1 0 1 0 0 -8 7/3 0 4 -2/3 -1 We observe that the lower triangular matrix has now the proper structure and the P matrix displayed by MATLAB is the same as in (14.i. X(j. and Numerical Analysis Using MATLAB® and Excel®.. The MATLAB matrix left division operator x = A\b uses the L ⋅ U factorization approach.24). define the matrix or vector % X and the indices i and j in MATLAB's Command Window % as X=[. interchanges rows i and j j of a vector or matrix X. % j = {row # to be interchanged with row i}.:).

First. let v=[2 −1 3 −5 7 −9 −12]'. 4 −9 −8 −1]. and for matrices is a row vector containing the maximum element from each column. As an example. Example 14. Third Edition Copyright © Orchard Publications .11 Given that the matrix X is defined as –2 5 X = –3 –6 7 –5 4 –9 –4 8 3 –8 9 1 2 –1 use the ExchRows.m]=max(v) Amax = 7 m = 5 [Amax.m]=max(abs(v)) 14−16 Numerical Analysis Using MATLAB® and Excel®. j = 3. let us explain the use of MATLAB’s built-in function max(v) where v is a row or a column vector. max(v) ans = 7 [Amax.j)at the command prompt. −3 −6 8 1. ExchRows(X. Solution: At the MATLAB command prompt we enter X=[−2 5 −4 9.j) and MATLAB outputs X = 7 -3 -2 4 -5 -6 5 -9 3 8 -4 -8 2 1 9 -1 The user−defined function GaussElimPivot below.i. 7 −5 3 2. i = 1. performs Gauss elimination with row pivoting.Chapter 14 Orthogonal Functions and Matrix Factorizations % then type ExchRows(X.m user−defined function above to interchange rows 1 and 3.i.

/z(k:n)).m] = max(abs(A(k:n.k) ~= 0 alpha = A(i. A = ExchRows(A.k+1:n)*b(k+1:n))/A(k.The LU Factorization Amax = 12 m = 7 % This user−defined function file solves A*x=b by % the Gauss elimination with row pivoting method.k)).k.1). error('Matrix is singular').1:n))). if Amag < eps.2) > 1. z = zeros(n. function x = GaussElimPivot(A. Third Edition Copyright © Orchard Publications 14−17 . z(i) = max(abs(A(i.b) if size(b. end end end % Back substitution phase for k = n:−1:1 b(k) = (b(k) − A(k.k).k)/A(k.k).k+1:n) b(i) = b(i) − alpha*b(k). end if m ~= k b = ExchRows(b. z = ExchRows(z.m). A(i. b=b'.m). end % The statements below exchange rows if required for k = 1:n−1 [Amag.k+1:n) − alpha*A(k.k. x is a column vector that % will display the computed unknown values. and b % is a column vector that contains the known values % on the right hand side. end Numerical Analysis Using MATLAB® and Excel®.m). % A is a matrix that contains the coefficients of % the system of equations. m = m + k − 1.k+1:n) = A(i. % Set up scale factor array for i = 1:n. end % Elimination steps for i = k+1:n if A(i.k. end n = length(b).

0000 -1.7143 2.12 Given that –2 5 A = –3 –6 7 –5 4 –9 –4 8 3 –8 x1 9 –3 1 .0000 3.2857 -3.8571 9.5714 -2.0000 -8.0000 -9.b).0000 -8.0000 -2.1429 3.0000 9.0000 1. 7 −5 3 2.0000 1.0000 4.2857 -4.0000 -3.8571 10.0000 -5.0000 -2.0000 3.2857 -3. Solution: At the MATLAB command prompt we enter A=[−2 5 −4 9.8571 9. x = x2 x3 2 8 –1 5 x4 use the GaussElimPivot user−defined function above to compute the values of the vector x.0000 -5. 4 −9 −8 −1]. b = 2 .0000 -8.1429 -5.7143 3.0000 A = 7.1429 -9.0000 1.5714 -6.0000 2.0000 9.0000 -3.0000 A = 7.0000 4.0000 -8.0000 4.0000 9.5714 -1.0000 9.1429 3. b = [−3 2 8 5]'.9298 -9.0000 -2.5714 -6. x Example 14.1429 14−18 Numerical Analysis Using MATLAB® and Excel®.0000 4.0000 -5.5714 -9.b).Chapter 14 Orthogonal Functions and Matrix Factorizations % Enter the values of A and b at the MATLAB's % command window and type GaussElimPivot(A.1429 3.0000 -8. GaussElimPivot(A.0000 1. −3 −6 8 1.0000 -3.1429 -8.0000 -2.2857 0.8571 9. x and MATLAB outputs the following: A = 7.0000 2.1429 5.0000 A = 7.1429 2.1429 3. Third Edition Copyright © Orchard Publications .3860 -2.0000 -3.

0000 -3. function [A.2857 -16.0000 -2.1176 -0.1429 3.0980 3.5439 2.0000 -2. returns A = L*U % and the row permutation vector permut n = size(A.0000 4. Third Edition Copyright © Orchard Publications 14−19 .0000 -8.0000 x = 0.0000 1.5714 -1.7451 -1.1429 -6. z = zeros(n.9298 -16.2857 0.1).1:n))).1373 The user−defined function LUdecomp below.7193 3.m).permut] = LUdecomp(A) % LU decomposition of matrix A. end % Exchange rows if necessary for k = 1:n−1 [Amag. for i = 1:n.1429 -5.5439 10.1176 2.9298 0.The LU Factorization A = 7. Numerical Analysis Using MATLAB® and Excel®.0000 9.m] = max(abs(A(k:n.1). performs LU decomposition.8571 -3.k.k)).0000 4. if Amag < eps error('Matrix is singular') end if m ~= k z = ExchRows(z.0000 A = 7.0000 9.0980 0.7193 0. z(i) = max(abs(A(i. permut = (1:n)'.0000 -8.k.5714 -6. and returns matrix A as A=L*U and the row permutation vector permut./z(k:n)).m).1429 3.7451 -5.0000 -3.1373 Check with MATLAB’s left division: x=b\A x = 0.8571 10.3860 -3.0000 1. m = m + k − 1.1889 -0. A = ExchRows(A.

0556 2.5714 -0.7544 -0. 4 −9 −8 −1]. −3 −6 8 1.2857 -16.k+1:n) − alpha*A(k.0000 -8.1429 0.2857 permut = 3 2 4 1 Check: -5. Third Edition Copyright © Orchard Publications .4286 0.k)~=0 alpha = A(i.k+1:n) = A(i. end % Elimination pass for i = k+1:n if A(i.Chapter 14 Orthogonal Functions and Matrix Factorizations permut = ExchRows(permut.k).0000 1.4386 3.8571 -3. 7 −5 3 2.13 Given that –2 5 A = –3 –6 7 –5 4 –9 –4 8 3 –8 9 1 2 –1 use the LUdecomp user−defined function above to decompose matrix A and show how the given rows were permuted.permut] = LUdecomp(A) A = 7. [A.k)/A(k.5439 10.k+1:n). Solution: At the MATLAB command prompt we enter A=[−2 5 −4 9.1889 14−20 Numerical Analysis Using MATLAB® and Excel®.7193 -0.0000 -0.0000 9.k) = alpha. A(i. A(i.k. end end end Example 14.m).

0556 2.5714 -0.2632 0 1 0 0 0 0 1 0 ans = 7. end n = size(A.0000 2.P]=lu(A) L = 1.2857 -5.4694 -15. x(i)= b(permut(i)).0417 3.9796 -3.8571 -3.2857 -16.0816 -0.1). for i = 1:n. is saved as LUsolPivot.0761 -5.1376 0.U.0000 -0.7193 -0. Third Edition Copyright © Orchard Publications 14−21 .5439 10.m and will be used in the user−defined function matInvert that follows.1889 The user−defined function LUsolPivot listed below.4347 10.0408 U = 7.The LU Factorization [L. b = b'.0000 0 0 0 P= 1 0 0 0 L*U 0 1.4386 3. % function x = LUsolPivot(A.permut) % % The six statements below rearrange vector b and % stores it in vector x.0000 -8.b.0000 -0.0000 1.0000 0. % if size(b) > 1.0000 9.0000 -8.0000 -0.0000 1.7544 -0. % In this user−defined function matrix A and column % vector b are entered in MATLAB's command window % and “permut” holds the row permutation data.0000 9. x = b.4490 0 0 0 0 0 1 0 0 1.6612 0 0 0 0 1.1429 0.0612 0.4286 0. Numerical Analysis Using MATLAB® and Excel®.

Third Edition Copyright © Orchard Publications .1).14 Invert the matrix A below with the user−defined function matInvert. end The user−defined function matInvert below.k).k+1:n)*x(k+1:n))/A(k.1:k−1)*x(1:k−1). 14−22 Numerical Analysis Using MATLAB® and Excel®. and store results in Ainv % replacing the corresponding vector using the % user−defined function LUsolPivot saved previously. % The statement below performs LU decomposition % using the user−defined function LUdecomp(A) saved % previously % [A. % Creates identity matrix of size n. inverts matrix A with LU decomposition.Ainv(:. % % The last three statements solve for each vector % on the right side. % Ainv = eye(n).i).i) = LUsolPivot(A.permut). % This user−defined function inverts a matrix A % defined in MATLAB's command prompt using LU % decomposition % function Ainv = matInvert(A) % n = size(A. % for i = 1:n Ainv(:.Chapter 14 Orthogonal Functions and Matrix Factorizations end % % The next six statements perform forward and % backward substitution % for k = 2:n x(k) = x(k)− A(k. end for k = n:−1:1 x(k) = (x(k) − A(k.permut] = LUdecomp(A). % Assigns the size of A to n. end Example 14.

0719 0.0610 0.0208 0. Ainv = matInvert(A) and MATLAB returns Ainv = -0. It is a special case of LU factorization and requires fewer computations than the LU factorization method of the previous section.0078 0.26) Relation (14.1174 0. −3 −6 8 1.0447 0.0389 0.0683 -0.0013 -0.6 The Cholesky Factorization A matrix is said to be positive definite if x ⋅A⋅x>0 T T (14.The Cholesky Factorization –2 5 A = –3 –6 7 –5 4 –9 –4 8 3 –8 9 1 2 –1 Solution: In MATLAB’s command prompt we enter A=[−2 5 −4 9.0013 -0.0242 -0.0981 inv(A) -0.0783 -0.0389 0. Let us invoke the MATLAB help chol command to see how MATLAB performs this factorization.0369 0.1174 0.0055 Check with MATLAB’s built−in inv(A) function. Under those conditions. Numerical Analysis Using MATLAB® and Excel®.0683 -0.25) for every x ≠ 0 and A is symmetric.0078 0.0981 -0. 7 −5 3 2. that is.0719 0.0208 0.0447 0.0055 14.0783 -0.0201 -0. there exists an upper triangular matrix G with positive diagonal elements such that G ⋅G = A T (14.26) is referred to as Cholesky factorization.0416 -0.0610 0.0369 0.0416 -0.0242 -0. Third Edition Copyright © Orchard Publications 14−23 .0201 -0. ans = -0. 4 −9 −8 −1]. A = A .

help eye EYE Identity matrix. DIAG(X.1). EYE(N) is the N-by-N identity matrix. DIAG(V) is the same as DIAG(V. K = 0 is the main diagonal.1). RANDN.k) as defined by MATLAB. Example m = 5. then R = CHOL(X) produces an upper triangular R so that R'*R = X.-1) produces a tridiagonal matrix of order 2*m+1. then p is a positive integer. K > 0 is above the main diagonal and K < 0 is below the main diagonal. [R. an error message is printed. We will consider an example using the Cholesky factorization after we review the MATLAB functions eye(n) and diag(v.1) + diag(ones(2*m.Chapter 14 Orthogonal Functions and Matrix Factorizations CHOL Cholesky factorization. EYE(SIZE(A)) is the same size as A.0) and puts V on the main diagonal. DIAG(X) is the main diagonal of X. Third Edition Copyright © Orchard Publications . RAND. with two output arguments. See also ONES.N) or EYE([M. EYE(M. See also SPDIAGS. If X is positive definite. If X is not positive definite. DIAG(V. If X is positive definite. TRIL.N]) is an M-by-N matrix with 1's on the diagonal and zeros elsewhere. TRIU.K) when X is a matrix is a column vector formed from the elements of the K-th diagonal of X. 14−24 Numerical Analysis Using MATLAB® and Excel®. ZEROS. The lower triangular is assumed to be the (complex conjugate) transpose of the upper. then p is 0 and R is the same as above. never produces an error message. DIAG(DIAG(X)) is a diagonal matrix. diag(-m:m) + diag(ones(2*m. help diag DIAG Diagonal matrices and diagonals of a matrix. But if X is not positive definite.p] = CHOL(X). CHOL(X) uses only the diagonal and upper triangle of X.K) when V is a vector with N components is a square matrix of order N+ABS(K) with the elements of V on the K-th diagonal.

15 Use MATLAB to compute the Cholesky factorization of matrix A as defined below. Numerical Analysis Using MATLAB® and Excel®.45 2. A1=G'*G Solution: Execution of the MATLAB script above displays the following: A = 5. −1)+diag(B.00 -0. Third Edition Copyright © Orchard Publications 14−25 .75 5.00 -0.25 5.00 We observe that A1 = A .00 -1.00].25 −0.00 5.00 0 0 -0. format bank.21 0 0 0 -0. 1).00 -0.11 2. A can be factored as A = QR (14.22 0 0 0 -0.25 5.22 2.00 5. A=5*eye(5)+diag(B.50 5.7 The QR Factorization The QR factorization decomposes a matrix A into the product of an orthonormal matrix and an upper triangular matrix.The QR Factorization Example 14. that is.00 0 0 0 -0. G=chol(A). 14.00 -0.50 0 -0.50 −0. In other words. the matrix product G ⋅ G = A is satisfied.00 -0.R]=qr(A) produces an n × n matrix whose columns form an orthonormal or unitary* matrix Q and an upper triangular matrix R of the same size as matrix A . The MATLAB function [Q.25 0 0 0 -0.25 0 -0.00 -1.00 0 0 0 -1.50 0 0 0 -0.50 5.75 −1.34 2.75 0 T 0 0 -0.23 0 0 0 -0.00 0 0 -0.75 0 0 0 G = 2.27) * An n × n matrix A is called unitary if ( A∗ ) = A T –1 where A∗ is the complex conjugate matrix of A .19 0 0 0 -1. B=[−0.75 5.24 0 0 0 0 A1 = 5.

29) The MATLAB [Q. C.R] = QR(A) returns both Q and R. then only the first n columns of Q are computed.R.0) produces the "economy size" decomposition.28) and multiplying both sides of (14. [Q. If A is m-by-n with m > n. R = QR(A. TRIU(QR(A)) is R. The least squares approximate solution to A*x = b can be found with the Q-less QR decomposition and one step of iterative refinement: x r e x = = = = R\(R'\(A'*b)) b .B). but Q is often nearly full.A*x R\(R'\(A'*r)) x + e. 14−26 Numerical Analysis Using MATLAB® and Excel®.R] = QR(A. so that Q*R = A(:. QR(A) is the output of LAPACK'S DGEQRF or ZGEQRF routine. an upper triangular R and a unitary Q so that A*E = Q*R. [Q.R] = QR(A. where B has as many rows as A.R] = QR(A) produces an upper triangular matrix R of the same dimension as A and a unitary matrix Q so that A = Q*R. The column permutation E is chosen so that abs(diag(R)) is decreasing. [Q. [Q.28) by Q ⋅ Q = I we obtain Rx = Q b T T (14. Third Edition Copyright © Orchard Publications . R = QR(A) returns only R.0) and [C.Chapter 14 Orthogonal Functions and Matrix Factorizations Then. Q.R]=qr(A) is described as follows: help qr QR Orthogonal-triangular decomposition.R] = QR(A. The column permutation E is chosen so that abs(diag(R)) is decreasing. returns C = Q'*B.E). By itself.E] = QR(A.E] = QR(A) produces a permutation matrix E.0) produces an "economy size" decomposition in which E is a permutation vector. The full version of QR does not return C.B. Note that R = chol(A'*A). a system described by Ax = b becomes QRx = b (14.0) produce economy size results.R.

00 0.58 Check = 4. [Q.00 1.77 0.58 0.35 -3.24 0 -0.27 -0.00 -0. since the elements are real numbers. x=R\Q'*b T Q = -0.74 0 0 x = 4. the complex conjugate of Q is also Q and thus we only need to show that Q = Q Q*Q' ans = 1. b=[2 4 5]'.43 7.00 -0.28 1.R]=qr(A).43 7. Of course.00 Check=A\b -0.00 -0.00 -0.15 9.58 -4.58 0.00 0.54 0. Solution: A=[2 −3 1. −1 5 −2.16 Given that 2 –3 1 2 A = – 1 5 – 2 and b = 4 3 –8 4 5 solve Ax = b using the MATLAB function [Q.R]=qr(A) and x = R\Q b .53 0.00 T –1 or Q ⋅ Q = I .The QR Factorization Example 14.00 Let us verify that the matrix Q is unitary.80 R = -3.62 -0.14 4.14 4. T Numerical Analysis Using MATLAB® and Excel®.00 1. Third Edition Copyright © Orchard Publications 14−27 . 3 −8 4].

1429 4. and V . V]=svd(A).4286 7. Example 14.* that is. The function pinv(A) displays the pseudoobtaininverse of a m × n (non−square) matrix A . X=lsqnonneg(A. −1 5 −2. systems with more equations than unknowns as in applications where we need to find the least square distance in linear regression.b). S .0000 Underdetermined systems have infinite solutions and MATLAB selects one but no warning message is displayed.8 Singular Value Decomposition The Singular Value Decomposition (SVD) method decomposes a matrix A into a diagonal matrix S . b=[2 4 5]'. For example.Chapter 14 Orthogonal Functions and Matrix Factorizations QR factorization is normally used to solve overdetermined systems.b) returns X = 4. of the same dimension as A and with nonnegative diagonal elements in decreasing order. As we’ve learned in Chapter 4. S. if A is square.17 Decompose the matrix * We defined overdetermined and underdetermined systems in Chapter 8 14−28 Numerical Analysis Using MATLAB® and Excel®. then pinv(A)=inv(A). Third Edition Copyright © Orchard Publications .30) The matrices U . 3 −8 4]. This function returns the vector X that minimizes norm(A*X−b) subject to X ≥ 0 provided that the elements of A and b are real numbers. there is no vector X which can satisfy the entire system of equations. the MATLAB function inv(A) produces the inverse of the square matrix A and an error message is displayed if A is not a square matrix. In an overdetermined system. A=[2 −3 1. and unitary matrices U and V so that A = U⋅S⋅V T (14. can be found with the MATLAB function [U. MATLAB does this with either the left division operator ( \ ) or with the non−negative least−squares function lsqnonneg(A. 14. Of course. so we select the vector X which produces the minimum error. decomposed from a given matrix A .

8228 S = 11. U*U' ans = 1.0000 V*V' -0.4731 -0. S.0000 1. V]=svd(A) function.0000 -0.0000 -0.0000 1.0325 0 1.0000 -0.S.5028 0.0000 0.9463 -0.0000 -0.8929 As expected.8632 -0.1782 0 -0.0000 -0. A=[2 −3 1.5924 -0.3972 -0.0000 0.V]=svd(A) U = -0.5675 0 0 0.6521 0.3150 0.0000 1. We also verify that the matrices U and V are unitary as shown below.5184 0.4420 0.0000 0.0000 Numerical Analysis Using MATLAB® and Excel®.Singular Value Decomposition 2 –3 1 A = –1 5 –2 3 –8 4 into two unitary matrices and a diagonal matrix with non−negative elements.8050 -0.3116 0.2122 -0. −1 5 −2.0000 -0.0863 0.0000 1. the diagonal elements of the triangular S matrix are non−negative and in decreasing values.4605 0 0 V = -0.2440 0.0000 ans = 1. Third Edition Copyright © Orchard Publications 14−29 . Solution: We will use the MATLAB [U. 3 −8 4]. [U.0000 0.0000 -0.

• We can find an orthonormal set of eigenvectors in a 2 × 2 matrix easily from the eigenvalues but the computations for finding orthonormal sets of eigenvectors for larger size ( 3 × 3 or higher) matrices using the above procedure becomes quite involved. Third Edition Copyright © Orchard Publications .R]=qr(A) produces an n × n matrix whose columns form an orthonormal or unitary matrix Q and an upper triangular matrix R of the same size as matrix A . A unique 2 2 2 unit vector U is obtained by dividing each component of X by the magnitude X and this process is referred to as normalization.Chapter 14 Orthogonal Functions and Matrix Factorizations 14. A simpler procedure is the Gram−Schmidt orthogonalization procedure which we will discuss on the next section. is defined as X = x 1 + x 2 + … + x n .9 Summary • Orthogonal functions are those which are perpendicular to each other. • A matrix is said to be positive definite if x ⋅ A ⋅ x > 0 for every x ≠ 0 and A is symmetric. Under those conditions. • Two families of curves with the property that each member of either family cuts every member of the other family at right angles are said to be orthogonal trajectories of each other. If these vectors are also unit vectors.U]=lu(A) decomposes the matrix A into a lower triangular matrix L and an upper triangular matrix U . • The LU factorization method decomposes a matrix A into a lower triangular matrix L and an upper triangular matrix U so that A = L ⋅ U . that is. • The magnitude of a vector X . The MATLAB function [Q. there exists an upper triangular matrix G with positive diagonal elements such that G ⋅ G = A . the matrix A is said to be orthogonal and A ⋅ A = I where A is the transpose of A and I is the identity matrix. The MATLAB function [L. T T T T T 14−30 Numerical Analysis Using MATLAB® and Excel®. denoted as X . • If the column (or row) vectors of a square matrix A are mutually orthogonal unit vectors. • A basis that consists of mutually orthogonal vectors is referred to as an orthogonal basis. • The QR factorization decomposes a matrix A into the product of an orthonormal matrix and an upper triangular matrix. these vector are said to be orthogonal to each other. This process is referred to as the Cholesky factorization. A = A . the basis is called orthonormal basis. • The inner (dot) product of two vectors X = [ x 1 x 2 x 3 … x n ] and Y = [ y 1 y 2 y 3 … y n ] is a scalar defined as X ⋅ Y = x 1 y 1 + x 2 y 2 + x 3 y 3 + … + x n y n • If the dot product of two vectors X 1 and X 2 is zero.

V]=svd(A). Third Edition Copyright © Orchard Publications 14−31 . T Numerical Analysis Using MATLAB® and Excel®. decomposed from a given matrix A . The matrices U . and unitary matrices U and V so that A = U ⋅ S ⋅ V . S . of the same dimension as A and with nonnegative diagonal elements in decreasing order. S. can be found with the MATLAB function [U.Summary • The Singular Value Decomposition (SVD) method decomposes a matrix A into a diagonal matrix S . and V .

Verify your answers with MATLAB. 4.Chapter 14 Orthogonal Functions and Matrix Factorizations 14. Show that the curve x + 3y = k 1 and the curve 3y = k 2 x where k 1 and k 2 are constants. Use the appropriate MATLAB function to decompose the system of equations A = 1 0 –1 3 and b = 5 0 1 2 –2 –3 4 9 T into an upper triangular matrix R of the same dimension as A and a unitary matrix Q so that Q ⋅ R = A .8 to decompose the system of equations x 1 + 2x 2 + 3x 3 = 14 – 2x 1 + 3x 2 + 2x 3 = 10 5x 1 – 8 x 2 + 6x 3 = 7 T T 2 2 2 2 3 into an upper triangular matrix U and a lower triangular matrix L .k) to define and display the matrix A shown below. Use MATLAB to find another set of an orthonormal basis with the vectors given in Exercise 3. are orthogonal to each other.00 Then. 7. 5.10 Exercises 1. Find the orthogonal trajectories of the curves of the family 2x + y = kx 3. use the Gram−Schmidt orthogonalization procedure to find two vectors Y 1 and Y 2 to form an orthonormal basis. Third Edition Copyright © Orchard Publications . 4. 6.20 0 0 – 1.80 4.00 4.00 0 – 1.80 0 A = – 0. Use a suitable function to verify your results. 2.00 – 1. Using the MATLAB functions eye(n) and diag(v.00 – 0. 14−32 Numerical Analysis Using MATLAB® and Excel®. use the MATLAB Cholesky factorization function to obtain the matrix G and verify that G ⋅ G = A .00 0 0 – 1.20 4. Use the Gaussian elimination method as in Example 14. Given the vectors X 1 = [ 2 – 1 ] and X 2 = [ 1 – 3 ] .

Use the appropriate MATLAB function to decompose the matrix A given as A = 1 0 –1 0 1 2 –2 –3 4 into a diagonal matrix S of the same dimension as A and with non−negative diagonal elements in decreasing order and unitary matrices U and V so that U ⋅ S ⋅ V = A . Third Edition Copyright © Orchard Publications 14−33 .Exercises 8. T Numerical Analysis Using MATLAB® and Excel®.

2x + y = kx (1) 2 2 Implicit differentiation of (1) yields d d d ----.= k dx and solving for dy ⁄ dx .(2) dx 2y From (1).= – -. 2.(3) 3 y dx Differentiation of (2) yields dy = 3k 2 x . 3y k 2 = ----3 x and by substitution into (4) we obtain 3y dy = ----. dy k – 4x ----.( kx ) dx dx dx dy 4x + 2y ----.y 2 = ----.( 2x 2 ) + ----.⋅ -.⋅ x 2 = 3 y (5) -----3 x dx x We observe that (5) is the negative reciprocal of (3) and thus the given curves are orthogonal to each other.= k x 2 (4) ----------------2 dx 3 2 From (2). x + 3y = k 1 (1) 3y = k 2 x 3 2 2 (2) Implicit differentiation of (1) yields dy 2x + 6y ----.Chapter 14 Orthogonal Functions and Matrix Factorizations 14. 14−34 Numerical Analysis Using MATLAB® and Excel®.11 Solutions to End−of−Chapter Exercises 1.----.= 0 dx or 1 x dy .= -------------. Third Edition Copyright © Orchard Publications .

(3) x 2 2 and by substitution into (2) 2x + y ------------------.Solutions to End−of−Chapter Exercises 2x + y k = ------------------. we need to find the curves whose slopes are given by the negative reciprocal of (4).du 3 x u u and by integrating these terms we find –1 ln x + ln u = ----.(4) x – 2x + y ----dx 2y 2xy 2 2 Now.du = ---.+ ----. that is.(5) ----2 2 dx 2x – y We rewrite (5) as ( 2x – y )dy = 2xydx (6) 2 2 and we let y = ux .= -----------------.du – ----3 3 u x u u 2 2 3 or 2 dx du ----.= -----------------------. Then. we need to find the family of the curves of 2xy dy = ------------------.= ---.– 4x 2 2 dy = -------------------------------. Third Edition Copyright © Orchard Publications 14−35 .+ C 2 u By substitution of u = y ⁄ x we obtain Numerical Analysis Using MATLAB® and Excel®. dy = udx + xdu and by substitution into (6) ( 2x – u x ) ( udx + xdu ) = 2x udx 2 2 2 2 Division of both sides of the above by x yields ( 2 – u ) ( udx + xdu ) = 2udx 2 2 Collecting like terms and simplifying we obtain x ( 2 – u )du = u dx Separating the variables we obtain 2 (2 – u ) du dx ----.

5257 14−36 Numerical Analysis Using MATLAB® and Excel®. A=[2 −1.= [ – 1 ⁄ 5 Y2 – 1 ⁄ 5] T –2 ⁄ 5 ] T and denoting the matrix whose elements are the unit vectors as A .14) Y1 = X1 = [ 2 –1 ] T T T Y1 ⋅ X2 T [ 2 –1 ] ⋅ [ 1 –3 ] T Y 2 = X 2 – ----------------.Chapter 14 Orthogonal Functions and Matrix Factorizations 2 y ln x + ln y + ln C = ln ⎛ x ⋅ -.8507 0.= [ 2 ⁄ 5 Y1 Y2 U 2 = -------. we have: A = T 2⁄ 5 –1 ⁄ 5 –1 ⁄ 5 –2 ⁄ 5 We verify that A ⋅ A = I as shown below.⋅ [ 2 – 1 ] = [ 1 – 3 ] – -.8507 I=B*B' -0.⋅ C⎞ = ln Cy = – x -------⎝ x ⎠ 2 x y and thus the family of curves orthogonal to the given family is x = – y ln Cy 2 2 3.15) Y1 U 1 = -------. From (14. 1 −3]. Third Edition Copyright © Orchard Publications .⋅ Y 1 = [ 1 – 3 ] – -----------------------------------------------.5257 -0. B=orth(A) B = -0.⋅ [ 2 – 1 ] T T Y1 ⋅ Y1 [ 2 –1 ] ⋅ [ 2 –1 ] T [2 + 3] T T 5 T = [ 1 – 3 ] – ---------------. 2⁄ 5 –1 ⁄ 5 –1 ⁄ 5 ⋅ 2 ⁄ 5 –2 ⁄ 5 –1 ⁄ 5 –1 ⁄ 5 = –2 ⁄ 5 4⁄5+1⁄5 –2 ⁄ 5 + 2 ⁄ 5 –2 ⁄ 5 + 2 ⁄ 5 = 1 0 1⁄5+4⁄5 0 1 4.⋅ [ 2 – 1 ] = [4 + 1] 5 = [ 1 –3 ] – [ 2 –1 ] = [ –1 2 ] T T T and from (14.

5 .0000 1. These are the elements L 21 . we multiply the first equation by 5 and we subtract it from the third in (1). Then. the lower triangular matrix is 1 0 L = –2 1 5 – 18 ⁄ 7 0 0 1 The elements of the upper triangular matrix are the coefficients of the unknowns in (3) and thus U = 1 2 3 0 7 8 0 0 81 ⁄ 7 Numerical Analysis Using MATLAB® and Excel®.0000 -0. and – 18 ⁄ 7 . x 1 + 2x 2 + 3x 3 = 14 7x 2 + 8x 3 = 38 – 18 x 2 – 9 x 3 = – 63 (2) Next.0000 -0. 1. Then. x 3 = 243 ⁄ 81 = 3 x 2 = ( 38 – 8x 3 ) ⁄ 7 = 2 x 1 = ( 14 – 3x 3 – 2x 2 ) = 1 The multipliers that we’ve used are – 2 . Third Edition Copyright © Orchard Publications 14−37 . we multiply the second equation in (2) by – 18 ⁄ 7 and we subtract it from the third in (2). Likewise. Therefore. and L 32 respectively. L 31 .Solutions to End−of−Chapter Exercises I = 5.0000 x 1 + 2x 2 + 3x 3 = 14 – 2x 1 + 3x 2 + 2x 3 = 10 (1) 5x 1 – 8 x 2 + 6x 3 = 7 Multiplying the first equation of (1) by – 2 and subtracting it from the second in (1) we obtain the second equation in (2) and thus x 1 is eliminated. after simplification x 1 + 2x 2 + 3x 3 = 14 7x 2 + 8x 3 = 38 ( 81 ⁄ 7 )x 3 = 243 ⁄ 7 (3) Thus.

5 −18/7 1].00 -1.80 4.2673 14−38 Numerical Analysis Using MATLAB® and Excel®. A=[1 0 −1. −2 1 0. [Q.6733 0 4.2].20 4.20 0 0 -1.20 4. 2 3 -8 3 2 6 format bank.5976 0. we use MATLAB to verify that L ⋅ U = A L=[1 0 0. A1=G'*G A = 4. A=4*eye(4)+diag(B. 0 7 8.00 -0.00 -1.00 -1. 0 0 81/7]. QQT=Q*Q'.00 0 0 -0.4472 0 0. −1)+diag(B.8944 R = -2.00 -1.00 0 0 -1.00 0 0 0 A1 = 4.3586 0.0 −1.2361 0 0 -2.6833 -1.00 0 -0.80 0 0 7. 1). 0 1 2. U=[1 2 3.20 0 -0.5345 0.96 0 0 -0.80 4.0249 -0. −2 -3 4].62 1.80 0 0 G = 2.90 0 0 -1.7171 -0.4781 2.8018 0.8 −1.00 Q = -0. b=[3 5 9]'. A=L*U A = 1 -2 5 6.Chapter 14 Orthogonal Functions and Matrix Factorizations Now.1381 0.00 -0.R]=qr(A).51 1.40 1.00 4. Check=A\b -0.00 4. B=[−0. G=chol(A).93 0 0 -1. x=R\Q'*b. Third Edition Copyright © Orchard Publications .

A=[1 0 −1. UUT=U*U'.0000 0.5583 0.0000 1.V]=svd(A).3184 -0.0000 0.0413 0 0.2464 0.0000 Numerical Analysis Using MATLAB® and Excel®.0000 x = 6.9154 0.0000 1.5000 3.7500 8.0000 0.0000 U = -0.9556 -0.0000 -0.2410 0 2.0000 1.7500 -2.3795 -0.0000 0.1977 0.1574 0 0 0.2493 -0. 0 1 2.0000 -0.0000 -0.7500 -2.1345 0.0000 VVT = 1.0000 0.0000 0.5985 0 0 V = -0.8187 0.0000 -0.0000 0.0000 -0.9480 -0. Third Edition Copyright © Orchard Publications 14−39 .0000 0. [U.Solutions to End−of−Chapter Exercises QQT = 1.7000 -0.0000 0.2093 0.4779 0. −2 −3 4].7500 Check = 6.0000 1.0000 1.S.0000 0.0000 1.2076 0.9577 S = 5.5000 3.7922 UUT = 1. VVT=V*V' 0.0000 -0.0000 0.

under certain conditions. we replace n with – n .2) This series is referred to as Bessel function of order n where n is any positive real number or zero.2). acoustics. and the most common are the Method of Frobenius and the Method of Picard. they are used in frequency modulation. or even a complex number. thermodynamics. these are discussed in advanced mathematics textbooks. such as (15. Applying the method of Frobenius to (15. 15. denoted as J n ( x ) . and telephone equations. It is beyond the scope of this book to derive the infinite series which are approximations to the solutions of these differential equations. in the electrical engineering field. transmission lines. Legendre. and Chebyshev Functions T his chapter is an introduction to some very interesting functions. Therefore.⎞ ⎝2⎠ n + 2k 1 ⋅ --------------------------------------k! ⋅ Γ ( n + k + 1 ) n≥0 (15. Bessel functions are solutions of the differential equation x2 dy dx 2 2 +x dy 2 2 + ( x – n )y = 0 dx (15. cannot be solved in terms of familiar functions as those which we encountered in ordinary differential equations with constant coefficients. theory of elasticity and others. Differential equations with variable coefficients.1). fractional. are used in engineering.1) depends on the value of n . Third Edition Copyright © Orchard Publications 15−1 .1). If in (15.Chapter 15 Bessel. They are solutions of differential equations with variable coefficients and. satisfy the orthogonality principle. The usual procedure is to derive solutions in the form of infinite series. we obtain the relation Numerical Analysis Using MATLAB® and Excel®. positive or negative integer. we obtain the infinite power series Jn ( x ) = ∞ k=0 ∑ x k ( – 1 ) ⋅ ⎛ -. we will accept the solutions without proof. For instance.1 The Bessel Function The Bessel functions.1) where n can be any number. aeronautics. These are special functions that find wide applications in science and engineering. Then. the form of the general solution of (15.

– ----------------------. if we multiply the series for J 1 ( x ) by x and differentiate it.10) Also.– --------------------.⎞ ⎝2⎠ k! ⋅ ( n + k )! n = 0. Γ ( n + k + 1 ) = ( n + k )! (15.+ ----------------------. we will find that 15−2 Numerical Analysis Using MATLAB® and Excel®.5) n 2 4 x ⎧ x x J n ( x ) = -------------. and Chebyshev Functions J–n ( x ) = k=0 ∑ ( –1 ) ∞ k x – n + 2k 1 ⋅ ⎛ -. 2. and compare with the series of J 1 ( x ) in (15.6) reduces to the following series: x x x x J 0 ( x ) = 1 – --------------------.– … 2 4 6 8 10 2 ⋅ 2! 2 ⋅ 1! ⋅ 3! 2 ⋅ 2! ⋅ 4! 2 ⋅ 3! ⋅ 5! 2 ⋅ 4! ⋅ 6! 2 4 6 8 10 3 5 7 9 2 4 6 8 (15. J n ( x ) is an even function of x . Third Edition Copyright © Orchard Publications . 1 and 2 .⎞ ⋅ ------------------------------------------⎝2⎠ k! ⋅ Γ ( – n + k + 1 ) (15.8).7) (15. and odd when n is odd. Legendre.7).8) (15.+ ----------------------. 1.⎨ 1 – ----------------------------------.9) We observe from (15. (15.7) through (15.+ ------------------------. If we differentiate the series of J 0 ( x ) in (15.+ … ⎬ 6 ⎭ 2 ⋅ 3! ⋅ ( n + 1 ) ( n + 2 ) ( n + 3 ) (15.+ --------------------.3) and the function J –n ( x ) is referred to as the Bessel function of negative order n .– ----------------------.+ ----------------------.– … 2 2 4 2 6 2 8 2 2 ⋅ ( 1! ) 2 ⋅ ( 2! ) 2 ⋅ ( 3! ) 2 ⋅ ( 4! ) x x x x x J 1 ( x ) = -.+ --------------------. that when n is zero or even. For the special case where n is a positive integer or zero. … (15.6) For n = 0.+ ----------------------------------------------------n 2 4 2 ⋅ n! ⎩ 2 ⋅ 1! ⋅ ( n + 1 ) 2 ⋅ 2! ⋅ ( n + 1 ) ( n + 2 ) 6 ⎫ x – ----------------------------------------------------------------------.9).– ----------------------.Chapter 15 Bessel.2) reduces to Jn ( x ) = or k=0 ∑ ∞ x n + 2k 1 k ⋅ --------------------------( – 1 ) ⋅ ⎛ -. we see that d J ( x ) = –J1 ( x ) dx 0 (15.– … 3 5 7 9 2 2 ⋅ 1! ⋅ 2! 2 ⋅ 2! ⋅ 3! 2 ⋅ 3! ⋅ 4! 2 ⋅ 4! ⋅ 5! x x x x x J 2 ( x ) = -------------.– ----------------------.4) and (15.

J 2 ( 1 ) = 0.11) Example 15. J 1 ( 3 ) = 0.The Bessel Function d { xJ 1 ( x ) } = xJ 0 ( x ) dx (15. Third Edition Copyright © Orchard Publications 15−3 .9).2).+ ----------------------. besselj(2.2239 ans = 0. the values of a.2239 b. From (15.n) function for the above computations.1149 Numerical Analysis Using MATLAB® and Excel®.+ -------. With MATLAB.3391 c. correct to four decimal places. 19683 -.= 1 – ----.= -------. 1 1 1 1 1 J 2 ( 1 ) = -.7).1 Compute.3).2187J 1 ( 3 ) = 3 – 27 + 243 – -------------. J 0 ( 2 ) b. 431256 64 -.= 0.-------.= 0.+ ----------------------.= 0. J 1 ( 3 ) c.– ----------------.+ -------------------.----. we obtain besselj(0.– ----. From (15. J 0 ( 2 ) = 0. J 2 ( 1 ) Solution: a.1-.1) ans = 0.1152 8 96 1536 184320 17694720 or from math tables.2240 192 4 36 576 4 64 64 × 36 256 × 576 or from math tables.----J 0 ( 2 ) = 1 – 4 + 16 – ----------------.x) function or the Excel BESSELJ(x.+ ----------. besselj(1.3391 ans = 0.1149 . From (15.3400 2 16 384 18432 1474560 or from math tables.8). We can use the MATLAB besselj(n.

x = 0. all J n ( x ) are infinite series and thus. 0. w = besselj(1. The x −axis crossings in the plot of Figures 15.x). xlabel('x').z).5 J2(x) Jn(x) 0 -0. Legendre. first sideband. J 1 ( x ) .x. Plots of J 0 ( x ) .2. Third Edition Copyright © Orchard Publications . respectively. it is a very difficult and tedious task to compute all roots of these series.85. x is denoted as β and it is called modulation index. ylabel('Jn(x)').1 and 15. Fortunately. text(0. J 2 ( β ) and so on.v. 15−4 Numerical Analysis Using MATLAB® and Excel®.00: 0.x). J 1 ( x ) and J 2 ( x ) are shown in Figure 15.* 1 J0(x) Bessel Functions of the First Kind J1(x) 0.20.2)= 0.1)= 0.1. 'J1(x)'). tables of some of the roots of J 0 ( x ) and J 1 ( x ) are shown in math tables. besselj(2.35. and J 2 ( x ) series.05: 10.2239 besselj(3.3391 besselj(1. grid. J 1 ( x ) and J 2 ( x ) using MATLAB We can also use Excel to plot these series as shown in Figure 15. J 1 ( x ) .1149 The MATLAB script below plots J 0 ( x ) . text(4. J 1 ( β ) .25. 0. 'J2(x)') The plots for J 0 ( x ) . 0. second sideband etc.Chapter 15 Bessel. However.2 show the first few roots of the J 0 ( x ) . title('Bessel Functions of the First Kind'). 'J0(x)').x).1. represent the carrier.00.5 0 1 2 3 4 5 x 6 7 8 9 10 Figure 15.60.w.95. text(2. * In Frequency Modulation (FM). plot(x. and Chebyshev Functions and with Excel.x. and J 2 ( x ) . The definition of a Bessel function of the first kind will be explained shortly.0)= 0. v = besselj(0. z = besselj(2. The functions J 0 ( β ) .

0000 0.10 0.0748 0.8971 0.9975 0.0112 0.60 0.2194 0.0000 0.3081 0.25 0.3290 0.0306 0.00 0.sin x πx (15. 1 and 2 x 0.75 J0(x) 1.0050 0.2).8812 0.5 Jn(x) J2(x) 0.55 0. the so−called half−order Bessel functions J 1 ⁄ 2 ( x ) and J ( – 1 ⁄ 2 ) ( x ) .45 0.0499 0. The most noteworthy are: 1.9120 0. we observe that the first root 3.0510 0.0012 0. and so on.0250 0.20 0. J 1 ( x ) and J 2 ( x ) using Excel The equations J 0 ( x ) = 0 and J 1 ( x ) = 0 exhibit some interesting characteristics.50 0. As the roots become larger and larger.65 0.0003 0.0369 0. If n is half of an odd integer.9994 0. If we let n = 1 ⁄ 2 in (15. the roots of these equations separate each other.8642 J1(x) 0.12) Numerical Analysis Using MATLAB® and Excel®.9604 0. In other words.0028 0.0197 0.2423 0.The Bessel Function Plot of Bessel Function Jn(x) for n = 0. are almost periodic with period almost 2π . Between two consecutive roots of one of these equations lies one and only one root of the other equation.8317 of J 1 ( x ) lies between the roots 2.5201 of J 0 ( x ) . that is. This is observed on Table 15.35 0. Third Edition Copyright © Orchard Publications 15−5 .9385 0.2867 0.9844 0. They have no complex roots 2.1240 0.3492 J2(x) 0.0437 0. that is. 5 ⁄ 2 . Each has an infinite number of distinct real roots 3.9696 0.0 -0. such as 1 ⁄ 2 . J 0 ( x ) and J 1 ( x ) .70 0.4048 and 5.0 J0(x) J1(x) 0.0995 0. For instance. 4.9900 0.9944 0. the difference between consecutive roots approaches the value of π.0078 0. Consider.1723 0.9776 0. Plots of J 0 ( x ) .2.1 which shows the first 5 positive roots of these equations. these series behave like the cos x and sin x functions.0000 0.0671 Bessel Functions of the First Kind 1. 3 ⁄ 2 . we obtain J1 ⁄ 2 ( x ) = 2----.15 0.0249 0.40 0. and the differences between consecutive roots.1960 0.9258 0. then J n ( x ) can be expressed in a finite form of sines and cosines.0152 0.0588 0.30 0.9500 0.1483 0.05 0. for example.5 0 2 4 x 6 8 10 Figure 15.2647 0.

1502 7. besselj(−0.1839 Differences … … … … Likewise.8 ⋅ -----. the values of a.8317 3.= 0. J 1 ⁄ 2 ⎛ -. π J ( – 1 ⁄ 2 ) ⎛ -.4048 3. Third Edition Copyright © Orchard Publications .sin ( π ⁄ 4 ) = -.Chapter 15 Bessel.⎞ = ⎝4⎠ 2 1 2 42 ----------------. Legendre.= ----. π J 1 ⁄ 2 ⎛ -.2 Compute.1394 14.5.13) Example 15.1 The first few roots of J 0 ( x ) and J 1 ( x ) J0 ( x ) = 0 Roots 2.3237 3.6537 3. Using (15. if we let n = 1 ⁄ 2 in (15.13).1153 5. we obtain J( –1 ⁄ 2 ) ( x ) = 2 ----.6366 2 π π 2π π(π ⁄ 4) b.1469 10. and Chebyshev Functions TABLE 15.5201 3. J ( –1 ⁄ 2 ) ⎛ -.8 ⋅ -----.7915 3. Using (15.pi/4) 15−6 Numerical Analysis Using MATLAB® and Excel®.1378 11.1579 J1 ( x ) = 0 Differences Roots 3.3).= 0.cos x πx (15.pi/4).⎞ ⎝ ⎠ π 4 b.4706 13.0156 3.cos ( π ⁄ 4 ) = -.1735 3.= -.⎞ = ⎝4⎠ 2 1 2 2 -----------------.12). correct to four decimal places.⎞ ⎝ ⎠ π 4 Solution: a.6366 2 π π π(π ⁄ 4) Check with MATLAB: besselj(0.5.= -.1336 8.9309 16.

that the numbers n = 0. ….= ( – 1 ) n J n ( x ) Γ ( n + m + 1 )! ⋅ m! m and thus (15. the first summation in the above relation is zero for k = 0. – 2. n – 1 .6366 ans = 0. if we let k = n + m in the second summation.+ k! ⋅ Γ ( – n + k + 1 ) – n + 2k k=n ∑ ∞ ( –1 ) ⋅ ( x ⁄ 2 ) -----------------------------------------------k! ⋅ Γ ( – n + k + 1 ) k – n + 2k (15. are referred to as Bessel functions of the first kind.14) has been proved. 3.3). we will prove that J–n ( x ) = ( – 1 ) Jn ( x ) for n = 1. As mentioned earlier. we recall from Chapter 13. J –n ( x ) = = k=0 n–1 k=0 ∑ ∑ ∞ ( –1 ) ⋅ ( x ⁄ 2 ) -----------------------------------------------k! ⋅ Γ ( – n + k + 1 ) k k – n + 2k ( –1 ) ⋅ ( x ⁄ 2 ) -----------------------------------------------. 2. denoted as Y n ( x ) and referred to as Bessel functions of the second kind.The Bessel Function ans = 0.2). These are additional solutions of the Bessel’s equation. or Hankel functions. – 1.14) Proof: From (15. … yield infinite values in Γ ( n ) .5). Third Edition Copyright © Orchard Publications 15−7 . Numerical Analysis Using MATLAB® and Excel®. If n is an integer. after simplification and comparison with (15. and thus their solutions are called Modified Bessel functions. Also. certain differential equations resemble the Bessel equation. can be obtained by replacing n with – n in (15. … n (15. we see that m=0 ∑ ∞ ⋅ (x ⁄ 2 ) ( –1 ) ------------------------------------------------------------------( n + m )! ⋅ Γ ( m + 1 ) = ( –1 ) n n+m – n + 2n + 2m m=0 ∑ ∞ ⎛x⎞ -⎝2⎠ n + 2m ( –1 ) -------------------------------------------. a Bessel function J –n ( x ) for n > 0 . or Neumann functions. Other Bessel functions.15) Now. 2. or Weber functions. 1. then. and will be explained in the next paragraph. Also.6366 The Bessel functions which we have discussed thus far.

y represents the general solution of (15. 3.19) can be written as sin x cos x y = C 1 ---------. Legendre.sin x + B ----. for this case.17) is y = AJ 1 ⁄ 2 ( x ) + BJ –1 ⁄ 2 ( x ) (15. … and so on.17) We will show that the general solution of (15. … (15.16) is the general solution.16) is not the general solution.19) and letting C 1 = A 2 ⁄ π and C 2 = B 2 ⁄ π . for this case.y = 0 dx ⎝ 4⎠ (15. that is. therefore.20) are linearly independent.12) and (15. (15.13) into (15. 1. relation (15.14).+ C 2 ----------x x (15.17).3 Find the general solution of Bessel’s equation of order 1 ⁄ 2 . (15.cos x πx πx (15. Third Edition Copyright © Orchard Publications .20) Since the two terms on the right side of (15.Chapter 15 Bessel. and Chebyshev Functions It is shown in advanced mathematics textbooks that. and for this reason. if n is not an integer. we obtain 2 2 y = A ----. 2. these two series produce only one solution. the functions J n ( x ) and J –n ( x ) are not linearly independent as we have seen in (15.18). Example 15. we obtain x 2 dy dx 2 2 +x dy ⎛ 2 1 ⎞ + x – -. the general solution of the Bessel equation is y = AJ n ( x ) + BJ – n ( x ) n ≠ 0. the Bessel functions of the second kind are introduced to obtain the general solution.16) For n = 1.1). J n ( x ) and J –n ( x ) are linearly independent. 15−8 Numerical Analysis Using MATLAB® and Excel®. 3.18) By substitution of (15. Solution: By the substitution n = 1 ⁄ 2 in (15. The following example illustrates the fact that when n is not an integer or zero. 2.

24) ∑1 J2k – 1 ( x ) sin ( 2k – 1 ) φ k= where the subscript 2k denotes that the first relation is valid for even values of k . One very important property of the Bessel’s functions is that within certain limits.The Bessel Function The Bessel functions of the second kind. More detailed discussion and proofs can be found in advanced mathematics textbooks. The function e x⎛ -. indicates that the second relation is valid for odd values of k . They are also orthog- = ∑ Jn ( x )t n = –∞ ∞ n (15.* For instance.25) * Two functions constitute an orthogonal system. Third Edition Copyright © Orchard Publications 15−9 . Numerical Analysis Using MATLAB® and Excel®. Using this function. The descriptions. J 0 ( a ) = 0 and J 0 ( b ) = 0 . then. whereas 2k – 1 in the second.21) and we say that J 0 ( ax ) and J 0 ( bx ) are orthogonal in the interval 0 ≤ x ≤ 1 . syntax. when the average of their cross product is zero within some specified limits. ∑ Jn ( x ) n = –∞ 2 ∞ = 1 ∞ (15. and help for Excel. and examples for each can be found by invoking help bessel for MATLAB. and others. ∫0 xJ0 ( ax )J0 ( bx ) dx onal with the variable x . we can obtain several interesting properties for integer values of n .t – 1 ⎞ -2⎝ t⎠ 1 = 0 (15.22) is referred to as the generating function for Bessel functions of the first kind of integer order. Some of these are given below without proof. if a and b are distinct roots of J 0 ( x ) = 0 . Also. can be evaluated at specified values either with MATLAB or Excel. ∫0 π ⎧ πJ n ( x ) n = even cos nφ ⋅ cos ( x sin φ ) dφ = ⎨ n = odd ⎩ 0 n = even ⎧0 sin n φ ⋅ sin ( x sin φ ) dφ = ⎨ ⎩ πJ n ( x ) n = odd ∫0 π (15.23) cos ( x sin φ ) = J 0 ( x ) + 2 sin ( x sin φ ) = 2 ∞ k=1 ∑ J2k ( x ) cos 2kφ (15. they constitute an orthogonal system. third kind.

the general solution of (15.x + -----------------------------------------------------.27) has polynomial solutions of special interest.2 Legendre Functions Another second−order differential equation with variable coefficients is the equation dy 2 d y ( 1 – x ) --------.27) known as Legendre’s equation.x – … 3! 5! (15. as in the Bessel equation. then (15.23) through (15. and Chebyshev Functions and 1 J n ( x ) = -π π ∫0 cos ( nφ – x sin φ ) dφ ∑ Jn ( β ) n = –∞ 2 ∞ (15. and if it is zero or a positive integer.x – … 3! 5! (15. it reduces to 1 2 P ave = -.26) appear in frequency modulation.– 2x ----.23).x – … 2! 4! (n – 1)(n + 2) 3 (n – 3)(n – 1)(n + 2)(n + 4) 5 + a 1 x – --------------------------------. n is a constant.x + -------------------------------------------------------------------.x + -----------------------------------------------------. the average power is shown to be 1 2 P ave = -.A C 2 15.29) where a 0 and a 1 are constants. Third Edition Copyright © Orchard Publications . Legendre. Applying the method of Frobenius. n ( n + 1 ) 2 ( n – 2 )n ( n + 1 ) ( n + 3 .26) Relations (15.30) and this series is absolutely convergent* for x > 1 .4 ) y 1 = a 0 1 – ------------------. we obtain two independent solutions y 1 and y 2 as follows. Then. We observe that y 1 is an even function of x . For example. while y 2 is an odd function. 15−10 Numerical Analysis Using MATLAB® and Excel®.28) (15.4 ) y = a 0 1 – ------------------.+ n ( n + 1 )y = 0 2 dx dx 2 (15. Here.A C 2 and with (15.27) is y = y 1 + y 2 or n ( n + 1 ) 2 ( n – 2 )n ( n + 1 ) ( n + 3 .x + -------------------------------------------------------------------.x – … 2! 4! ( n – 1 )( n + 2) 3 ( n – 3)( n – 1)( n + 2)( n + 4 ) 5 y 2 = a 1 x – --------------------------------.Chapter 15 Bessel.

x + … 3! 2 ⋅ 4 ⋅ 6 ⋅ … ⋅ (n – 1) for n = odd integer (15. or an even positive integer.e. whenever n is zero or a positive integer. the first term on the right side of (15.1 – ------------------.x + … 2! 2⋅4⋅6⋅…⋅n (15.Legendre Functions The parameter n is usually a positive integer.31) and (15. The even and odd functions of (15. i. The infinite series solution Q n ( x ) is referred to as Legendre functions of the second kind.for n = even and N = ---------------. If n is zero. they will not be discussed in this text.31) and (15.32) and these are also referred to as surface zonal harmonics. or (15. we obtain the following first 6 Legendre polynomials. Therefore. ∑ un ( x0 ) n=1 ∞ = u 1 ( x 0 ) + u 2 ( x 0 ) + … also Numerical Analysis Using MATLAB® and Excel®. if it is odd.x n – 2k n 2 k! ( n – k )! ( n – 2k )! k (n – 1) n where N = -.32).31) for n = 0 or n = even integer Pn ( x ) = ( –1 ) (n – 1) ⁄ 2 (n – 1)(n + 2) 3 1⋅3⋅5⋅…⋅n ⋅ ------------------------------------------------. These become infinite as x → ± 1 and their applications to science and engineering problems are very limited. the general solution of Legendre’s equation contains a polynomial solution which is denoted as P n ( x ) . and an infinite series solution which is denoted as Q n ( x ) .32) can be combined to a single relation as Pn ( x ) = k=0 ∑ N ( – 1 ) ⋅ ( 2n – 2k )! --------------------------------------------------. reaches a limit.2 ) 1 ⋅ 3 ⋅ 5 ⋅ … ⋅ (n – 1) ⋅ ------------------------------------------------. Accordingly. we find that the resulting series converges. If.for n = odd 2 2 (15. the second term contains only a finite number of terms.. when we replace the terms of this series by their absolute value.x – --------------------------------. Third Edition Copyright © Orchard Publications 15−11 . * Assume that the infinite series ∑ un ( x0 ) n=1 ∞ = u 1 ( x 0 ) + u 2 ( x 0 ) + … converges. The Legendre polynomials are defined as Pn ( x ) = ( –1 ) n⁄2 n(n + 1. this series is said to be absolutely convergent.33) From (15.33).30) contains only a finite number of terms.

15−12 Numerical Analysis Using MATLAB® and Excel®.( 3x – 1 ) 2 1 4 2 P 4 ( x ) = -. and the angle which point P makes with the center of the dipole. We prove (15.37) Now. usually fed from the center. (x – 1) = 2 n k=0 n ∑ ( – 1 ) ⋅ n! --------------------------.2 P n ( x ) = -------------.36) with respect to x n times yields n d ------.33).( x – 1 ) n n 2 ⋅ n! dx (15. Another important identity involving Legendre polynomials.x 2n – 2k k! ⋅ ( n – k )! k (15. we recognize (15. Example 15. is the generating function for Legendre polynomials which is defined as 2 n 1 ------------------------------.36) and differentiation of (15.⋅ -------. of equal magnitude but of opposite sign or polarity.35) is known as Rodrigues’ formula. and Chebyshev Functions P0 ( x ) = 1 1 2 P 2 ( x ) = -.= P 0 ( x ) + P 1 ( x )t + P 2 ( x )t + … + P n ( x )t = 2 1 – 2xt + t ∑ Pn ( x )t n=0 ∞ n (15.35) is proved. separated by a small distance.38) We will illustrate the use of the Legendre polynomials with the following example. and offers another method of expressing the Legendre polynomials.37) as 2 ⋅ n! ⋅ P n ( x ) and thus (15.4 Find the potential difference (voltage) v at a point P developed by a nearby dipole* in terms of the distance between the point P and the dipole. a dipole is an antenna.( 35x – 30x + 3 ) 8 P1 ( x ) = x 1 3 P 3 ( x ) = -.35) as follows. Alternately. From the binomial theorem.( x 2 – 1 ) = n dx n k=0 ∑ N ( – 1 ) ⋅ n! ( 2n – 2k )! ----------------------. * A dipole is a pair of electric charges or magnetic poles. Third Edition Copyright © Orchard Publications .x n – 2k k! ( n – k )! ( n – 2k )! n k (15. by comparison with (15. consisting of two equal rods extending outward in a straight line.⋅ -----------------------.( 63x – 70x + 15x ) 8 (15. Legendre.( 5x – 3x ) 2 1 5 3 P 5 ( x ) = -.Chapter 15 Bessel.34) The relation n n 1 d .

= r d 2d cos θ ----. r1 = d + r – 2 dr cos ( 180° – θ ) = r2 = 2 2 2 2 d + r + 2dr cos θ 2 2 (15.4πε 0 ⎝ r 2 r 1 ⎠ (15. Numerical Analysis Using MATLAB® and Excel®. For simplicity.⎞ .⎞ = kq ( r 2 – r 1 ) . Third Edition Copyright © Orchard Publications 15−13 .40) Next.39) as –1 –1 1 1 V P = kq ⎛ --.– --. Figure for Example 15.42) and d + r – 2 dr cos θ Dividing both sides of (15.⎛ --.42) by r . By the law of cosines.– --.3.43) or * Permittivity is a measure of the ability of a material to resist the formation of an electric field within it.1 1 V P = ----------. we need to express r 1 and r 2 in terms or d and r.Legendre Functions Solution: Let the charges q and – q of the dipole be a distance 2d apart with the origin 0 as the midpoint as shown in Figure 15. we obtain r2 --.⎝r r ⎠ 2 1 (15. P r1 r θ −q d 0 d q r2 Figure 15.39) where ε 0 is the permittivity* of the vacuum. From electromagnetic field textbooks we find that q . we will denote the quantity 1 ⁄ ( 4πε 0 ) as k and thus we rewrite (15.41) (15.3.4 Let the potential at point P be V P .+ 1 – -----------------2 r r 2 (15.

This requirement is satisfied since x and y. P n ( – cos θ ) = P n ( cos θ ) .⎜ ----.48) However.⎞ = -----------.48) are duplicated. we want to relate the terms inside the parentheses of (15. Now.44) we obtain ⎛ d2 2d cos θ⎞ ⎜ ----.49) and for r » d . if n is even in (15. we obtain kq V P = ----r ∑ [ Pn ( x ) y n=0 ∞ – P n ( – x )y ] (15.49) can be approximated as d 2kdq 2kq V P ≈ -------. Legendre.⎞ ⎝r ⎠ (15.48).⎟ 2 r ⎠ ⎝ r –1 ⁄ 2 = ( 1 – 2xy + y ) 2 –1 ⁄ 2 = ∑ Pn ( x )y n=0 ∞ n (15. P n ( – cos θ ) = – P n ( cos θ ) and the odd powers in (15.⎞ ⎝r ⎠ (15. we assume that r > d .45) We recall that (15.Chapter 15 Bessel.+ 1 – ----------------. kq V P = ----r ∞ n=0 ∑ d 2n + 1 2P 2n + 1 ( cos θ ) ⎛ -.45) holds only if x < 1 and y < 1 .44) In all practical applications. by substitution into (15. But when n is odd.⎟ r ⎝ r2 r ⎠ –1 ⁄ 2 (15. (15. the point P is sufficiently far from the origin. then. and thus ( 1 + 2xy + y ) 2 –1 ⁄ 2 –1 = ∑ Pn ( –x )y n=0 n n ∞ n (15. and y = d ⁄ r . To find a similar expression for r 1 . we can express (15.45) and (15. all even powers vanish. thus. Third Edition Copyright © Orchard Publications .45). and Chebyshev Functions 1⎛ d 2 –1 2d cos θ⎞ r 2 = -. We let x = cos θ .47) Since x = cos θ .+ 1 – ----------------.46) By substitution of (15.P 1 ( cos θ ) ⎛ -. We do this by expressing these terms in the form of the generating function of (15. as defined.38). Then. and y = d ⁄ r . and therefore.50) 15−14 Numerical Analysis Using MATLAB® and Excel®.46) into (15.47) as kq V P = ----r ∑ n=0 ∞ d n [ P n ( cos θ ) – P n ( – cos θ ) ] ⎛ -.40).44). are both less than unity.cos θ * 2 ⎝r ⎠ r r (15. to a Legendre polynomial. we simply replace x with – x in (15.

40) we obtain kq 2kqd 1 1 V P = kq ⎛ --. the negative and positive charges look like a single point charge.51) The relation of (15. Derivation of the voltage developed by a dipole Another interesting relation that can be used to find the Legendre polynomial series of a function f ( x ) for x < 1 . r.⎞ = -----------. and r 2 can be approximated by parallel lines as shown in Figure 15. the distances r 1 .– --. is 2n + 1 B n = -------------2 ∫–1 f ( x )Pn ( x ) dx 1 (15. of course. This will be seen shortly in (15.52) We observe that (15. Third Edition Copyright © Orchard Publications 15−15 . and using (15.50) can.cos θ . P r1 × r2 = r 2 r2 r 2 – r 1 = 2d cos θ r r1 θ θ −q d 0 d q Figure 15.4.52) is the same as (15. It is denoted with the letter p . we have used the identity P1 ( cos θ ) form of the Legendre polynomials.Legendre Functions The term 2dq is the magnitude of the so−called dipole moment.50). be derived without the use of Legendre polynomials as follows: For r » d . that is. p = 2qd (15. It is a vector directed from the negative charge towards the positive charge.57) when we discuss the trigonometric Numerical Analysis Using MATLAB® and Excel®.53) * Here.2 ⎝r r ⎠ r1 ⋅ r2 r 2 1 (15.( r 2 – r 1 ) = -----------. = cos θ .4. Then.

Waveform for Example 15.34) for the polynomials of P n ( x ) .+ -.x 4 1 3 2 + -.x –1 4 1 2 3 3 3 = -.x 2 1 0 = –1+1 = 0 -. then.-.( 5x – 3x ) dx + -2 2 –1 0 ∫0 1 ⋅ -.5. a function f ( x ) can be expanded as f ( x ) = B0 P0 ( x ) + B1 P1 ( x ) + B2 P2 ( x ) + … + Bn Pn ( x ) = ∑0 Bn Pn ( x ) n= ∞ (15.Chapter 15 Bessel.= -.5 Solution: We will first compute the coefficients B n from (15.x 2 0 –1 0 1 + -.2 2 1 0 3 ( – 1 ) ⋅ x ⋅ dx + -2 –1 3 2 1 ⋅ x ⋅ dx = – -.( 5x 2 1 1 3 -– 3x ) dx = – 7 8 4 ∫ 1 9 4 2 ( – 1 ) ⋅ -.( 35x – 30x + 3 ) dx + -8 2 –1 0 ∫0 1 ⋅ -.54) The example below illustrates how this relation is being used.( 3x 2 1 – 1 ) dx = 0 ∫ 1 7 3 ( – 1 ) ⋅ -. Legendre.5 Compute the Legendre polynomial series representing the waveform of Figure 15. Third Edition Copyright © Orchard Publications . we will substitute these into (15. Example 15.54).( 35x 8 1 – 30x + 3 ) = 0 2 15−16 Numerical Analysis Using MATLAB® and Excel®.( 3x – 1 ) dx + -2 2 –1 0 ∫0 1 ⋅ -. f (x) 1 −1 0 −1 1 x Figure 15. For this example. We will also use (15. and Chebyshev Functions Then.5.4 4 2 5 B 2 = -2 7 B 3 = -2 9 B 4 = -2 ∫ 1 5 2 ( – 1 ) ⋅ -. 1 B 0 = -2 3 B 1 = -2 ∫ ∫ 1 ( – 1 ) ⋅ 1 ⋅ dx + -2 –1 0 0 ∫0 1 ⋅ 1 ⋅ d x ∫0 1 1 1 = – -.53).

56) we obtain the first 6 Legendre polynomials in trigonometric form listed below.⋅ -------------------------------------------.55) We observe that the waveform of f ( x ) is an odd function and. as we found above.⋅ -.2 cos n θ + -. the algebraic form of the Legendre polynomials is usually the most useful. Also.x – ----.( 5x – 3x ) + ----.⋅ -------------------------------------------.( 5x – 3x ) + -------. Third Edition Copyright © Orchard Publications 15−17 . In many applications.54) and (15.( 63x 8 1 1 5 3 ----– 70x + 15x ) = 11 16 and so on. satisfy the orthogonality principle when m ≠ n as indicated by the following integral.2 cos ( n – 2 ) θ 2 ⋅ 4 ⋅ … ⋅ 2n 2 2 ⋅ 4 ⋅ … ⋅ ( 2n – 2 ) 1 ⋅ 3 1 ⋅ 3 ⋅ … ⋅ ( 2n – 5 ) + --------.57) The Legendre polynomials in algebraic form.( 63x 5 – 70x 3 + 15x ) dx + ----8 2 –1 0 ∫0 -.= -.56) From (15.P 5 ( x ) 2 8 16 7 1 11 1 3 3 5 3 . Numerical Analysis Using MATLAB® and Excel®. P 0 cos θ = 1 P 1 cos θ = cos θ 3 cos 2 θ + 1 P 2 cos θ = --------------------------4 5 cos 3 θ + 3 cos θ P 3 cos θ = --------------------------------------8 35 cos 4 θ + 20 cos 2 θ + 9 P 4 cos θ = ---------------------------------------------------------64 ------------------------------------------------------------------------P 5 cos θ = 63 cos 5 θ + 35 cos 3 θ + 30 cos θ 128 (15.4. as we did in Example 15.⋅ ( 63x – 70x + 15x ) 16 128 2 525 3 693 5 525 = -------.x 64 128 128 (15.P 3 ( x ) + ----.Legendre Functions – 11 B 5 = -------2 ∫ 1 11 -.x – -------. its expansion contains only odd Legendre polynomials. using (15. there are times when we want to express the polynomials in terms trigonometric functions.x + -------.( 63x – 70x + 15x ) 8 2 16 8 2 7113 3 5 3 = -. It is shown in advanced mathematics textbooks that 1 ⋅ 3 ⋅ … ⋅ ( 2n – 1 ) 1 1 ⋅ 3 ⋅ … ⋅ ( 2n – 3 ) P n cos θ = -------------------------------------------.x – -. However. the trigonometric forms are most convenient with the cylindrical and spherical coordinate systems.⋅ -..P 1 ( x ) – -.2 cos ( n – 4 ) θ + … 2 ⋅ 4 2 ⋅ 4 ⋅ … ⋅ ( 2n – 4 ) (15.34) we obtain 3 7 11 f ( x ) = -. Therefore.

and math tables include values of these as computed from Rodrigues’ formula of (15.60) is y = C1 Pn ( x ) + C2 Qn ( x ) m m m m (15. There is another class of Legendre functions which are solutions of the differential equation 2 dy 2 d y m ( 1 – x ) --------. and Chebyshev Functions ⎧ 0 ⎪ P m ( x )P n ( x ) dx = ⎨ 2 –1 ⎪ -------------⎩ 2n + 1 1 ∫ m≠n m = n (15.61) where C 1 and C 2 are arbitrary constants.+ n ( n + 1 ) – ------------.58) Similarly. The functions P n ( x ) and Q n ( x ) are referred to as associated Legendre functions of the first and second kind respectively. Legendre. We will restrict our subsequent discussion to the associated Legendre functions of the first kind. that is. The general solution of (15.P n ( x ) m dx d ⋅ --------. We observe that if m = 0 .35). (15.63) are also known as spherical harmonics.27).60) reduces to (15. the Legendre polynomials in trigonometric form satisfy the orthogonality principle when m ≠ n as indicated by the following integral. These are evaluated from Pn ( x ) = ( –1 ) ( 1 – x ) m m 2 m⁄2 d ⋅ --------.60) and this is referred to as the associated Legendre differential equation.Chapter 15 Bessel. m 15−18 Numerical Analysis Using MATLAB® and Excel®.Q n ( x ) m dx m m (15.59) We must remember that all the Legendre polynomials we have discussed thus far are referred to as surface zonal harmonics. ∫0 π ⎧ 0 ⎪ P m ( cos θ )P n ( cos θ ) sin θ dθ = ⎨ 2 ⎪ -------------⎩ 2n + 1 m≠n m = n (15.– 2x ----.62) and Qn ( x ) = ( –1 ) ( 1 – x ) m m 2 m⁄2 (15.63) Relations (15. the polynomials P n ( x ) .62) and (15.y = 0 2 2 dx dx 1–x 2 (15. Third Edition Copyright © Orchard Publications .

P 2 ( x ) x = 0.5 2 1⁄2 d. Pn ( x ) = ( –1 ) ( 1 – x ) m m 2 m⁄2 1 x = 0.x) function computes the associated Legendre functions of the first kind of degree n and order m = 0.-------------------. m = 1 and m = 2 are:'). second. n = 2 and thus MATLAB will return a matrix whose rows correspond to the values of m = 0 . MATLAB provides the legendre(n. and m = 2 .⎛ 3x – 1⎞ dx ⎝ 2 ⎠ 2 x = 0. we obtain P2 ( x ) 1 x = 0. 1.6 Find the following associated Legendre functions and evaluate as indicated. legendre(2.P n ( x ) m dx m and the appropriate relations of (15.5 2 3 b.62).x) function that computes the associated Legendre functions of the first kind of degree n . n evaluated for each element of x .34). m = 1 . Excel does not have any functions related to Legendre polynomials. ….5 As stated above. Third Edition Copyright © Orchard Publications 15−19 .0.2990 For m = 0 in (15.Legendre Functions At present. m = 1 and m = 2 are: Numerical Analysis Using MATLAB® and Excel®. 1.5 2 1⁄2 = ( –1 ) ( 1 – x ) = –( 1 – x ) 2 1⁄2 1 d----. Check with MATLAB: disp('The values for m = 0. 2. P2 ( x ) 1 x = 0.125 x = 0.P 2 ( x ) dx = –( 1 – x ) x = 0. Here.⎞ ⎝ 2 ⎠ 2 = – 0. n evaluated for each element of x . a.5) The values for m = 0. and order m = 0.5 ( 3x ) = – 1.25 d ⋅ --------. and third rows respectively.5 c.5 3x – 1 = ⎛ ---------------. For this example. 2. …. the MATLAB legendre(n. for the first. that is. Example 15. P 3 ( x ) x = – 0. P 2 ( x ) Solution: For this example. we use the relation (15.62). a.

2). y(:.25 = ( –1 ) ( 1 – x ) 3 2 3⁄2 d ------.2990 2.( 3x 2 – 1 ) 3 dx 3 x = 0. Legendre -0. and thus MATLAB will display a matrix whose rows correspond to the values of m = 0 .2500 2 2⁄2 P3 ( x ) 2 x = – 0. and Chebyshev Functions ans = -0. y=zeros(4. fprintf('m\t Legendre \n'). y(:. n = 3 .1)=m'.6250 -9. fprintf('\n'). y=zeros(3. then P n ( x ) = 0 . fprintf('\n'). for the first.P 3 ( x ) 2 dx 2 x = – 0.0f\t %7. m=0:2.5 5x – 3x 2 d = ( 1 – x ) ------.5).25 2 3⁄2 d ------.⎛ --------------------⎞ 2⎝ 2 ⎠ dx 2 x = – 0. y(:.5). Check with MATLAB: m=0:3. y(:. fprintf('m\t Legendre \n'). fprintf('%2.1250 -1. Third Edition Copyright © Orchard Publications .Chapter 15 Bessel. second.5 2 d 15x – 3 = ( 1 – x ) ----.2990 2.25 and since the third derivative of 3x – 1 is zero.y') c. In general. if m > n .2)=legendre(3. third and fourth rows respectively.2500 or more elegantly.⎞ dx ⎝ 2 ⎠ 2 = ( 1 – x ) ( 15x ) x = – 0. Legendre.3248 -5.0.−0.7428 P2 ( x ) 3 x = 0.2)=legendre(2. fprintf('%2.4f \n'. m = 2 . and m = 3 .6250 Here. m 2 3 15−20 Numerical Analysis Using MATLAB® and Excel®.⎛ ------------------.5 2 3 x = – 0. it follows that P 2 ( x ) = 0 .y') m 0 1 2 b. m = 1 .4375 -0.0f\t %7.5 = – 5.5 = ( –1 ) ( 1 – x ) 2 d ------. m 0 1 2 3 Legendre 0.4f \n'.2).P 2 ( x ) 3 dx 3 = –( 1 – x ) x = 0.1250 -1.1)=m'.

2). Third Edition Copyright © Orchard Publications 15−21 .% Differentiate y twice with respect to x Numerical Analysis Using MATLAB® and Excel®.3 Laguerre Polynomials Another class of polynomials that satisfy the orthogonality principle. we obtain L0 ( x ) = e L1 ( x ) = e L2 ( x ) = e x d dx 0 0 (x e ) = e e 0 –x x –x = e = 1 0 x –x x –x –x d ( xe ) = e ( e – xe ) = 1 – x dx x d dx 2 2 3 ( x e ) = e e ( 2 – 4x + x ) = 2 – 4x + x 2 –x x –x 2 2 (15. these are solutions of the differential equation x dy dx 2 2 + (1 – x) dy + ny = 0 dx (15.66) Compute the Laguerre polynomials a.64) These polynomials are computed with the Rodrigues’ formula x n –x Ln ( x ) = e d ( x e ) n dx n (15. L 0 ( x ) b. L 2 ( x ) d. L 3 ( x ) Solution: Using Rodrigues’s formula of (15.Laguerre Polynomials 15.7 ∞ e L m ( x )L n ( x ) dx = 0 –x (15. z=diff(y. are the Laguerre polynomials L n ( x ) .65) The orthogonality principle for these polynomials states that ∫0 Example 15. L 1 ( x ) c.67) x 3 –x 2 3 L 3 ( x ) = e d ( x e ) = 6 – 18x + 9x – x 3 dx The differentiation of the last two polynomials in (15.65).67) was performed with MATLAB as follows: syms x y z y=x^2*exp(−x).

Legendre. Two interesting properties of the T n ( x ) polynomials are: 1.69) The solutions of (15. y=x^3*exp(−x). We will restrict our discussion to the T n ( x ) polynomials.4 Chebyshev Polynomials The Chebyshev polynomials are solutions of the differential equations dy 2 d y 2 ( 1 – x ) --------.+ n y = 0 2 dx dx 2 (15.% Differentiate y twice % we cannot differentiate three times at once w=diff(z).* The solutions of (15.% Differentiate one more time L3x=exp(x)*w. Third Edition Copyright © Orchard Publications . 2. another class of orthogonal functions known as Genenbauer or Ultraspherical functions use the notation Cn ( x ) and for this reason.68) and dy 2 d y ( 1 – x ) --------.2). This property is the basis for the Chebyshev approximation in the design of Chebyshev type electric filters. * Some books use the notation Ck ( x ) for these polynomials. simplify(L2x) ans = 2-4*x+x^2 syms x y z w . that is. they oscillate with the same ripple.– 3x ----.+ n ( n + 2 )y = 0 2 dx dx 2 (15. z=diff(y.68) are referred to as Chebyshev polynomials of the first kind and are denoted as y = T n ( x ) .69) are the Chebyshev polynomials of the second kind. (a) 15−22 Numerical Analysis Using MATLAB® and Excel®. within this range. For x > 1 they increase or decrease more rapidly than any other polynomial of order n .– x ----. We will plot some of these later in this section. we will avoid notation C k ( x ) for the Chebyshev polynomials. and Chebyshev Functions L2x=exp(x)*z. these are denoted as y = U n ( x ) . They exhibit equiripple amplitute characteristics over the range – 1 ≤ x ≤ 1 .Chapter 15 Bessel. However. simplify(L3x) ans = 6-18*x+9*x^2-x^3 15. Both kinds comprise a set of orthogonal functions.

74) with (15. They can also be derived from the following relations. T n ( x ) = cos ( n cos x ) T n ( x ) = cos h ( n cos h x ) –1 –1 for x ≤ 1 for x > 1 (15.72).73).2 Chebyshev polynomials expressed in powers of x n 0 1 2 3 4 5 6 Tn ( x ) 1 x 2x – 1 4x – 3x 8x – 8x + 1 16x – 20x + 5x 32x – 48x + 18x – 1 6 4 2 5 3 4 2 3 2 To show that the relation of (15.70) can be expressed as a polynomial. A good reference is the Handbook of Mathematical Functions.73) and T n ( y ) = cos ny Next.75).71) Using (15. in (15. we obtain T n + 1 ( y ) + T n – 1 ( y ) = 2 cos ny cos y = 2T n ( y )x = 2xT n ( y ) (15. and making use of (15. we let x = cos y (15. Some are shown in Table 15. we replace n with n + 1 and we obtain T n + 1 ( y ) = cos ( n + 1 )y = cos ny cos y – sin ny sin y (15.73) and (15.76) Numerical Analysis Using MATLAB® and Excel®. we can express T n ( x ) as polynomials in powers of x . Third Edition Copyright © Orchard Publications 15−23 .71).75) Now. replacing n with n – 1 . we obtain T n – 1 ( y ) = cos ( n – 1 )y = cos ny cos y + sin ny sin y (15. TABLE 15. we add (15.72) (15.2.70) or (15.74) Similarly. Dover Publications.70) (15.Chebyshev Polynomials These polynomials are tabulated in reference books which contain mathematical functions.

70) by letting y = cos x . can now be verified by using a combination of the above relations. we use the recurrence formula of (15. Legendre. (15. 3. for n = 0 .2 with (15. Thus. for n = 0 . For instance.78) For n = 1 .73) yields T0 ( y ) = T0 ( x ) = 1 (15. we obtain T1 ( y ) = T1 ( x ) = x (15.71) can be derived from (15. T 3 ( x ) = 2xT 2 ( x ) – T 1 ( x ) = 4x – 2x – x = 4x – 3x 3 (15. from (15. Third Edition Copyright © Orchard Publications . T 2 ( x ) = cos ( 2 ⋅ cos x ) = cos ( 2 ⋅ y ) = cos 2y = 2 cos y – 1 ⎧ ⎪ ⎪ ⎨ ⎪ ⎪ ⎩ ⎧ ⎪ ⎪ ⎨ ⎪ ⎪ ⎩ = 2 cos ( cos x ) – 1 = 2 2 –1 –1 2 cos ( cos x ) x 2 –1 ⋅ cos ( cos x ) x –1 –1 or T 2 ( x ) = 2x – 1 Relation (15. we can replace y with x to obtain T n + 1 ( x ) = 2xT n ( x ) – T n – 1 ( x ) Recurrence Relation (15.77).Chapter 15 Bessel. T 0 ( x ) = cos ( 0 ⋅ cos x ) = cos ( 0 ⋅ y ) = 1 –1 For n = 1 . we can prove the first 3 entries of Table 15.73) and (15. Thus.70) as follows: We recall that 15−24 Numerical Analysis Using MATLAB® and Excel®.77) The polynomials in Table 15.81) –1 Alternately. and Chebyshev Functions or T n + 1 ( y ) = 2xT n ( y ) – T n – 1 ( y ) Then. T 2 ( x ) = 2xT 1 ( x ) – T 0 ( x ) = 2x – 1 2 (15.72). when n = 2 . T 1 ( x ) = cos ( 1 ⋅ cos x ) = cos ( 1 ⋅ y ) = cos y = x –1 and for n = 2 .2. 4 and so on.79) To derive the algebraic expressions corresponding to n = 2.80) 3 and when n = 3 .

83) (15.85) follows. Tnx6).71).Chebyshev Polynomials e +e cos α = ----------------------2 jα –j α (15.. Tnx0=cos(0*acos(x)).70). Tnx4. Tnx5=cos(5*acos(x))..2 −1. cos α = cos hj α and when x > 1 . cos x = – j cosh x * –1 –1 By substitution into (15. x. For example.5 1. We can also use MATLAB to convert (15.2:0. syms x.5]). xlabel('x'). x. j cos v = cosh v and (15. Tnx3. expand(cosh(3*acosh(x))) ans = 4*x^3-3*x ans = 4*x^3-3*x The MATLAB script below plots the T n ( x ) for n = 0 through n = 6 . Tnx4=cos(4*acos(x)). Tnx0.71) to polynomials. Tnx1=cos(1*acos(x)). title('Chebyshev Polynomials of the First Kind').2. x. x. Tnx2. expand(cos(3*acos(x))). Tnx2=cos(2*acos(x)).. making use of (15. Tnx1.85) Then. Third Edition Copyright © Orchard Publications 15−25 . x.85).. if n = 3 .01:1.70) and (15. plot(x. x. jα = cosh v . –1 –1 –1 –1 Numerical Analysis Using MATLAB® and Excel®. Tnx5.82) and e +e cos h α = ------------------2 α –α (15.2 1. % Chebyshev polynomials % x=−1. Tnx3=cos(3*acos(x)). grid.84) (15. then α = cos v . and that cosh ( – t ) = cosh t . axis([−1. we obtain T n ( x ) = cos [ n ( – j cosh x ) ] = cos ( – jn cosh x ) = cosh ( jnj cosh x ) = cosh [ j ( – jn cosh x ) ] = cosh ( n cosh x ) –1 –1 –1 –1 –1 and this is the same as (15. ylabel('Tn(x)') % We could have used the gtext function to label the curves but it is easier with the Figure text % tool * Let cos α = cosh jα = v . Tnx6=cos(6*acos(x)).

if we want to design a second order Chebyshev low−pass filter. we use the Chebyshev polynomial T 2 ( x ) = 2x – 1 2 and (15.2 0. Plot of Chebyshev polynomials with MATLAB As mentioned earlier. and α and ε are other parameters that are used to specify the order and type of the electric filter.5 -1 -0.86) becomes α A ( ω ) = ----------------------------------------------------2 2 1 + ε [ 2 ( ω ⁄ ωC ) – 1 ] 2 (15.86) where ω is the operating radian frequency.5 T5 -1 T4 T6 T2 T3 -1. among other applications. Legendre. The basic Chebyshev low−pass filter approximation is defined as α A ( ω ) = -----------------------------------------2 2 1 + ε T n ( ω ⁄ ωC ) 2 (15. ISBN 0−9744239−9−8.4 -0.6.6 shows the plot of the Chebyshev polynomials of the first kind T n ( x ) for n = 0 through n = 6 . 1.4 0.2 0 x 0.Chapter 15 Bessel.8 1 Figure 15. For example.5 Chebyshev Polynomials of the First Kind 1 T0 T1 0.87) * For a thorough discussion on the design of analog and digital filters refer to Signals and systems with MATLAB Applications. ω C is the cutoff frequency. Chebyshev polynomials.* The filters are described in terms of rational polynomials that approximate the behavior of ideal filters.5 Tn(x) 0 -0.6 -0. are used in the design of electric filters. Orchard Publications. 15−26 Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications .6 0. and Chebyshev Functions Figure 15.8 -0.

and the most common are the Method of Frobenius and the Method of Picard. positive or negative integer.– ----------------------. • Bessel functions are solutions of the differential equation x2 dy dx 2 2 +x dy 2 2 + ( x – n )y = 0 dx where n can be any number. The general solution depends on the value of n .+ ----------------------.+ --------------------. fractional.– ----------------------.– ----------------------.5 Summary • Differential equations with variable coefficients cannot be solved in terms of familiar functions as those which we encountered in ordinary differential equations with constant coefficients.Summary 15. Third Edition Copyright © Orchard Publications 15−27 .– ----------------------. • The series Jn ( x ) = k=0 ∑ ∞ x n + 2k 1 k ⋅ --------------------------------------( – 1 ) ⋅ ⎛ -. The usual procedure is to derive solutions in the form of infinite series.+ ----------------------.⎞ ⋅ ------------------------------------------⎝2⎠ k! ⋅ Γ ( – n + k + 1 ) is referred to as the Bessel function of negative order n .+ ------------------------. • For n = 0.+ ----------------------.– … 2 4 6 8 10 2 ⋅ 2! 2 ⋅ 1! ⋅ 3! 2 ⋅ 2! ⋅ 4! 2 ⋅ 3! ⋅ 5! 2 ⋅ 4! ⋅ 6! 2 4 6 8 10 3 5 7 9 2 4 6 8 • Two more useful relations are d J ( x ) = –J ( x ) 1 dx 0 Numerical Analysis Using MATLAB® and Excel®.+ --------------------.⎞ ⎝2⎠ k! ⋅ Γ ( n + k + 1 ) n≥0 where n is any positive real number or zero is referred to as Bessel function of order n . or even a complex number.– … 2 2 4 2 6 2 8 2 2 ⋅ ( 1! ) 2 ⋅ ( 2! ) 2 ⋅ ( 3! ) 2 ⋅ ( 4! ) x x x x x J 1 ( x ) = -.– --------------------. • The series J –n ( x ) = k=0 ∑ ( –1 ) ∞ k x – n + 2k 1 ⋅ ⎛ -. 1 and 2 the series reduce to x x x x J 0 ( x ) = 1 – --------------------.– … 2 2 3 ⋅ 1! ⋅ 2! 2 5 ⋅ 2! ⋅ 3! 2 7 ⋅ 3! ⋅ 4! 2 9 ⋅ 4! ⋅ 5! x x x x x J 2 ( x ) = -------------.

• If n is not an integer. denoted as Y n ( x ) and referred to as Bessel functions of the second kind. • The infinite series solution of the Legendre functions. Third Edition Copyright © Orchard Publications . or Hankel functions. 15−28 Numerical Analysis Using MATLAB® and Excel®. and thus their solutions are called Modified Bessel functions. or Weber functions. denoted as Q n ( x ) . Also. and can also be found with the MATLAB besselj(n. • Besides the above functions known as Bessel functions of the first kind. is referred to as Legendre functions of the second kind. J n ( x ) and J –n ( x ) are linearly independent. … • If a and b are distinct roots of J 0 ( x ) = 0 . 3. They also can be found in math table books.cos x πx are known as half−order Bessel functions. ∫0 xJ0 ( ax )J0 ( bx ) dx • The differential equation 1 = 0 and thus we say that J 0 ( ax ) and J 0 ( bx ) are orthogonal in the interval 0 ≤ x ≤ 1 . for this case. certain differential equations resemble the Bessel equation. 2. the general solution of the Bessel equation is y = AJ n ( x ) + BJ – n ( x ) n ≠ 0. and Chebyshev Functions d { xJ 1 ( x ) } = xJ 0 ( x ) dx • Values of J n ( x ) can be calculated using the appropriate series given above. 1.sin x and J ( – 1 ⁄ 2 ) ( x ) = πx 2 ----. then. J 0 ( a ) = 0 and J 0 ( b ) = 0 .– 2x ----.Chapter 15 Bessel. Legendre.+ n ( n + 1 )y = 0 2 dx dx 2 2 where n is a constant. dy d y ( 1 – x ) --------. is known as Legendre’s equation. or Neumann functions exist. other Bessel functions. • The Bessel functions J1 ⁄ 2 ( x ) = 2 ----.n) function.x) function or the Excel BESSELJ(x.

2 cos ( n – 2 ) θ 2 ⋅ 4 ⋅ … ⋅ 2n 2 2 ⋅ 4 ⋅ … ⋅ ( 2n – 2 ) 1 ⋅ 3 1 ⋅ 3 ⋅ … ⋅ ( 2n – 5 ) + --------.( x – 1 ) n n 2 ⋅ n! dx is known as Rodrigues’ formula.( 3x – 1 ) 2 1 4 2 P 4 ( x ) = -.for n = even and N = ---------------. is 2n + 1 B n = -------------2 ∫–1 f ( x )Pn ( x ) dx ∑ Bn Pn ( x ) n=0 ∞ 1 and with this relation we can find a polynomial f ( x ) defined as f ( x ) = B0 P0 ( x ) + B1 P1 ( x ) + B2 P2 ( x ) + … + Bn Pn ( x ) = • The trigonometric form of the Legendre polynomials is 1 ⋅ 3 ⋅ … ⋅ ( 2n – 1 ) 1 1 ⋅ 3 ⋅ … ⋅ ( 2n – 3 ) P n cos θ = -------------------------------------------.( 63x – 70x + 15x ) 8 • The relation n n 1 .( 35x – 30x + 3 ) 8 P1 ( x ) = x 1 3 P 3 ( x ) = -. Third Edition Copyright © Orchard Publications 15−29 .⋅ -------------------------------------------. Numerical Analysis Using MATLAB® and Excel®.x n – 2k n 2 k! ( n – k )! ( n – 2k )! k (n – 1) n where N = -.⋅ -------.2 P n ( x ) = -------------. • The Legendre polynomial series of a function f ( x ) for x < 1 .d .for n = odd 2 2 and the first 6 Legendre polynomials are P0 ( x ) = 1 1 2 P 2 ( x ) = -.2 cos n θ + -.2 cos ( n – 4 ) θ + … 2 ⋅ 4 2 ⋅ 4 ⋅ … ⋅ ( 2n – 4 ) and the first 6 Legendre polynomials in trigonometric form listed below.Summary • The Legendre polynomials are defined as Pn ( x ) = k=0 ∑ N ( – 1 ) ⋅ ( 2n – 2k )! --------------------------------------------------.⋅ -------------------------------------------. and offers another method of expressing the Legendre polynomials.( 5x – 3x ) 2 1 5 3 P 5 ( x ) = -.

y = 0 2 2 dx dx 1–x 2 is referred to as the associated Legendre differential equation. satisfy the orthogonality principle when m ≠ n as indicated by the integral ∫ ⎧ 0 ⎪ P m ( x )P n ( x ) dx = ⎨ 2 –1 ⎪ -------------⎩ 2n + 1 1 m≠n m = n • The Legendre polynomials in trigonometric form satisfy the orthogonality principle when m ≠ n as indicated by the integral ∫0 π ⎧ 0 ⎪ P m ( cos θ )P n ( cos θ ) sin θ dθ = ⎨ 2 ⎪ -------------2n + 1 ⎩ m≠n m = n • The differential equation 2 dy 2 d y m ( 1 – x ) --------.+ n ( n + 1 ) – ------------. and Chebyshev Functions P 0 cos θ = 1 P 1 cos θ = cos θ 3 cos 2 θ + 1 P 2 cos θ = --------------------------4 5 cos 3 θ + 3 cos θ P 3 cos θ = --------------------------------------8 35 cos 4 θ + 20 cos 2 θ + 9 P 4 cos θ = ---------------------------------------------------------64 ------------------------------------------------------------------------P 5 cos θ = 63 cos 5 θ + 35 cos 3 θ + 30 cos θ 128 • The Legendre polynomials in algebraic form. The general solution of this equation is y = C1 Pn ( x ) + C2 Qn ( x ) m m where C 1 and C 2 are arbitrary constants. also known as spherical harmonics.P n ( x ) m dx m 15−30 Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications . These functions. Legendre. The functions P n ( x ) and Q n ( x ) are referred to as associated Legendre functions of the first and second kind respectively.Chapter 15 Bessel.– 2x ----. are evaluated from the relations Pn ( x ) = ( –1 ) ( 1 – x ) m m 2 m⁄2 m m d ⋅ --------.

…. n evaluated for each element of x . The solutions of the second are the Chebyshev polynomials of the second kind. 1. 2.– 3x ----. They are computed with the Rodrigues’ formula x n –x Ln ( x ) = e d ( x e ) n dx n • The Chebyshev polynomials are solutions of the differential equations dy 2 d y 2 ( 1 – x ) --------. This property is the basis for the Chebyshev approximation in the design of Chebyshev type electric filters.+ n y = 0 2 dx dx 2 and dy 2 d y ( 1 – x ) --------.+ n ( n + 2 )y = 0 2 dx dx 2 The solutions of the first differential equation are referred to as Chebyshev polynomials of the first kind and are denoted as y = T n ( x ) . These polynomials are satisfy the orthogonality principle. • The solutions of the differential equation x dy dx 2 2 + (1 – x) dy + ny = 0 dx are known as Laguerre polynomials and are denoted as L n ( x ) . Numerical Analysis Using MATLAB® and Excel®.Q n ( x ) m dx m • The MATLAB legendre(n.x) function computes the associated Legendre functions of the first kind of degree n .6.– x ----. Third Edition Copyright © Orchard Publications 15−31 .Summary Qn ( x ) = ( –1 ) ( 1 – x ) m m 2 m⁄2 d ⋅ --------. Both kinds comprise a set of orthogonal functions. and order m = 0. that is. within this range. • The T n ( x ) polynomials are derived from the relations T n ( x ) = cos ( n cos x ) T n ( x ) = cos h ( n cos h x ) –1 –1 for x ≤ 1 for x > 1 These polynomials exhibit equiripple amplitute characteristics over the range – 1 ≤ x ≤ 1 . these are denoted as y = U n ( x ) . they oscillate with the same ripple as shown in Figure 15.

6 Exercises 1.25 x = 0.5 x = – 0. f (x) 1 −1 1 x 15−32 Numerical Analysis Using MATLAB® and Excel®. P 3 ( x ) 2 x = 0. Then. P 3 ( x ) f..75 c. P 0 ( x ) through P 4 ( x ) will be sufficient.Chapter 15 Bessel. P 2 ( x ) 3 x = 0. and Chebyshev Functions 15. J 0 ( 3 ) b.e. J 1 ⁄ 2 ( π ⁄ 6 ) d. P 2 ( x ) e. i. P 1 ( x ) 2 x = 0. The first 5 terms of P n ( x ) . and check your answers with MATLAB. P 1 ( x ) d. a. J –1 ⁄ 2 ( π ⁄ 3 ) 2. a. Use the appropriate series of the Bessel functions J n ( x ) to compute the following values using the first 4 terms of the series and check your answers with MATLAB or Excel.5 m b. use MATLAB or Excel to plot g ( x ) and compare with f ( x ) . Compute the Legendre polynomial g ( x ) representing the waveform f ( x ) of the figure below. J 1 ( 2 ) c.5 x = 0. Third Edition Copyright © Orchard Publications .25 3. Use the appropriate Legendre polynomials P n ( x ) or P n ( x ) and Rodrigues’s formulas to compute the following. Legendre.

Third Edition Copyright © Orchard Publications 15−33 .= -----.5764 16 384 18432 c.2563 and this is much closer to the value obtained with MATLAB. besselj(1.2601 ans = 0.– ----------.5513 π 2 2π π π(π ⁄ 6) 6 1 6 2 .– --------------------2 2 4 2 6 2 2 ⋅ ( 1! ) 2 ⋅ ( 2! ) 2 ⋅ ( 3! ) 2 4 6 x=3 9 81 729 = 1 – -.3008 4 64 2304 b. This is because our computation was based on the first 4 terms of the series. J1 ⁄ 2 ( x ) = 2 ----. x x x J 0 ( x ) = 1 – --------------------.+ --------------------.sin x πx = x = π⁄6 12 1 2 3 3 2 .cos ( π ⁄ 3 ) = -----. Had we taken also the fifth term our answer would have been – 0. Numerical Analysis Using MATLAB® and Excel®.Solutions to End−of−Chapter Exercises 15.cos x πx = x = π⁄3 Check with MATLAB: besselj(0.pi/6).-----------------.-----------------.= --------.7 Solutions to End−of−Chapter Exercises 1.pi/3) ans = -0.= 0.+ ----.– -------------.⋅ -. x x x x J 1 ( x ) = -.= -----.= – 0.= 0.= 0.+ ---------------------.– -----------. besselj(0.⋅ -.+ -------.5767 ans = 0.5.3).2).sin ( π ⁄ 6 ) = --------. besselj(−0.– ------------------------------2 22 ⋅ 4 22 ⋅ 42 ⋅ 6 22 ⋅ 42 ⋅ 62 ⋅ 8 3 5 7 x=2 8 32 128 = 1 – ----.5. J–1 ⁄ 2 ( x ) = 2----. a.3898 π 2 2π π(π ⁄ 3) d.3898 We observe that the first value returned by MATLAB above is significantly different from that we obtained from the series.5513 ans = 0.

( 15x – 3 ) 2 dx = 0.⎨ -. Third Edition Copyright © Orchard Publications . In other words.( x ) 2 dx 2 = 0 x = 0.3438 x = 0.4688 ( 30x ) x = 0.5 m = 0 This is because m > n .25 ) = – 0.⋅ ----.Chapter 15 Bessel.= ( 1 – x ) ------. P1 ( x ) x = 0.( 5x – 3x ) ⎬ 2 2 dx ⎩ ⎭ x = 0.( 3x 2 – 1 ) ⎬ = 0 . and Chebyshev Functions 2.5160 15−34 Numerical Analysis Using MATLAB® and Excel®. 3 3 ⎫ d ⎧1 d ------. 2 P 1 ( x ) x = 0.5 = ( –1 ) ( 1 – x ) 2 2 2⁄2 d ------.25 ) ⋅ -. Legendre.25 x = 0.5 d = ( 1 – x ) ⋅ ------.25 2 2 3 d.( 3x – 1 ) 2 = 0. We will use the relations of (15.25 1 d 2 2 = ( 1 – 0.P 3 ( x ) 2 dx 2 x = 0. P3 ( x ) x = 0. P3 ( x ) 2 x = 0.3359 x = 0. P0 ( x ) = 1 1 2 P 2 ( x ) = -.P 2 ( x ) = ------.25 = 3.( 35x – 30x + 3 ) 8 m Pn ( x ) m P1 ( x ) = x 1 3 P 3 ( x ) = -.5 ( 3 × ( 0.P n ( x ) m dx m a. then P n ( x ) = 0 . P2 ( x ) 3 x = – 0.75 ) – 1 ) = 0.( 63x – 70x + 15x ) 8 2 m⁄2 = ( –1 ) ( 1 – x ) d ⋅ --------.( 3x – 1 ) 2 1 4 2 P 4 ( x ) = -.3 3 2 dx dx ⎩ ⎭ f.25 1 3 = -.62).25 2 ⎫ 2 d ⎧1 3 .5 2 b. e.25 ) – 3 × 0.75 1 2 = -. They are repeated below for convenience.25 = ( –1 ) ( 1 – x ) 2 2 2⁄2 d ------.5 ( 5 × ( 0. P2 ( x ) x = 0.34) and (15.5 = x = 0.75 c.( 5x – 3x ) 2 = 0.( 5x – 3x ) 2 1 5 3 P 5 ( x ) = -.P 1 ( x ) 2 dx x = 0.5 We recall that if m > n .⎨ -.

5). fprintf('m\t Legendre \n'). Third Edition Copyright © Orchard Publications 15−35 . y(:. m=0:1. fprintf('\n').5156 3 -13.25). fprintf('m\t Legendre \n').0. n.2)=legendre(3.4882 2 1. m=0:1. y(:.0f\t %7. y(:.4f \n'.2)=legendre(1. y(:..5000 1 -0. m=0:2.75).2)=legendre(2. y=zeros(3.y') m Legendre 0 0. y(:. fprintf('\n').8660 Here.5). y=zeros(2.5000 1 -0. m=0:3.3359 1 0.1)=m'. fprintf('m\t Legendre \n').3438 1 -1. . y=zeros(3. y(:. fprintf('%2.. fprintf('%2. y=zeros(4.6160 d.0f\t %7. m=0:2.1)=m'. fprintf('\n'). evaluated for each element of x.2).Solutions to End−of−Chapter Exercises Check with MATLAB: a. y(:. For this reason we’ve used m=0:1. fprintf('%2. e.y') m Legendre 0 0.8660 b. that is. fprintf('%2.x) function computes the associated Legendre functions of degree n and order m = 0. y=zeros(2.2).2).1)=m'. 1.0f\t %7. y(:. For this example.0f\t %7. fprintf('%2.−0.4f \n'. fprintf('\n'). fprintf('m\t Legendre \n'). the legendre(n.4f \n'.4f \n'. fprintf('m\t Legendre \n').5). m = 2 and n = 1 and the statement m=0:2 is not accepted.y') m Legendre 0 0.0. m > n . y(:.0f\t %7.2)..0.4f \n'.2).2)=legendre(2. y(:.3125 c.9985 2 3.0.1)=m'.y') As in (d) above m > n and MATLAB returns Numerical Analysis Using MATLAB® and Excel®.y') m Legendre 0 -0.2)=legendre(1.1)=m'. fprintf('\n').

1)=m'.– ---.4f \n'. and Chebyshev Functions m Legendre 0 -0. 1 B 0 = -2 3 B 1 = -2 5 B 2 = -2 7 B 3 = -2 ∫0 ∫0 1 1 x .y') 3.⎞ 4⎝ 4 2 ⎠ 3 4 2 5 = ----16 1 ∫0 1 1 7 3 x ⋅ -. fprintf('\n').– 3x .⎛ ------.⎞ 4⎝ 5 3 ⎠ 1 = 0 0 9 B 4 = -2 ∫0 1 1 9 4 2 x ⋅ -.5156 3 -13.⋅ ---2 3 1 = -4 = 1 -2 1 0 1 3 1 0 ∫0 1 1 5 2 x ⋅ -. y(:. Third Edition Copyright © Orchard Publications .2990 2 2.0. m=0:3.+ ------.------( 5x – 3x ) dx = -. m Legendre 0 -0.3359 1 0.⎛ ---------.x ⋅ P 0 ( x ) ⋅ dx = -.1250 1 1.0f\t %7. y=zeros(4.6160 2n + 1 B n = -------------2 ∫–1 f ( x )Pn ( x ) dx ∫0 f ( x )Pn ( x ) dx 2 1 0 1 1 For this exercise f ( x ) = 0 for – 1 ≤ x ≤ 0 and thus 2n + 1 B n = -------------2 Then. y(:.Chapter 15 Bessel.⎞ 16 ⎝ 6 4 2 ⎠ 3 = – ----32 15−36 Numerical Analysis Using MATLAB® and Excel®.2).⎛ 5x .25).⋅ ---2 2 3 xx ⋅ P 1 ( x ) ⋅ dx = -.2)=legendre(3. fprintf('%2. Legendre.9985 2 3. fprintf('m\t Legendre \n').2500 f.– ---------.( 35x – 30x + 3 ) dx = ----8 16 1 0 ∫0 ( 35x 5 – 30x + 3x ) dx 3 9 35x 6 30x 4 3x 2 = ----.( 5x – 3x ) dx = -2 4 ∫0 5 3 7 .( 3x – 1 ) dx = -2 4 ∫0 1 1 5 3x 4 x 2 ( 3x – x ) dx = -.------.

*x.P 1 ( x ) + ----.8 0.9 1 Numerical Analysis Using MATLAB® and Excel®.3 0. Third Edition Copyright © Orchard Publications 15−37 .1 0.( 3x – 1 ) – ----.+ ---------.+ ---------. Also. grid 1 0. x=0:0.2 0.7 0.P 2 ( x ) + 0 ⋅ P 3 ( x ) – ----.fx).⋅ x + ----. These values are close to zero.– ------------. plot(x. ylabel(‘f(x)’).1 0 0 0.5 0.– -------4 2 32 32 256 256 256 2 4 2 or 12 4 f ( x ) = -------.P 0 ( x ) + -. f ( 1 ) = 248 ⁄ 256 and this value is close to unity. fx=(15+128.^2−105.⋅ 1 + -.⋅ -.( 35x – 30x + 3 ) 16 2 2 32 8 4 1 x 15x 5 105x 90x 9 .3 0.= -.5 x 0.8 0. xlabel(‘x’).9 0.4 0.– ----.6 f(x) 0.. We plot f ( x ) with the MATLAB script below.4 0.^4).01:1.= -.6 0./256.( 15 + 128x + 210x – 105x ) 256 we note that f ( – 1 ) = – 8 ⁄ 256 and f ( 0 ) = 15 ⁄ 256 .P 4 ( x ) 2 16 32 4 5 1 1 3 1 1 2 4 2 .Solutions to End−of−Chapter Exercises and by substitution into f ( x ) = B0 P0 ( x ) + B1 P1 ( x ) + B2 P2 ( x ) + … + Bn Pn ( x ) = we obtain n=0 ∑ Bn Pn ( x ) ∞ 1 5 3 1 f ( x ) = -.*x+210.*x.7 0.⋅ -.2 0.+ -.

00 per 1000 Due to limited supplies of silicon. Numerical Analysis Using MATLAB® and Excel®.Chapter 16 Optimization Methods T his chapter introduces three methods for maximizing or minimizing some function in order to achieve the optimum solution. ABC Semiconductor can only buy 450 parts of Material A . We will discuss linear programming. are linearly related. Thus. referred to as the objective. and 1000 parts of Material B . The material types.1 Data for Example 16. Example 16. * A linear program is one in which the variables form a linear combination. These methods are topics discussed in detail in a branch of mathematics called operations research and it is concerned with financial and engineering economic problems.1 Linear Programming In linear* programming we seek to maximize or minimize a particular quantity. which is dependent on a finite number of variables. its product mix at times of high consumer demand. and we will illustrate these with some simple but practical examples. is subject to limited supplies.1 Parts of Material Types μPs Semiconductor Material A Semiconductor Material B Profit 3 5 $25. and in most cases are subject to certain conditions or limitations referred to as constraints. 16.00 per unit RAMs (1000s) 2 10 $20. Third Edition Copyright © Orchard Publications 16−1 .i.1 The ABC Semiconductor Corporation produces microprocessors ( μPs ) and memory ( RAM ) chips. phosphorus and boron. These variables may or may not be independent of each another. This corporation needs to know what combination of μPs and RAMs will maximize the overall profit. Our intent here is to introduce these methods with the basic ideas.1.. All other programs are considered non−linear. required to manufacture the μPs and RAMs and the profits for each are shown in Table 16. dynamic programming.e. TABLE 16. A and B . and network analysis.

y ) satisfying all constrains. 16−2 Numerical Analysis Using MATLAB® and Excel®. therefore. This line will pass through one of the three corners denoted as a .* y 250 200 150 100 50 a 5x + 10y = 1000 c 50 100 150 200 250 x 3x + 2y = 450 Isoprofit line b Figure 16. The x and y intercept corresponding to the above equations is shown in the plot of Figure 16. and x and y must be integers. there are only two variables. x and y . b . Plot of constraint lines for Example 16.Chapter 16 Optimization Methods Solution: Since with Material A we can produce 3 μPs and 2 RAMs . For this example. and with Material B 5 μPs and 10 RAMs . a graphical solution is possible.1 where the cross−hatched area indicates the feasible region.2) Two additional constraints are x ≥ 0 .1 The equation of the straight line of the maximum profit is referred to as isoprofit line. y ≥ 0 .1. and c . * The feasible region is the area which includes all points ( x. the corporation is confronted with the following constraints: 3x + 2y ≤ 450 5x + 10y ≤ 1000 We now can state the problem as subject to the constraints Maximize z = 25 × μP + 20 × RAMs 3x + 2y ≤ 450 5x + 10y ≤ 1000 (16.1) (16. We will solve this example graphically. Third Edition Copyright © Orchard Publications .

6) and the isoprofit line can be drawn from the equation 25x + 20y = 3865 (16. Therefore. are parallel to each another.25x + k 20 20 (16. 5*x+10*y−1000) x = 125 y = 75/2 Of course. Then.1 are found by simultaneous solution of 3x + 2y = 450 5x + 10y = 1000 (16. Third Edition Copyright © Orchard Publications 16−3 .25 20 This is shown as a dotted line on the plot of Figure 16.= – 1. all possible isoprofit lines have the same slope.7) by first letting x = 0 . and the highest isoprofit line passes through point b . that is. y = 0 . by substitution into (16. Then. then. z max = 25 × 125 + 20 × 37 = $3865 (16.3) We can express this equation in y = mx + b form. that is. Numerical Analysis Using MATLAB® and Excel®.Linear Programming The isoprofit line that we are interested is described by the equation z = 25 × μP + 20 × RAM = cons tan t = 25x + 20y = C (16. these values must be integers. 25 C y = – ----. The coordinates of point b in Figure 16.= 154.4) where k is the y −intercept.x + ----.1.5) Using MATLAB for the solution of (16.1).5) we obtain syms x y [x y]=solve(3*x+2*y−450.6 25 and ----------y = 3865 = 193. so we accept the values x = 125 . and y = 37 . we obtain the points 3865 x = ----------.

Third Edition Copyright © Orchard Publications .1 1. Use Add-Ins if necessary to add it. we must resort to algebraic methods such as the simplex method. The alternative paths are represented by the line segments ab .2 A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 B C D E F Optimization .860 448 1000 Note: Contents of A12:A18 are typed-in for information only Figure 16. Solve x(μPs)= 124 y(RAMs)= 38 Maximum Profit= Semiconductor Material A= Semiconductor Material B= $3. and the choice of alternative paths when leaving a given state. Spreadsheet for solution of Example 16. The procedure is included in the spreadsheet of Figure 16. however. Add B18<=1000. and so on. where the nodes a through h represent the states. is called a decision. In B17 enter =3*B12+2*B13 and in B18 =5*B12+10*B13 4. 16−4 Numerical Analysis Using MATLAB® and Excel®. Add B12>=0. Enter zeros in B12 and B13 2.2 Dynamic Programming Dynamic Programming is based on R. ac . In most cases. Bellman’s Principle of Optimality which states that: An optimum policy has the property that whatever the initial state and the initial decisions are.3 represents a line graph.Chapter 16 Optimization Methods It was possible to solve this problem graphically because it is relatively simple. OK . Add B13=Integer. we cannot obtain the solution by graphical methods and therefore. bd . In B15 enter =25*B12+20*B13 3.1 with Excel’s solver 16. 5. This and other methods are described in operations research textbooks. We can find the optimum solution to this type of problems with Excel’s Solver feature. On the Solver Parameters screen enter the following: Set Target Cell: B15 Equal to: Max By Changing Cells: B12:B13 Click on Add and enter Constraints: B12=Integer. Add B17<=450. the remaining decisions must constitute an optimum policy with regard to the state resulting from the first decision.2.Maximum Profit for Example 16. From the Tools drop menu select Solver . Figure 16. Add B13>=0.

and each has a value assigned to it which we will refer to as the cost. in this case. Thus. the cost is J ah = J ac + J cf + J fh (16.Dynamic Programming c e d a b h f g Figure 16. ( J ac + g c ) } (16.11) The optimum path policy of (16. and it is usually denoted with the letter J . and h . if the entire path from a to h is to be optimum (minimum in this case).3.8) The costs for the other possible paths are defined similarly. The part which is related to the present decision. let us suppose that the initial state is a . we say that the optimum path policy for this line graph is J min = min { ( J ac + J cf + J fh ). the path from b to h must be selected optimally. For the line graph of Figure 16. f . ( J ac + J ce + J eh ). and the initial decision has been made to go to state b . ( J ce + J eh ) } (16.9) Now. For example. if the initial decision is to go from state a to c . the path from state c to h must be optimum. for the path a .10) Likewise.10) and (16. g b = min { ( J bd + J dh ). the objective is to go from state a to state h with minimum cost. Numerical Analysis Using MATLAB® and Excel®. Then. Then. Third Edition Copyright © Orchard Publications 16−5 .3. Line graph for a typical dynamic programming example We assume that all segments are directed from left to right. Accordingly. ( J ab + J bg + J gh ) } (16. ( J ab + J bd + J dh ).12) This relation indicates that to obtain the minimum cost we must minimize: 1. there is a cost associated with each segment. costs J ab and J ac .11) as g a = J min = min { ( J ab + g b ). that is. c .9) can now be expressed in terms of (16. ( J bg + J gh ) } (16. g c = min { ( J cf + J fh ). Let the minimum cost from state b to h be denoted as g b .

we make decisions at states b and c . d 9 b 5 a 3 c 4 6 f Figure 16. g e = min { ( 3 + g h ).14) (16.4. ( 5 + g k ) } = min { ( 3 + 5 ).2 8 6 e 5 k 4 3 6 h 5 m Solution: We observe that at states h .15) The final decision is at state a and thus g a = min { ( 5 + g b ). The line segments are directed from left to right and the costs are indicated beside each line segment. and f have no alternative paths since the lines are directed from left to right. ( 5 + 4 ) } = 8 (e → h → m) (16. ( 6 + g e ) } = min { ( 9 + 6 ). we make the first decision at state e .13) Next. Line graph for Example 16. Third Edition Copyright © Orchard Publications . g b = min { ( 9 + g d ).2 Find the minimum cost route from state a to state m for the line graph of Figure 16.16) 16−6 Numerical Analysis Using MATLAB® and Excel®.4. ( 6 + 8 ) } = 14 (b → e) g c = min { ( 4 + g e ). ( 3 + 12 ) } = 15 (a → c) (16. Then. d . k . Example 16. The part which represents the minimum value of all future costs starting with the state which results from the first decision.Chapter 16 Optimization Methods 2. ( 6 + g f ) } = min { ( 4 + 8 ). ( 6 + 8 ) } = 12 (c → e) (16. ( 3 + g c ) } = min { ( 5 + 14 ). Therefore.

K .6. J .5. node A represents an airport in New York City and nodes B through L several airports throughout Europe and Asia.5 d 9 b 5 a 3 c 4 6 f Figure 16.2 8 6 e 5 k 4 3 6 h 5 m Example 16. and the numbers beside the line segments indicated the flight times. and in how many hours after departure from A will he reach his destination? D 4 B 8 A 6 3 C 5 7 4 2 2 E 4 3 F 7 Figure 16. The encircled numbers represent waiting times in hours at each airport. also in hours. K . Line graph for Example 16.6. Which airport should he choose ( H . Line graph showing the minimum cost for Example 16.Dynamic Programming Therefore. J . as shown in Figure 16. A salesman must leave New York City and be in one of the airports H .3 On the line graph of Figure 16. or L at the shortest possible time. All flights originate at A and fly eastward. Third Edition Copyright © Orchard Publications 16−7 .3 L 3 5 4 3 4 K 6 4 J 2 H 3 Numerical Analysis Using MATLAB® and Excel®. or L ) to minimize his total travel time. The numbers in squares show the hours he must travel by an automobile to reach his destination. the minimum cost is 15 and it is achieved through path a → c → e → h → m .

g J = 2 .3 16−8 Numerical Analysis Using MATLAB® and Excel®. g K = 4 . ( 7 + 3 ) } = 3 + 10 = 13 F → K or F → L (16.17) The first decisions are made at D . Line graph showing the minimum cost for Example 16. and F .22) The final decision is made at A . ( 4 + g J ) } = 2 + min { ( 5 + 3 ).19) (16. ( 4 + 4 ) } = 4 + 5 = 9 E→J g F = 3 + min { ( 6 + g K ). E .7.7. 5 4 3 E 4 3 F 7 L 3 4 K 6 4 J 2 H 3 D 4 B 8 A 6 3 C 5 7 4 2 2 Figure 16.21) (16. ( 4 + 2 ) } = 2 + 6 = 8 D→J g E = 4 + min { ( 3 + g J ). and g L = 3 (16. ( 5 + g F ) } = 3 + min { ( 7 + 9 ).Chapter 16 Optimization Methods Solution: The hours that the salesman must travel by automobile to reach his destination are g H = 3 . ( 6 + 19 ) } = 23 A→B (16.23) Therefore.18) (16. ( 2 + g E ) } = 4 + min { ( 4 + 8 ). g D = 2 + min { ( 5 + g H ). the minimum cost (minimum time from departure to arrival at destination) is 23 hours and it is achieved through path A → B → E → J . ( 4 + gK ) } = 4 + min { ( 3 + 2 ). ( 2 + 9 ) } = 4 + 11 = 15 B→E g C = 3 + min { ( 7 + g E ). Then. ( 6 + g C ) } = min { ( 8 + 15 ). ( 5 + 13 ) } = 3 + 16 = 19 C→E (16. ( 7 + g L ) } = 3 + min { ( 6 + 4 ). as shown in Figure 16. where we find g A = min { ( 8 + g B ).20) The next decisions are made at B and C where we find that g B = 4 + min { ( 4 + g D ). Third Edition Copyright © Orchard Publications .

2.000.000.24) denote the profits in millions from product i .Dynamic Programming Example 16.000.000.000 $5.000 $6.2 x p(x) pA ( x ) pB ( x ) pC ( x ) 0 0 0 0 1 2 1 1 2 5 3 4 3 6 6 5 4 7 7 8 Our objective is to maximize the total profit z that represents the sum of the profits from each product. For simplicity. TABLE 16.000. Investments in each product are assumed to be multiples of $1. when x units of dollars are invested in it. we want to maximize z = p A ( x ) + p B ( x ) + p C ( x ) (16.2 Amounts invested and return on investment for each product Investments Amount Invested 0 Product A Product B Product C 0 0 0 $1.000.000 $3.25) subject to the constraint Numerical Analysis Using MATLAB® and Excel®. and we enter these in Table 16. C (16. The expected profits are shown in Table 16.000 Return on Investment How should the money be allocated so that company will realize the maximum profit? Solution: This problem can also be solved with linear programming methods but we will use the so called tabular form of solution.000 $2.000 $7. B and C. has $4.3.000 $4.000.000 $4.000.000 to invest in three different products A.000.3 Modified Table 16.000 $6. TABLE 16.000 and the company may allocate all the money to just one product or split it between these three products. subject to the constraint that the amount invested does not exceed four million dollars. high−technology company. In other words is.000. B.000.000 $3.000 $8.4 A start−up. Let pi ( x ) i = A.000 $7.000 $2.000. we express the profits in millions.000.000 $5.000.000.000. Third Edition Copyright © Orchard Publications 16−9 .000.000 $1.000 $1.000.

8 } = 8 (16. If we invest the remaining three units in Product C. do not have 4 units to invest in Product C. and u = 4 . and x C .31) (16. 4 millions assumed to be allocated to Product C. 4. The possibilities that we allocate 0 or 1 or 2 or 3 or 4 units (millions) to Product C. A for Product A. we have three or less.28) with decision dC ( 4 ) = 8 that is.32) with decision dC ( 2 ) = 4 With only one unit left to invest. j = C . 1. we let d j ( u ) be the decision that is being made to achieve the optimum value from v j ( u ) . p C ( 1 ) } = max { 0.. p C ( 1 ).Chapter 16 Optimization Methods xA + xB + xC ≤ 4 (16. p C ( 2 ). p C ( 2 ).29) (16. 4.33) 16−10 Numerical Analysis Using MATLAB® and Excel®. by a previous decision.26) where x A . one per product.e. we must consider all possibilities. v C ( 4 ) = max { p C ( 0 ). i. 4 } = 4 (16. Also. the optimum value v C ( 3 ) is found from v C ( 3 ) = max { p C ( 0 ). and u represents the number of money units. p C ( 1 ). p C ( 2 ) } = max { 0. where the subscript j indicates the number or stage assigned to the product.3. In this case.27) (16. 1. The computations are done in three stages. B and C respectively. 1. we obtain the maximum from v C ( 2 ) = max { p C ( 0 ). i. are the amounts to be invested in products A. We let v j ( u ) denote the value of the optimum profit that can be achieved.30) with decision dC ( 3 ) = 5 If we have only two units left.e. 5 } = 5 (16. but since we do not know what units were allocated to the previous products A and B. We start by allocating units (millions) to Product C (Stage C). 1 } = 1 (16. Third Edition Copyright © Orchard Publications . x B . and the corresponding returns are. p C ( 1 ). from Table 16. The next possibility is that one unit was invested in either Product A or Product B. and C for Product C. p C ( 3 ).. 5. p C ( 4 ) } = max { 0. the maximum appears in the fourth position since the left most is the zero position. we have v C ( 1 ) = max { p C ( 0 ). At Stage C. p C ( 3 ) } = max { 0. B for Product B. and we invest them in Product C.

we obtain v B ( 4 ) = max { 0 + 8. With j = B and u = 4. 3 + 4.4. with no units left to invest in Product C. or if one unit was invested in Product B. 1 and 0 . p B ( 3 ) + v C ( 4 – 3 ).39) with decision dB ( 4 ) = 0 since the maximum value is the zero position term. again we must consider all possibilities. 3. 2. 1 + 5.37) This expression says that if zero units were invested in Product B. it is possible that 3 units were invested in Product C. 6 + 1. p B ( 4 ) + v C ( 4 – 4 ) } (16. and so on.36) with decision dC ( 0 ) = 0 With these values. Third Edition Copyright © Orchard Publications 16−11 .Dynamic Programming with decision dC ( 1 ) = 1 Finally.35) (16. TABLE 16. 7 + 0 } = 8 (16.34) (16.38) (16. we consider Stage B. v C ( 0 ) = max { p C ( 0 ) } = max { 0 } = 0 (16. we have v B ( 4 ) = max { p B ( 0 ) + v C ( 4 – 0 ). Inserting the appropriate values. p B ( 1 ) + v C ( 4 – 1 ). Numerical Analysis Using MATLAB® and Excel®.4 Optimum profit and decisions made for Stage C u 0 Stage C Stage B Stage A vC ( u ) dC ( u ) vB ( u ) dB ( u ) vA ( u ) dA ( u ) 0 0 … … … … 1 1 1 … … … … 2 4 2 … … … … 3 5 3 … … … … 4 8 4 … … … … Next. we construct Table 16. and since we do not know what units were allocated to Product A (Stage A). it is possible that all four units were invested in Product C. p B ( 2 ) +v C ( 4 – 2 ).

p B ( 1 ) + v C ( 1 – 1 ) } or v B ( 1 ) = max { 0 + 1. 1 + 4. These are shown in Table 16.40) or with decision (16.48) (16. v B ( 0 ) = max { p B ( 0 ) + v C ( 0 – 0 ) } (16.42) (16.52) or v B ( 0 ) = max { 0 + 0 } = 0 with decision dB ( 0 ) = 0 Next.Chapter 16 Optimization Methods Using a similar reasoning. Also. v B ( 2 ) = max { p B ( 0 ) + v C ( 2 – 0 ). p B ( 1 ) + v C ( 3 – 1 ). 16−12 Numerical Analysis Using MATLAB® and Excel®.49) dB ( 3 ) = 3 Also. we have v B ( 3 ) = max { p B ( 0 ) + v C ( 3 – 0 ).51) (16.5.41) (16. 1 + 0 } = 1 with decision dB ( 1 ) = 0 if we consider the zero position term.44) (16.47) (16.50) (16.45) (16. p B ( 3 ) + v C ( 3 – 3 ) } v B ( 3 ) = max { 0 + 5.43) (16. Third Edition Copyright © Orchard Publications . p B ( 2 )+v C ( 2 – 2 ) } or v B ( 2 ) = max { 0 + 4. we update the previous table to include the Stage B values. 3 + 0 } = 4 with decision dB ( 2 ) = 0 v B ( 1 ) = max { p B ( 0 ) + v C ( 1 – 0 ). p B ( 2 ) +v C ( 3 – 2 ). 1 + 1. or dB ( 1 ) = 1 if we consider the first position term. 6 + 0 } = 6 (16.46) (16. 3 + 1. p B ( 1 ) + v C ( 2 – 1 ).

5 + 4. 9 units. * Since this is the first stage.000. 6 + 1.000) invested in this product will return $5.5 Updated table to include Stage B values u 0 Stage C Stage B Stage A vC ( u ) dC ( u ) vB ( u ) dB ( u ) vA ( u ) dA ( u ) * 1 1 1 1 1 … … 2 4 2 4 0 … … 3 5 3 6 3 … … 4 8 4 8 0 … … 0 0 0 0 … … Finally. To determine the investment allocations to achieve this profit.6. and the given table shows that 2 units ($2. that is. this tells us that we should allocate 2 units to Product A .55) with decision dA ( 4 ) = 2 We complete the table by entering the values of Stage A in the last two rows as shown in Table 16. Table 16. Third Edition Copyright © Orchard Publications 16−13 . with j = A and u = 4 v A ( 4 ) = max { p A ( 0 ) + v B ( 4 – 0 ). Therefore.54) (16. all 4 units can be allocated to the Product A or some of these can be allocated to Products B and C. all possibilities have been considered. p A ( 2 ) +v B ( 4 – 2 ).000. p A ( 4 ) + v B ( 4 – 4 ) } (16.Dynamic Programming TABLE 16.53) or v A ( 4 ) = max { 0 + 8.000.000. and thus the maximum profit is $9. The only entries are in the last column. we start with d A ( 4 ) = 2 . and this is always the case since in deriving v A ( 4 ) and d A ( 4 ) . 2 + 6. Numerical Analysis Using MATLAB® and Excel®.6 indicates that the maximum profit is realized with v A ( 4 ) = 9 .000. 7 + 0 } = 9 (16. p A ( 1 ) + v B ( 4 – 1 ). p A ( 3 ) + v B ( 4 – 3 ). v A ( 4 ) considers all possibilities.

AD . This tells us that we should not invest any units in Product B if only two units are left.000.6.6 Updated table to include values for all stages u 0 Stage C Stage B Stage A vC ( u ) dC ( u ) vB ( u ) dB ( u ) vA ( u ) dA ( u ) 0 0 0 0 … … 1 1 1 1 1 … … 2 4 2 4 0 … … 3 5 3 6 3 … … 4 8 4 8 0 9 2 We now have two units left to invest in Products B and C. Thus. Since two out of the four units have already been invested.3 Network Analysis A network. and by reference to the Table 16. to obtain the maximum profit of $9. as defined here. BE . and 6 branches AB . Third Edition Copyright © Orchard Publications . A typical network 16−14 Numerical Analysis Using MATLAB® and Excel®. The decision at Stage C yields d C ( 4 – 0 – 2 ) = d C ( 2 ) . two units to Product C to earn $4. This indicates that we should invest the remaining two units to Product C where we can obtain a return of $4. AC . To find out where we should invest these units.8. C . we should allocate: 1.000 16.000.6. we consider the decision at Stage B. is a set of points referred to as nodes and a set of lines referred to as branches. two units to Product A to earn $5.8 is a network with 5 nodes A .000. BD .000.000. D and E . we see that d 2 ( 2 ) = 0 . B . In summary.000 2.000. B E A D C Figure 16. and from Table 16. d C ( 2 ) = 2 . we have d B ( 4 – 2 ) = d B ( 2 ) . zero units to Product B to earn $0 3. Figure 16. and CD .Chapter 16 Optimization Methods TABLE 16.

B E A C D Figure 16.12 represents a network for a project that requires telephone cable be installed to link 7 towns.11. A network which is not connected A tree is a connected network which has n branches and n + 1 nodes. the network of Figure 16.10 is not connected since the branch CD is removed.8.10. if they have a direction assigned to them. Thus. Third Edition Copyright © Orchard Publications 16−15 .9.11 is a tree network. or two−way.Network Analysis Branches can be either directed (or oriented). if there is a path (branch) connecting each pair of nodes. the network of Figure 16. the branches indicate possible paths. In such problems. B E A D C Figure 16. Example 16. and the numbers beside the Numerical Analysis Using MATLAB® and Excel®. one−way. A network is said to be connected. that is. are directed but the others are not.5 Figure 16. If no direction is assigned. For example. the network shown in Figure 16. A tree network Network analysis is a method that is used to solve minimum span problems. A network which is connected The network of Figure 16. The towns are the nodes. and the sum of the costs (shortest total distance) is a minimum. However. they are considered to be two−way. Thus.9 is also connected.8 is connected. B E A D Figure 16. we seek to find a tree which contains all nodes. the branches BD and BE in Figure 16.

Network of Example 16. AD = 5. the least amount of telephone cable required to link each town. B 3 A 4 C 5 4 10 5 D 5 F 8 6 7 2 E 5 G Figure 16. By inspection.5 with no connections We observe that there are 3 branches associated with node A . show the distance (not to scale) between towns in kilometers.5 Solution: For convenience.e.56) we find that branch AB is the shortest. Network for Example 16. and we arbitrarily choose A as the starting node.14. AB . AD . B 3 A 4 C 5 4 10 5 8 E 6 7 5 F 2 5 G D Figure 16. and AC . we redraw the given network with dotted lines as shown in Figure 16.13.13.5 with first connection 16−16 Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications . Network of Example 16. B 3 A 4 C 5 4 10 5 D 5 F 8 6 7 2 E 5 G Figure 16.Chapter 16 Optimization Methods branches. that is.14. AC = 4 } = AB = 3 (16.12. We accept this branch as the first branch of the minimum span tree and we draw a solid line from Node A to Node B as shown in Figure 16. i. or from the expression min { AB = 3. Find the minimal spanning tree..

Network Analysis Next. DE = 6. AC is connected to the network as shown in Figure 16. B and C . BE = 8. The dotted lines AD and BD have been removed since we no longer need to consider branch AD and BD . considering all branches associated with Nodes B .15. we will not have a tree network.5 with the third connection Next. BD = 5. B 3 A 4 C 4 10 8 D 5 F E 6 7 2 5 G Figure 16. CD = 4. We find that the minimum of these is min { AD = 5. we consider all branches associated with Nodes A and B . and D and we find that the shortest is min { BE = 8. BD = 5. Numerical Analysis Using MATLAB® and Excel®. Network of Example 16. B 3 A 4 C 5 4 10 5 8 E 6 7 5 F 2 5 G D Figure 16. otherwise. BE = 8 } = AC = 4 (16.16.17. and we find that the shortest is min { AD = 5. Third Edition Copyright © Orchard Publications 16−17 . DF = 5. C .58) and we add branch CD to the network shown in Figure 16.15. CF = 10 } = DF = 5 (16. CF = 10 } = CD = 4 (16.16. Network of Example 16.5 with the second connection We continue by considering all branches associated with Nodes A . because Nodes B and D are already connected.57) and thus.59) and the network now is connected as shown in Figure 16. AC = 4. DG = 7.

5 with the fourth connection Continuing.5 with the fifth connection The last step is to determine the shortest branch to Node G .19 shows that the minimum distance is 3 + 4 + 4 + 6 + 5 + 2 = 24 kilometers.18.60) and the network is connected as shown in Figure 16. we obtain min { BE = 8. We find that min { EG = 5.19. DE = 6. Network of Example 16.61) and the complete minimum span tree is shown in Figure 16. DG = 7.5 with all connections Figure 16.19.17. Network of Example 16.18 B 3 A 4 C 4 D 5 F 6 7 2 E 5 G Figure 16. FG = 2 } = FG = 2 (16. DG = 7 } = DE = 6 (16. Third Edition Copyright © Orchard Publications .Chapter 16 Optimization Methods B 3 A 4 C 4 8 6 D 5 F 7 2 E 5 G Figure 16. 16−18 Numerical Analysis Using MATLAB® and Excel®. Network of Example 16. B 3 A 4 C 4 D 5 F 2 6 G E Figure 16.

Third Edition Copyright © Orchard Publications 16−19 . • A network. Bellman’s Principle of Optimality which states that an optimum policy has the property that whatever the initial state and the initial decisions are. the remaining decisions must constitute an optimum policy with regard to the state resulting from the first decision. referred to as the objective. is a set of points referred to as nodes and a set of lines referred to as branches. which is dependent on a finite number of variables. • A tree is a connected network which has n branches and n + 1 nodes. In such problems.4 Summary • Linear programming is a procedure we follow to maximize or minimize a particular quantity. we seek to find a tree which contains all nodes. • Dynamic Programming is based on R. • Network analysis is a method that is used to solve minimum span problems.Summary 16. and in most cases are subject to certain conditions or limitations referred to as constraints. and the sum of the costs (shortest total distance) is a minimum. as defined in this chapter. These variables may or may not be independent of each another. Numerical Analysis Using MATLAB® and Excel®.

Repeat Example 16.3 for the line graph shown below.Chapter 16 Optimization Methods 16.00 per barrel from one oil refinery company. D 2 B 3 A 5 2 C 1 7 5 4 1 E 3 4 F 6 L 4 5 K 3 6 4 4 J 2 H 2 7 16−20 Numerical Analysis Using MATLAB® and Excel®.00 per barrel from another oil refinery company. The line segments are directed from left to right and the costs are indicated beside each line segment. d 8 b 3 a 5 c 4 6 f 7 5 e 4 k 5 3 5 h 4 m 3. How many barrels of each grade of oil should he buy so that after mixing the two grades can minimize his cost while at the same time meeting EPA’s requirement? Solve this problem graphically and check your answers with Excel’s Solver. He can also buy Grade B oil which contains 15% lead for $20. The Environmental Protection Agency (EPA) requires that all oil sold must not contain more than 10% lead.5 Exercises 1. Third Edition Copyright © Orchard Publications . 2. A large oil distributor can buy Grade A oil which contains 7% lead for $25. Use dynamic programming to find the minimum cost route from state a to state m for the line graph shown below.

Third Edition Copyright © Orchard Publications 16−21 . The third row (zero hours) indicates the commission that he will receive if he just calls instead of visiting them. Consider only integer number of visiting hours. and ignore travel time from customer to customer. Compute the optimal allocation of time that he should spent with his customers so that he will maximize the sum of his commissions. Repeat Example 16. A salesman has 4 hours available to visit 4 of his customers. He will earn the commissions shown on the table below for various visiting times.Exercises 4. Visit Time (Hours) 0 1 2 3 4 Customer 1 $20 $45 $65 $75 $83 2 $40 $45 $57 $61 $69 3 $40 $52 $62 $71 $78 4 $80 $91 $95 $97 $98 5. B 30 40 A 50 20 C 40 D 50 F 50 90 70 E Numerical Analysis Using MATLAB® and Excel®.5 for the network shown below.

10 ⁄ 0. z = 25x + 20y (1) We want to minimize (1) because it represents a cost.07 = 10 ⁄ 7 . therefore x≥0 y ≥ 0 (4) The problem then can be stated as: Minimize (1) subject to the constraints of (2).10 (2) The oil of Grade A and Grade B used in each barrel to be sold must be equal to unity.15 = 2 ⁄ 3 and if y = 0 .15y ≤ 0. not a profit.10 ⁄ 0.10 8⁄7 9 ⁄ 7 10 ⁄ 7 x The isoprofit line passes through point b and its coordinates are found by simultaneous solu- 16−22 Numerical Analysis Using MATLAB® and Excel®.07x + 0. x = 0. and if y = 0 . Third Edition Copyright © Orchard Publications . Each barrel to be sold must not contain more than 10 % lead and since Grade A contains 7 % and Grade B 15 % . if x = 0 .15y = 0. if x = 0 . for simplicity. Thus. x = 1 . x + y = 1 (3) Moreover. y = 1 . we must have 0.Chapter 16 Optimization Methods 16.6 Solutions to End−of−Chapter Exercises 1. To determine the feasible region we plot (2) and (3) where the x and y crossings are found by first setting x = 0 and then y = 0 . from (3). Likewise. x and y cannot be negative numbers. y 1 Isoprofit line x+y = 1 2⁄3 a 1⁄3 b c 1⁄7 2⁄7 3⁄7 4⁄7 5⁄7 6⁄7 1 0. y = 0. and (4). Thus from (2).00x + $20.00y or. (3).07x + 0. The objective is to minimize z = $25. Let x be the number of barrels of Grade A oil and y be the number of barrels of Grade B oil.

1 1. Enter zeros in B12 and B13 2. From the Tools drop menu select Solver . [x.= 185 = $23. For convenience. The isoprofit line is z = 25x + 20y = 23.Solutions to End−of−Chapter Exercises tion of (2) and (3).15*B13 and in B18 =B12+B13 4. Third Edition Copyright © Orchard Publications 16−23 .125 -------8 8 8 and this represents his cost per barrel.125 Lead Content= 0.125 and the y −intercept is found by setting x in the equation above to zero and we find that y – intercept = 23. Solve Grade A= 0. we use the following MATLAB script: syms x y.625002 Grade B= 0. Add B17<=0. Add B13>=0.Minimum Cost for Exercise 16.1563 Check with Excel’s Solver: A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 B C D E F Optimization . In B15 enter =25*B12+20*B13 3. On the Solver Parameters screen enter the following: Set Target Cell: B15 Equal to: Min By Changing Cells: B12:B13 Click on Add and enter Constraints: B12>=0.07*B12+0. the distributor should buy Grade A oil at the ratio x = 5 ⁄ 8 and Grade B at the ratio y = 3 ⁄ 8 and by substitution into (1) 5 3 z = 25 × -. In B17 enter =0. x+y−1) x = 5/8 y = 3/8 Therefore.07*x+0.10.000001 Note: Contents of A12:A18 are typed-in for information only Numerical Analysis Using MATLAB® and Excel®.10 Grade A + Grade B= 1.10.+ 20 × -.15*y−0. 5. Add B18=1.374999 Minimum Cost= $23.125 ⁄ 20 = 1.y]=solve(0. OK . Use Add-Ins if necessary to add it.

5 + g e } = min { 8 + 5. g J = 2 . 5 + 11 } = 15 Thus. Next. 5 + g c } = min { 3 + 12. g b = min { 8 + g d. Third Edition Copyright © Orchard Publications .Chapter 16 Optimization Methods 2. the best (shortest) path is a → b → e → h → m 3. g K = 3 . 5 + 7 } = 12 and g c = min { 4 + g e. g a = min { 3 + g b. 4 + g k } = min { 3 + 4. 6 + 7 } = 11 Finally. and g L = 4 16−24 Numerical Analysis Using MATLAB® and Excel®. the best route from state e to state m passes through state h . Last stage: g H = 2 . 6 + g f } = min { 4 + 7. 4 + 5 } = 7 Therefore. state e is the first node where a decision must be made and thus g e = min { 3 + g h. d 8 b 3 a 5 c 4 6 f 7 5 e 4 k 5 3 5 h 4 m Since the segments are directed from left to right. D 2 B 3 A 5 2 C 1 7 5 4 1 E 3 4 F 6 L 4 5 K 3 6 4 4 J 2 H 2 7 The numbers in circles represent the waiting time at these nodes.

Solution A salesman has 4 hours available to visit of his customers. 5 + g C } = 17 from A to B Therefore. 4 + g E } = 5 + 9 = 14 g C = 2 + min { 7 + g E. 4 + g J } = 1 + 6 = 7 g E = 3 + min { 4 + g J. Visit Time (Hours) 0 1 2 3 4 Solution We will follow the same method as in Example 16. The third row (zero hours) indicates the commission that he will receive if he just calls instead of visiting them.4 . 5 + g K } = 3 + 6 = 9 g F = 4 + min { 7 + g K. 4. Consider only integer number of visiting hours. 1 $20 $45 $65 $75 $83 Customer 2 $40 $45 $57 $61 $69 3 $40 $52 $62 $71 $78 4 $80 $91 $95 $97 $98 continued on the next page Numerical Analysis Using MATLAB® and Excel®. minimum path is from A → B → D → J and the numerical minimum cost is 17 . Compute the optimal allocation of time that he should spend with his customers so that he will maximize the sum of his commissions. Third Edition Copyright © Orchard Publications 16−25 . and ignore travel time from customer to customer.Solutions to End−of−Chapter Exercises Next stage to the left: g D = 1 + min { 6 + g H. 6 + g L } = 4 + 10 = 14 from D to J from E to J from F to K or F to L Next to initial stage: g B = 5 + min { 2 + g D. 1 + g F } = 2 + 15 = 17 from B to D from C to F Initial stage: g A = 0 + min { 3 + g B. A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 B C D E F G H Exercise 16.4 It is convenient to rearrange the table as shown below. He will earn the commissions shown on the table below for various visiting times.

Chapter 16 Optimization Methods A 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 f(x) \ x f1(x) f2(x) f3(x) f4(x) B 0 20 40 40 80 C 1 45 45 52 91 D u 2 65 57 62 95 E 3 75 61 71 97 F 4 83 69 78 98 G H I m4(4)= max(B26. u 0 m4(u) d4(u) m3(u) d3(u) m2(u) d2(u) m1(u) d1(u) Next.D25+B38) m3(1)=max[f3(0)+m4(1-0).D26. f3(1)+m4(3-1).C26) m4(1)= max(B26) The values of m4(u) and d4(u) are entered in the table below.C26.E25+C38. f3(3)+m4(3-3)] MAX(B25+E38. Third Edition Copyright © Orchard Publications . 16−26 Numerical Analysis Using MATLAB® and Excel®.D25+C38.C26. f3(2)+m4(4-2).D26) m4(1)= max(B26. f3(1)+m4(4-1). f3(2)+m4(2-2)] MAX(B25+D38.D25+D38.E25+B38) m3(2)=max[f3(0)+m4(2-0).C25+C38.C25+E38. f3(4)+m4(4-4)] MAX(B25+F38.F26) m4(3)= max(B26.D26. f3(1)+m4(2-1). f3(1)+m4(1-1)] MAX(B25+C38.F25+B38) m3(3)=max[f3(0)+m4(3-0).E26) m4(2)= max(B26. we compute the values of m3(u) and d3(u) m3(4)=max[f3(0)+m4(4-0).E26. f3(3)+m4(4-3).C26.C25+D38.C25+B38) m3(0)=max[f3(0)+m4(0-0)] MAX(B25+B38) 80 0 120 0 160 0 1 91 1 132 1 172 0 2 95 2 143 1 183 0 3 97 3 153 2 193 0 4 98 4 162 3 202 0 248 2 98 with d4(4)= 97 with d4(3)= 95 with d4(2)= 91 with d4(1)= 80 with d4(0)= 4 3 2 1 0 162 with d3(4)= 3 153 with d3(3)= 2 143 with d3(2)= 1 132 with d3(1)= 1 120 with d3(0)= 0 continued on the next page. f3(2)+m4(3-2).

Third Edition Copyright © Orchard Publications 16−27 .C23+E42. f2(1)+m3(4-1).D24+B40) m2(1)=max[f2(0)+m3(1-0). f2(4)+m3(4-4)] MAX(B24+F40.F23+B42) These two values are the last entries into the table in Cells F44 and F45 The table (Rows 36 through 45) indicates that. f2(2)+m3(3-2). f2(1)+m3(2-1).E24+B40) m2(2)=max[f2(0)+m3(2-0). u=4.D24+D40.C24+E40.Solutions to End−of−Chapter Exercises A 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 B C D E F G H I These values are now added to the table above. we compute the values of m2(u) and d2(u) m2(4)=max[f2(0)+m3(4-0). f1(1)+m2(4-1). 0 hours = Customer #3. 2 hours = Customer #2.D24+C40. and for the remaining 2 hours he should spend 1 hour with Customer #3 and 1 hour with Customer #4. f2(1)+m3(3-1). Rows 42 and 43 Stage 1 is the last stage and there is only one state associated with it. f2(2)+m3(2-2)] MAX(B24+D40. and thus m1(4)=max[f1(0)+m2(4-0). the salesman should spend 2 hours with Customer #1 (d1(4)=2). 1 hour = Total = $65 $40 $52 $91 $248 202 with d2(4)= 0 193 with d2(3)= 0 183 with d2(2)= 0 172 with d2(1)= 0 160 with d2(0)= 0 248 with d1(4)= 2 Numerical Analysis Using MATLAB® and Excel®.C24+B40) m2(0)=max[f2(0)+m3(0-0)] MAX(B24+B40) These values are added to the table above.E24+C40. f1(2)+m2(4-2).C24+C40. f1(3)+m2(4-3).D23+D42.E23+C42.C24+D40. f2(1)+m3(1-1)] MAX(B24+C40. Rows 40 and 41 Similarly. f2(3)+m3(3-3)] MAX(B24+E40. f2(2)+m3(4-2). f1(4)+m2(4-4)] MAX(B23+F42.F25+B40) m2(3)=max[f2(0)+m3(3-0). to achieve the maximum sum of commissions. f2(3)+m3(4-3). Check: Customer #1. 0 hours with Customer #2 (d2(4)=0). 1 hour = Customer #4.

B 30 40 A 50 20 C 40 D 50 F 50 90 70 E min [ A → B. D → E. A → C ] = min [ 30. 50. C → F ] = min [ 50. 70 ] = 50 B 30 40 A 20 D 50 E C 40 F and thus the minimum distance is 20 + 30 + 40 + 40 + 50 = 180 kilometers 16−28 Numerical Analysis Using MATLAB® and Excel®. 50. 90. B → E.Chapter 16 Optimization Methods 5. C → D. D → F. C → F ] = min [ 40. 50. 40 ] = 40 min [ B → E. 50. C → D. 90. C → F ] = min [ 30. F → E ] = min [ 50. D → E. 20 ] = 20 A→C A→B choose B → D C→F B→E min [ A → B. 40 ] = 40 min [ B → E. Third Edition Copyright © Orchard Publications . 40 ] = 30 min [ B → D.

The three steps are as follows: 1. ISBN 0-9744239-9-8.1) is the same as that used for solving second−order differential equations. Obtain the natural response (complementary solution) y C ( n ) in terms of two arbitrary real constants k 1 and k 2 . This difference equation expresses the output y ( n ) at time n as the linear combination of two previous outputs y ( n – 1 ) and y ( n – 2 ) . each term of which is determined by application of a formula to preceding terms. † Newton’s method is discussed in Chapter 2.1) where a 1 and a 2 are constants and the right side is some function of n . Third Edition. The right side of relation (A. While recursive methods yield a desired result. The general (closed-form) solution of relation (A.2 Method of Undetermined Coefficients A second−order difference equation has the form y ( n ) + a1 y ( n – 1 ) + a2 ( n – 2 ) = f ( n ) (A. such as a polynomial. A. Third Edition Copyright © Orchard Publications A−1 . An example of a recursive method is Newton’s method† for solving non−linear equations. that is. we can solve difference equations using the Method of Undetermined Coefficients. Higher−order difference equations of this type and their solution is facilitated with the Z−transform. and this method is similar to the classical method of solving linear differential equations with constant coefficients. If a closed−form solution is desired.1 Recursive Method for Solving Difference Equations In mathematics.2) 2. yC ( n ) = k1 a1 + k2 a2 n n (A. they do not provide a closed−form solution.1) is referred to as the forcing function. * For an introduction and applications of the Z-transform please refer to Signals and Systems with MATLAB Computing and Simulink Modeling. a recursion is an expression. where a 1 and a 2 are also real constants. This method is described in the next section. Numerical Analysis Using MATLAB® and Excel®. The solution of a difference equation is often obtained by recursive methods.* A.Appendix A Difference Equations in Discrete−Time Systems T his appendix is a treatment of linear difference equations with constant coefficients and it is confined to first− and second−order difference equations and their solution. Obtain the forced response (particular solution) y P ( n ) in terms of an arbitrary real constant k 3 .

that is.* TABLE A. A−2 Numerical Analysis Using MATLAB® and Excel®.4). It is important to remember that the constants k 1 and k 2 must be evaluated from the total solution of (A. 3. yP ( n ) = k3 a3 n (A. Also. we must multiply y P ( n ) by the lowest power of n that will eliminate the duplication. y ( n ) = yC ( n ) + yP ( n ) = k1 a1 + k2 a2 + yP ( n ) n n (A.5) subject to the initial conditions y ( – 2 ) = 25 and y ( – 1 ) = 6 . we must remember that if f ( n ) is the sum of several terms. Third Edition Copyright © Orchard Publications . Solve for k 1 and k 2 in (A. Example A. the most general form of the particular solution y P ( n ) is the linear combination of these terms.1 Forms of the particular solution for different forms of the forcing function Form of forcing function Form of particular solutiona Constant an − a is a constant ab ±n k k − a constant k 0 + k 1 n + k 2 n + … + k k n − k i is constant Expression proportional to b k 1 cos ( nω ) + k 2 sin ( nω ) ±n 2 k − a and b are constants acos ( nω ) or asin ( nω ) a.3) where the right side of (A. Add the natural response (complementary solution) y C ( n ) and the forced response (particular solution) y P ( n ) to obtain the total solution.1 Find the total solution for the second−order difference equation 1 5 –n y ( n ) – -.3) is chosen with reference to Table A.4) 4. As in the case with the solutions of ordinary differential equations with constant coefficients. if a term in y P ( n ) is a duplicate of a term in the complementary solution y C ( n ) . It is best to illustrate the Method of Undetermined Coefficients via examples.Appendix A Difference Equations in Discrete-Time Systems that is.4) using the given initial conditions. not from the complementary solution y C ( n ) .y ( n – 2 ) = 5 6 6 n≥0 (A. * Ordinary differential equations with constant coefficients are discussed in Chapter 5.1.y ( n – 1 ) + -.

10) The roots of (A.8) Division of (A.⎞ 5 = 1 ⎝6⎠ ⎝6⎠ or k 3 = 1 and thus yP ( n ) = 5 –n (A.5).7) yields 5 n–1 1 n–2 n + -. Since the forcing function is 5 –n .6) The homogeneous equation of (A.12) and by substitution into (A. Third Edition Copyright © Orchard Publications A−3 .13).⎞ 5 + ⎛ -.8) by a n – 2 yields 5 2 -a – -.9) are 1 a 1 = -2 1 a 2 = -3 and by substitution into (A.5) is 5 1 y ( n ) – -.9) (A.a = 0 a – -.⎞ = k 1 2 + k 2 3 ⎝2⎠ ⎝3⎠ (A. y ( n ) = yC ( n ) + yP ( n ) = k1 2 + k2 3 + 5 –n –n –n (A. We assume that the complementary solution y C ( n ) has the form yC ( n ) = k1 a1 + k2 a2 n n (A.6) we obtain 1 n 1 n –n –n y C ( n ) = k 1 ⎛ -.Method of Undetermined Coefficients Solution: 1.13) The total solution is the addition of (A.⎞ 5 ⎝6⎠ ⎝6⎠ Division of both sides by 5 –n yields 1 2 5 k 3 1 – ⎛ -. 5 –( n – 1 ) 1 –( n – 2 ) –n –n + k 3 ⎛ -.y ( n – 1 ) + -.y ( n – 2 ) = 0 6 6 n≥0 (A.⎞ + k 2 ⎛ -.a 6 6 (A.⎞ 5 = 5 k 3 5 – k 3 ⎛ -. that is.11) and (A.a + 1 = 0 6 6 (A.7) Substitution of y ( n ) = a n into (A. we assume that the particular solution is yP ( n ) = k3 5 –n (A.14) Numerical Analysis Using MATLAB® and Excel®.11) 2.

1.4 1.14) we obtain the total solution as 3 –n –n 2 –n y ( n ) = y C ( n ) + y P ( n ) = ⎛ -.6 1.*3.18) To plot this difference equation for the interval 0 ≤ n ≤ 10 .1.16) yields 3 k 1 = -2 2 k 2 = – -3 (A.5. yn=1.8 1.⎞ 2 + ⎛ – -. 2 1. (A. stem(n. Plot for the difference equation of Example A.e.14) reduces to y ( – 2 ) = k 1 2 + k 2 3 + 5 = 25 2 2 2 from which For n = – 1 .⎞ 3 + 5 ⎝ 3⎠ ⎝2⎠ n≥0 (A.^(−n)+5. Third Edition Copyright © Orchard Publications .1 A−4 Numerical Analysis Using MATLAB® and Excel®.4 0.yn).16) Simultaneous solution of (A.14) reduces to 4k 1 + 9k 2 = 0 y ( –1 ) = k1 2 + k2 3 + 5 = 6 1 1 1 (A.^(−n)−(2.17) and by substitution into (A.Appendix A Difference Equations in Discrete-Time Systems To evaluate the constants k 1 and k 2 we use the given initial conditions.2 1 0.6 0. grid The plot is shown in Figure A.15) and (A..8 0. For n = – 2 . we use the following MATLAB script: n=0:1:10.^(−n).15) from which 2k 1 + 3k 2 = 1 (A. i.2 0 0 1 2 3 4 5 6 7 8 9 10 Figure A. s y ( – 2 ) = 25 and y ( – 1 ) = 6 ./3). (A.*2.

23) are -a1 = 1 2 a2 = 1 and by substitution into (A.a = 0 2 2 (A.a + -.y ( n – 1 ) + -.22) Division of (A.27) and by substitution of (A.1.Method of Undetermined Coefficients Example A. we choose the particular solution as yP ( n ) = k3 n + k4 3 –n (A. To avoid the duplication.27) into (A.21) Substitution of y ( n ) = a n into (A.21) yields 3 n–1 1 n–2 n a – -. we would assume that the particular solution is yP ( n ) = k3 + k4 3 –n (A.24) The roots of (A. Since the forcing function is 1 + 3 –n . that is.26) contain common terms. Third Edition Copyright © Orchard Publications A−5 .⎞ + k 2 ( 1 ) = k 1 2 + k 2 ⎝2⎠ (A.= 0 2 2 (A.y ( n – 2 ) = 1 + 3 2 2 n≥0 (A.19) we obtain Numerical Analysis Using MATLAB® and Excel®.19) is 1 3 y ( n ) – -.23) (A. we observe that both relations (A.y ( n – 2 ) = 0 2 2 n≥0 (A.25) and (A. the constants k 2 and k 3 .a + -.20) The homogeneous equation of (A.26) However. in accordance with the first and third rows of Table A.2 Find the total solution for the second−order difference equation 1 3 –n y ( n ) – -.25) 2.y ( n – 1 ) + -. We assume that the complementary solution y C ( n ) has the form yC ( n ) = k1 a1 + k2 a2 n n (A.19) subject to the initial conditions y ( – 2 ) = 0 and y ( – 1 ) = 2 Solution: 1.20) we obtain 1 n n –n y C ( n ) = k 1 ⎛ -.22) by a n – 2 yields 3 2 1 a – -.

k3 = 2 k4 = 1 By substitution into (A.⎞ k 4 3 = 1 + 3 ⎝2 ⎠ ⎝2⎠ ⎝2 ⎠ ⎝2 ⎠ 2 3 –n –n k 4 3 + ⎛ -.30) and (A.⎞ k 3 – k 3 = 1 + 3 ⎝2 ⎠ Equating like terms.⎞ k 4 3 + -.28).29) To evaluate the constants k 1 and k 2 we use the given initial conditions.Appendix A Difference Equations in Discrete-Time Systems 3 3 1 1 –n –( n – 1 ) –( n – 2 ) –n k 3 n + k 4 3 – ⎛ -.⎞ k 3 ( n – 1 ) – ⎛ -.29) we obtain the total solution as A−6 Numerical Analysis Using MATLAB® and Excel®. i. y P ( n ) = 2n + 3 –n (A.e.31) Simultaneous solution of (A.. s y ( – 2 ) = 0 and y ( – 1 ) = 2 .⎞ k 4 3 = 1+3 ⎝2 ⎠ ⎝2⎠ ⎝2⎠ 2 3 1 9 3 9 –n –n –n –n k 3 n + k 4 3 – ⎛ -.k 3 ( n – 2 ) + ⎛ -.32) and by substitution into (A.27). we obtain ⎛ 3 ⎞k – k = 1 -3 ⎝2 ⎠ 3 k4 3 –n = 3 –n and after simplification.⎞ k 4 3 + -.31) yields k1 = –3 k2 = 7 (A.29) reduces to y ( –1 ) = k1 2 + k2 – 2 + 3 = 2 1 1 from which 2k 1 + k 2 = 1 (A. Third Edition Copyright © Orchard Publications .⎞ k 3 – ⎛ -.k 3 n – k 3 + ⎛ -.⎞ k 3 n + ⎛ -. (A.28) The total solution is the addition of (A. (A.25) and (A. For n = – 2 .30) For n = – 1 . y ( n ) = y C ( n ) + y P ( n ) = k 1 2 + k 2 + 2n + 3 –n –n (A. that is.29) reduces to y ( –2 ) = k1 2 + k2 – 4 + 9 = 0 2 from which 4k 1 + k 2 = – 5 (A.

34) subject to the initial condition y ( – 1 ) = 5 Solution: 1.9y ( n – 1 ) = 0 n≥0 (A. yn=(−3). grid 30 25 20 15 10 5 0 0 1 2 3 4 5 6 7 8 9 10 Figure A.2 Example A.^(−n).3 Find the total solution for the first-order difference equation y ( n ) – 0. Plot for the difference equation of Example A.34) is y ( n ) – 0.35) yields a – 0.*2. we use the following MATLAB script: n=0:1:10.*n+3.^(−n)+7+2.36) Substitution of y ( n ) = a n into (A.9 ) n–1 n≥0 (A.9a n n–1 = 0 (A.5 + ( 0.33) To plot this difference equation for the interval 0 ≤ n ≤ 10 .yn). stem(n.35) The homogeneous equation of (A.2.Method of Undetermined Coefficients y ( n ) = y C ( n ) + y P ( n ) = ( – 3 )2 + 7 + 2n + 3 –n –n n≥0 (A. Third Edition Copyright © Orchard Publications A−7 . We assume that the complementary solution y C ( n ) has the form yC ( n ) = k1 a n (A.37) Numerical Analysis Using MATLAB® and Excel®.9y ( n – 1 ) = 0.

41).9 ) n –1 n and after simplification.39) and (A.9 ) n–1 + 0.9 ) –1 n Equating like terms.9 ) – 0.42). Third Edition Copyright © Orchard Publications .43) A−8 Numerical Analysis Using MATLAB® and Excel®.35) we obtain y C ( n ) = k 1 ( 0.9 ) 0.9 ) n–1 0. we obtain 0.39) and (A.9 ) n .5 + ( 0.1.9k 3 n ( 0.9 ) – k 3 n ( 0.9 ) n (A. k2 = 5 ----k 3 = 10 9 By substitution into (A.9 ) – 0.9 ) ( 0.9 ) n and k 3 ( 0. we would assume that the particular solution is y P ( n ) = k 2 + k 3 ( 0.9 ) n–1 n–1 = 0.5 + ( 0. we observe that both relations (A.9 ) 9 (A.5 + ( 0.9 ) 0.9 ) 0.9 ) (n – 1) = 0.9 0.40) contain common terms.9 ) + k 3 ( 0. that is.9 ) = 0.9 (A. To avoid the duplication.9 ) n n n –1 n –1 = 0.5 + ( 0.n ( 0.9 + 0.37) by a n – 1 yields a – 0.9 ) ( 0. in accordance with the first and third rows of Table A.9 ) – 0.5 k 3 ( 0.9k 2 – 0.5 + ( 0.9 ) n (A. Since the forcing function is 0.9 ) + 5 9 (A.Appendix A Difference Equations in Discrete-Time Systems Division of (A.9k 3 ( n – 1 ) ( 0.38) and by substitution into (A. 10 n y P ( n ) = 5 + ----.39) 2.41) and by substitution of (A. the constants k 1 ( 0.9 ) + ----.40) However.9 = 0 a = 0.1k 2 + k 3 n ( 0.1k 2 + k 3 n ( 0.9 ) n n n (n – 1) n (n – 1) = 0.n ( 0.9 ) = ( 0.34) we obtain k 2 + k 3 n ( 0. 10 n n y ( n ) = y C ( n ) + y P ( n ) = k 1 ( 0.9 ) n – 1 . we choose the particular solution as y P ( n ) = k 2 + k 3 n ( 0. that is.9k 3 ( 0.5 + ( 0.9k 3 ( 0.1k 2 + k 3 n ( 0.9k 3 n ( 0.41) into (A.9 ) n (A.42) The total solution is the addition of (A.1k 2 = 0.

( – 1 ) ( 0. For n = – 1 .81y ( n – 2 ) = 2 –n n≥0 (A.3. Plot for the difference equation of Example A.44) and by substitution into (A.Method of Undetermined Coefficients To evaluate the constant k 1 we use the given initial condition. we use the following MATLAB script: n=0:1:10.45) To plot this difference equation for the interval 0 ≤ n ≤ 10 .yn).e.43) we obtain the total solution as y ( n ) = ( 0. y ( – 1 ) = 5 .9 ) +5 n–1 +5 y ( n ) = ( n + 1 ) ( 0.43) reduces to 10 –1 –1 y ( – 1 ) = k 1 ( 0.9 ) n–1 + n ( 0.^(n-1)+5. yn=(n+1).3 Example A.9 ) + 5 = 5 9 10 ----.9 ) + ----.9). stem(n.9 ) n–1 n≥0 (A.8y ( n – 1 ) + 0.. (A. i.k 1 – 100 = 0 -------9 81 from which 10 k 1 = ----9 (A. grid 10 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 8 9 10 Figure A.4 Find the total solution for the second−order difference equation y ( n ) – 1. Third Edition Copyright © Orchard Publications A−9 .46) Numerical Analysis Using MATLAB® and Excel®.*(0.

= ----0.81 )2 ] = 1 k 3 [ 1 – 3.48) yields a – 1.9 ) n n (A. We assume that the complementary solution y C ( n ) has the form yC ( n ) = k1 a1 + k2 a2 n n (A.8 )2 –n –( n – 1 ) + k 3 ( 0. 1.81y ( n – 2 ) = 0 n≥0 (A.6 + 3.46).9 and as in the case of ordinary differential equations.47) The homogeneous equation of (A.8a + 0.52) 2.8a n n–1 + 0. Since the forcing function is 2 –n .81 = 0 2 (A. we assume that the particular solution is yP ( n ) = k3 2 –n (A.50) (A.8 )2 + ( 0.49) Division of (A.64 16 2 A−10 Numerical Analysis Using MATLAB® and Excel®.9 ) + k 2 n ( 0.Appendix A Difference Equations in Discrete-Time Systems subject to the initial conditions y ( – 2 ) = 25 and y ( – 1 ) = 6 Solution: No initial conditions are given and thus we will express the solution in terms of the unknown constants. k 3 2 – k 3 ( 1.49) by a n – 2 yields a – 1. Third Edition Copyright © Orchard Publications .81 )2 = 2 –n Division of both sides by 2 –n yields k 3 [ 1 – ( 1. that is.81a n–2 = 0 (A.50) are repeated roots. we accept the complementary solution to be of the form y C ( n ) = k 1 ( 0.24 ] = 1 1 25 k 3 = --------.48) Substitution of y ( n ) = a n into (A.51) The roots of (A.8y ( n – 1 ) + 0.53) –( n – 2 ) and by substitution into (A.46) is y ( n ) – 1. a 1 = a 2 = 0.

9 ) + ⎛ ----.⎞ ⎝ 2⎠ ⎝ 2⎠ (A.81y ( n – 2 ) = ( 0.57).52) and (A.9 ) + k 2 n ( 0. Third Edition Copyright © Orchard Publications A−11 .1 indicates that a good choice for the particular solution would be k 3 ( 0.6 Find the particular solution for the first-order difference equation nπ y ( n ) – 0. the particular solution has the form nπ nπ y P ( n ) = k 1 sin ⎛ ----. 25 –n n n y ( n ) = y C ( n ) + y P ( n ) = k 1 ( 0.54) The total solution is the addition of (A.9 ) 2 n (A.54).⎞ 2 ⎝ 16 ⎠ (A.57) Row 3 in Table A.8y ( n – 1 ) + 0.4 where the forcing function is ( 0. the proper choice would be y P ( n ) = k 3 n ( 0. Therefore.⎞ ⎝2⎠ n≥0 (A.9 ) n but this is of the same form as the second term on the right side of (A.9 ) n n (A. But this is of the same form as the first term on the right side of (A.9 ) n instead of 2 –n where we found that the complementary solution is y C ( n ) = k 1 ( 0.5y ( n – 1 ) = sin ⎛ ----.9 ) + k 2 n ( 0.9 ) n .⎞ 2 ⎝ 16 ⎠ (A.⎞ + k 2 cos ⎛ ----.55) Example A.1 we see that for a sinusoidal forcing function.56) what would be the appropriate choice for the particular solution? Solution: This is the same difference equation as that of Example A.Method of Undetermined Coefficients and thus 25 –n y P ( n ) = ⎛ ----.57).60) Numerical Analysis Using MATLAB® and Excel®.9 ) n n≥0 (A.59) Solution: From Row 4 in Table A. The next choice would be a term of the form k 3 n ( 0.58) Example A. that is.5 For the second−order difference equation y ( n ) – 1.

⎞ = sin θ ⎝ 2⎠ Then.⎞ + k 2 cos ⎛ ----.5k 2 sin ⎛ ----.59) is nπ nπ 4 .= sin ⎛ ----.⎞ + k 2 cos ⎛ ----. sin ⎛ θ – π ⎞ = – cos θ -⎝ 2⎠ π cos ⎛ θ – -.k 1 sin ⎛ ----.59) nπ nπ ( n – 1 )π ( n – 1 )π nπ k 1 sin ⎛ ----.⎞ – 0.5k 1 + k 2 = 0 (A.65) A−12 Numerical Analysis Using MATLAB® and Excel®. Third Edition Copyright © Orchard Publications .5k 2 cos ------------------.⎝ 2 ⎠ 2 2 nπ nπ π cos ----.61) nπ nπ nπ nπ nπ k 1 sin ⎛ ----. nπ nπ π sin ----.⎞ ⎝2⎠ ⎝ 2⎠ ⎝ 2⎠ 2 2 2 2 (A.64) and simultaneous solution of (A. we obtain k 1 – 0.⎞ ⎝ 2⎠ ⎝ 2⎠ 5 5 (A..⎞ ⎝ 2⎠ ⎝ 2⎠ ⎝2⎠ 2 2 nπ nπ nπ nπ π nπ π .– -.63) and (A.-y P ( n ) = -.⎞ ⎝ 2⎠ ⎝ 2⎠ ⎝ 2⎠ ⎝ 2⎠ ⎝2⎠ (A.– -.⎞ – 2 cos ⎛ ----. the particular solution of (A.⎞ + 0.5k 2 cos ----.Appendix A Difference Equations in Discrete-Time Systems and by substitution of (A.– 0.⎞ – 0.5k 1 cos ⎛ ----.⎝ 2 ⎠ 2 2 and by substitution into (A.61) From trigonometry.= sin ⎛ ----.63) (A.– 0.⎞ – 0.⎞ .⎞ .⎞ = sin ⎛ ----.64) yields 4 k 1 = -5 2 k 2 = – -5 Therefore.5k 1 sin ------------------.= – cos ⎛ ----.= sin ⎛ ----.60) into (A.5k 1 sin ----.– -.⎞ + k 2 cos ⎛ ----.– -.5k 2 = 1 0.sin ⎛ ----.62) Equating like terms.

1) into (B. Third Edition Copyright © Orchard Publications B−1 .5 V . simulate.1 For this example.1) and by Kirchoff’s voltage law (KVL).1. We will compute v c ( t ) .1. and thus we can analyze. it is highly recommended that the novice to MATLAB reader reviews Chapter 1 which serves as an introduction to MATLAB. Circuit for Example B. B. We will introduce Simulink with a few illustrated examples.1 Simulink and its Relation to MATLAB The MATLAB® and Simulink® environments are integrated into one entity. the initial conditions are i L ( 0 − ) = 0 . and v c ( 0 − ) = 0.2) Substitution of (B. Some familiarity with MATLAB is essential in understanding Simulink.1 For the circuit of Figure B. and revise our models in either environment at any point.+ v C = u 0 ( t ) dt (B. R L 1⁄4 H C 1Ω + vC ( t ) − + − i(t) 4⁄3 F vs ( t ) = u0 ( t ) Figure B. Example B. dv C i = i L = i C = C -------dt (B. di L Ri L + L -----. We invoke Simulink from within MATLAB. and for this purpose.Appendix B Introduction to Simulink® T his appendix is a brief introduction to Simulink.2) yields Numerical Analysis Using MATLAB® and Excel®. This author feels that we can best introduce Simulink with a few examples.

+ LC ---------.+ 4 -------. three different methods of obtaining the solution are presented.3 dt 2 3 dt dv C d vC ---------. Also. B−2 Numerical Analysis Using MATLAB® and Excel®.Introduction to Simulink® d vC dv C RC -------. Therefore. the total solution will –s1 t –s2 t v c ( t ) = natural response + forced response = v cn ( t ) + v cf ( t ) = k 1 e + k2 e + v cf ( t ) (B. decaying exponentials of the form ke where k and a are constants.+ 4 -------..+ -.+ 3v C = 3 2 dt dt 2 2 (B. non−homogeneous differential equation with constant coefficients. the natural response is the sum of the terms k 1 e be –s1 t –s t –s t – at and k 2 e –s2 t . Third Edition Copyright © Orchard Publications .+ v C = u 0 ( t ) .3) Substituting the values of the circuit constants and rearranging we obtain: 1 d v C 4 dv C -. However.6) The values of s 1 and s 2 are the roots of the characteristic equation * Please refer to Circuit Analysis II with MATLAB Applications.---------. are possible candidates since their derivatives have the same form but alternate in sign. It can be shown* that if k 1 e 1 and k 2 e 2 where k 1 and k 2 are constants and s 1 and s 2 are the roots of the characteristic equation of the homogeneous part of the given differential equation. and the solution using Simulink follows. First Method − Assumed Solution Equation (B.+ v C = u 0 ( t ) 2 dt dt 2 (B.5) To appreciate Simulink’s capabilities. and thus the complete solution will consist of the sum of the forced response and the natural response.5) is a second−order. Appendix B for a thorough discussion. It is obvious that the solution of this equation cannot be a constant since the derivatives of a constant are zero and thus the equation is not satisfied.+ 3v C = 3u 0 ( t ) 2 dt dt 2 dv C d vC ---------. ISBN 0−9709511−5−9.-------. the solution cannot contain sinusoidal functions (sine and cosine) since the derivatives of these are also sinusoids. for comparison.4) t>0 (B.

5 V and evaluating (B. and dv C dv C i L i L = i C = C -------. 2 dv C d vC ---------.+ 4 -------.14) we obtain Numerical Analysis Using MATLAB® and Excel®.5 k 1 + k 2 = – 0. By substitution into (B.= 0 C C (B.Simulink and its Relation to MATLAB s + 4s + 3 = 0 2 (B.7) yields of s 1 = – 1 and s 2 = – 3 and with these values (B. i.9) is a constant.11) The constants k 1 and k 2 will be evaluated from the initial conditions.10) Substitution of this value into (B.. First. the forced response will also be a constant and we denote it as v Cf = k 3 . Third Edition Copyright © Orchard Publications B−3 .8) The forced component v cf ( t ) is found from (B. -------.9) Since the right side of (B. and equate it with (B.13). dv C -------dt = – k 1 – 3k 2 t=0 (B. we evaluate it at t = 0 ..e. we obtain v C ( 0 ) = k 1 e + k 2 e + 1 = 0. using v C ( 0 ) = 0.12) Also.7) Solution of (B.+ 3v C = 3 2 dt dt t>0 (B.14) By equating the right sides of (B. yields the total solution as v C ( t ) = v Cn ( t ) + v Cf = k 1 e + k 2 e –t –3 t +1 (B.9) we obtain 0 + 0 + 3k 3 = 3 or v Cf = k 3 = 1 (B. Thus.5 0 0 (B.13) t=0 Next.11) at t = 0 .= --.6) is written as vc ( t ) = k1 e + k2 e –t –3 t + v cf ( t ) (B.5). we differentiate (B.13) and (B.11).= --dt dt C dv C -------dt iL ( 0 ) 0 = ----------.8).

Using the expression for v C ( t ) in (B. R 1 L 0.Introduction to Simulink® – k 1 – 3k 2 = 0 (B.25 .12) and (B.25s C 3 ⁄ 4s + VC ( s ) − Vs ( s ) = 1 ⁄ s + − I(s) 0.2.17) Second Method − Using the Laplace Transformation The transformed circuit is shown in Figure B.5 ⁄ s + V (0) C − Figure B. Transformed Circuit for Example B.1 B−4 Numerical Analysis Using MATLAB® and Excel®.75 and k 2 = 0.⎛ -. for our example. the solution has been verified by MATLAB.2) % The second derivative of y(t) y2 = -3/4*exp(-t)+9/4*exp(-3*t) y=y2+4*y1+3*y0 % Summation of y and its derivatives y = 3 Thus. By substitution into (B. we obtain the total solution as v C ( t ) = ( – 0.8).25*exp(−3*t)+1.2.75*exp(−t)+0. gives k 1 = – 0. vc(t) % The first derivative of y(t) y1 = 3/4*exp(-t)-3/4*exp(-3*t) y2=diff(y0.75 e + 0.16).15) Simultaneous solution of (B.i = i L = i C = C --------. y1=diff(y0) % Define symbolic variable t % The total solution y(t).e – 3 e ⎞ = e – e A -⎠ dt 3⎝ 4 4 (B..= -. Third Edition Copyright © Orchard Publications .25e –t –3 t + 1 )u 0 ( t ) (B.15). we find the expression for the current as dv C 4 3 –t – 3t – t – 3t .16) Check with MATLAB: syms t y0=−0.

– 0.= --.5⎞ + 0.5s + 2s + 3 r 3 = --------------------------------s(s + 1) 2 2 2 = 1 s=0 = – 0. please refer to Circuit Analysis I with MATLAB Applications.+ --------------s (s + 1) (s + 3) s(s + 1 )( s + 3) (B.5s + 2s + 3 r 1 = --------------------------------(s + 1)(s + 3) --------------------------------r 2 = 0. ‡ For an introduction to Laplace Transform and Inverse Laplace Transform. in State−Space and State Variables Analysis.-. Signals and Systems with MATLAB Computing and Simulinl Modeling.† we let 2 r2 r3 r1 0.75V C ( s ) = ----------------------------------.5 = -------------------------------.18) 0.5s + 2s + 3-. ISBN 0-9744239-9-8.25s + 3 ⁄ 4s ) ⎝ s s s ⎠ s s(s + 1)(s + 3) s ( s + 4s + 3 ) Using partial fraction expansion.5 . ISBN 09744239-9-8.25 0. † Partial fraction expansion is discussed in Chapter 12.Simulink and its Relation to MATLAB By the voltage division* expression. For distinction. we will denote the Unit Step Function as u0 ( t ) . this text.+ 0. 2 3 ⁄ 4s 0.-----. please refer to Chapters 2 and 3. Third Edition Copyright © Orchard Publications B−5 .25e –t – 3t Third Method − Using State Variables di L Ri L + L -----.+ v C = u 0 ( t ) ** dt * For derivation of the voltage division and current division expressions.75e + 0. ISBN 0−9709511−2−4.25 s = –3 and by substitution into (B.= 1 + --------------.5s + 2s + 3 s(s + 3) 0. For a detailed discussion on State−Space and State Variables Analysis.5 = ----------------------------------2 ( 1 + 0. Numerical Analysis Using MATLAB® and Excel®. ** Usually.⋅ ⎛ 1 – 0.+ --------------.75 s = –1 = 0.5s + 2s + 3----------------------------------.5s + 2s + 31.----------V C ( s ) = --------------------------------------------. Signals and Systems with MATLAB Computing and Simulinl Modeling.18) 0. u ( t ) denotes any input. please refer to Chapter 5.+ --------------s (s + 1) (s + 3) s(s + 1)(s + 3) 2 Taking the Inverse Laplace transform‡ we find that v C ( t ) = 1 – 0.

from (B. B−6 Numerical Analysis Using MATLAB® and Excel®.x 2 3 dt 3 · x 2 = -. we obtain the state equations · x 1 = – 4x 1 – 4x 2 + 4 3 · x 2 = -. · x x1 = –4 –4 1 + 4 u0 ( t ) ·2 3 ⁄ 4 0 x2 0 x (B.* dt (B.Introduction to Simulink® By substitution of given values and rearranging.19) Next.19). we define the state variables x 1 = i L and x 2 = v C . (B. we obtain di 1 ------.21) Also. and (B.= Cx 2 = -.23) yields · · * The notation x (x dot) is often used to denote the first derivative of the function x .= – 4i L – 4v C + 4 dt (B. Signals and Systems with MATLAB Computing and Simulinl Modeling.L = ( – 1 )i L – v C + 1 .23) Solution† of (B. and thus.x 1 4 and in matrix form.x 1 4 (B.20) and dv C · x 2 = -------dt (B.20).4 dt or di L -----. † The detailed solution of (B.23) is given in Chapter 5. or dv C i L = C -------dt dv C 4· · x 1 = i L = C -------. di L · x 1 = -----.22). x = dx ⁄ dt .22) Therefore. ISBN 0-9744239-9-8. Then. that is. Third Edition Copyright © Orchard Publications .

The right side is referred to as the Contents Pane and displays the blocks that reside in the library currently selected in the Tree Pane. we type: simulink Alternately.= – 4 -------.Simulink and its Relation to MATLAB x1 x2 = e –e –t –t – 3t – 3t 1 – 0. It appears on the top bar on MATLAB’s Command prompt.4.1 as 2 dv C d vC ---------.1 with Simulink To run Simulink. We will use Simulink to draw a similar block diagram.3.25e –t (B. the left side is referred to as the Tree Pane and displays all Simulink libraries installed. Third Edition Copyright © Orchard Publications B−7 . x1 = iL = e –e (B.5.25) Modeling the Differential Equation of Example B. Figure B. all Simulink block diagrams will be referred to as models. the Commonly Used Blocks appear as shown in Figure B. we can click on the Simulink icon shown in Figure B.75e + 0. we must first invoke MATLAB. The Simulink icon Upon execution of the Simulink command. Let us express the differential equation of Example B.4.25e –t – 3t Then.* * Henceforth.26) above is shown in Figure B.75 e + 0.3.26) A block diagram representing relation (B. In Figure B. Numerical Analysis Using MATLAB® and Excel®. Make sure that Simulink is installed in your system.24) – 3t and x 2 = v C = 1 – 0. In the MATLAB Command prompt.– 3v C + 3u 0 ( t ) 2 dt dt (B.

26) To model the differential equation (B.26) using Simulink.6.5. The Simulink Library Browser d vC ---------2 dt 2 u0 ( t ) 3 Σ ∫ dt −4 dv C -------dt ∫ dt vC −3 Figure B. we perform the following steps: 1. Third Edition Copyright © Orchard Publications . Block diagram for equation (B. A new model window named untitled will appear as shown in Figure B. we click on the leftmost icon shown as a blank page on the top title bar.4.Introduction to Simulink® Figure B. On the Simulink Library Browser. B−8 Numerical Analysis Using MATLAB® and Excel®.

We choose the gain block and we drag it to the right of the unit step function. and draw a straight line to connect the two Numerical Analysis Using MATLAB® and Excel®. If the Equation_1_26 model window is no longer visible. Figure B. it can be recalled by clicking on the white page icon on the top bar of the Simulink Library Browser. We save this as model file name Equation_1_26. With the Equation_1_26 model window and the Simulink Library Browser both visible. The gain block in Simulink is under Commonly Used Blocks (first item under Simulink on the Simulink Library Browser).8. See Figure B. The triangle on the right side of the unit step function block and the > symbols on the left and right sides of the gain block are connection points. Model window for Equation_1_26. 4.7.8).8. The Untitled model window in Simulink. 3. With reference to block diagram of Figure B.6. and we drag it into the Equation_1_26 model window which now appears as shown in Figure B.5. and all saved files will have this appearance. Third Edition Copyright © Orchard Publications B−9 . We select it. See Figure B.7.8.mdl file 2. we click on the Sources appearing on the left side list.Simulink and its Relation to MATLAB Figure B. The window of Figure B. we observe that we need to connect an amplifier with Gain 3 to the unit step function block. We point the mouse close to the connection point of the unit step function until is shows as a cross hair.6 where we choose Save as and name the file as Equation_1_26. This is done from the File drop menu of Figure B. The new model window will now be shown as Equation_1_26.mdl. We save file Equation_1_26 using the File drop menu on the Equation_1_26 model window (right side of Figure B.6 is the model window where we enter our blocks to form a block diagram. See Figure B. Simulink will add the extension . and on the right side we scroll down until we see the unit step function shown as Step.

Third Edition Copyright © Orchard Publications .9. and left−clicking on the destination block. Figure B.8. See Figure B. B−10 Numerical Analysis Using MATLAB® and Excel®. we change the gain from 1 to 3. Dragging the unit step function into File Equation_1_26 Figure B.9.* We double−click on the gain block and on the Function Block Parameters. then holding down the Ctrl key. File Equation_1_26 with added Step and Gain blocks * An easy method to interconnect two Simulink blocks is by clicking on the source block to select it.Introduction to Simulink® blocks.

Then.10.11.12. We repeat this step and to add a second Integrator block. Figure B. File Equation_1_26 with added gain block 6. We click on the text “Integrator” under the first integrator block. Third Edition Copyright © Orchard Publications B−11 . We flip the pasted Gain blocks by using the Flip Block command from the Format drop menu. and we connect it to the output of the Add block. we add the Scope block which is found in the Commonly Used Blocks on the Simulink Library Browser. we need to add a thee−input adder. we choose the Integrator block. File Equation_1_26 with the addition of two integrators 7. we change the text “Integrator 1” under the second Integrator to “Integrator 2” as shown in Figure B. and we copy and paste it twice.11. From the Commonly Used Blocks of the Simulink Library Browser.12. We double click it.10. we specify 3 inputs. We then connect the output of the of the gain block to the first input of the adder block as shown in Figure B. Next. we click on the Gain block. Figure B. we change the gains from to −4 and −3 as shown in Figure B. File Equation_1_26 complete block diagram Numerical Analysis Using MATLAB® and Excel®.Simulink and its Relation to MATLAB 5. we double−click on these gain blocks and on the Function Block Parameters window. We select it. and on the Function Block Parameters window which appears. Finally. and we drag it into the Equation_1_26 model window. To complete the block diagram. and we label these as Gain 2 and Gain 3. we drag it into the Equation_1_26 model window. The adder block appears on the right side of the Simulink Library Browser under Math Operations. and we change it to Integrator 1. Figure B.

5 for the second integrator.1. and v c ( 0 ) = 0.Introduction to Simulink® 8.1 with the State−Space block. as shown in Figure B.1 Another easier method to obtain and display the output v C ( t ) for Example B. Figure B. We also need to specify the simulation time. B−12 Numerical Analysis Using MATLAB® and Excel®. we obtain the waveform shown in Figure B.14.14. The waveform for the function v C ( t ) for Example B. we double click on the Scope block.5 V are entered by − double clicking the Integrator blocks and entering the values 0 for the first integrator.13. Figure B. To see the output waveform. and then clicking on the Autoscale icon.13. Third Edition Copyright © Orchard Publications . Obtaining the function v C ( t ) for Example B. This is done by specifying the simulation time to be 10 seconds on the Configuration Parameters from the Simulation drop menu. The initial conditions i L ( 0 − ) = C ( dv C ⁄ dt ) t=0 = 0 . and 0. We can start the simulation on Start from the Simulation drop menu or by clicking on the icon. is to use State− Space block from Continuous in the Simulink Library Browser. 9.

Figure B. We issue the command who to see those variables. Numerical Analysis Using MATLAB® and Excel®. · x1 x = –4 –4 1 + 4 u0 ( t ) ·2 3 ⁄ 4 0 x2 0 x The output equation is or y = Cx + du y = [0 1] x1 x2 + [ 0 ]u We double−click on the State−Space block. This block writes its output to an array or structure that has the name specified by the block's Variable name parameter.14 writes its input to the workspace. and in the Functions Block Parameters window we enter the constants shown in Figure B. This gives us the ability to delete or modify selected variables. Third Edition Copyright © Orchard Publications B−13 . reside in the MATLAB Workspace. The data and variables created in the MATLAB Command window. The Function block parameters for the State−Space block.15. Page B−6.23.15. From Equation B.Simulink and its Relation to MATLAB The simout To Workspace block shown in Figure B.

Third Edition Copyright © Orchard Publications .27) as a set of state equations B−14 Numerical Analysis Using MATLAB® and Excel®. The state−space block is the best choice when we need to display the output waveform of three or more variables as illustrated by the following example. and then clicking on the Autoscale obtain the waveform shown in Figure B.2 A fourth−order network is described by the differential equation 4 d y + a d y + a d y + a dy + a y ( t ) = u ( t ) --------3 -------2 ------1 ----0 3 2 4 dt dt dt dt 3 2 (B. we form.1 with the State−Space block. and to see the output waveicon. and the initial conditions are y ( 0 ) = y' ( 0 ) = y'' ( 0 ) = y''' ( 0 ) = 0 .Introduction to Simulink® The initials conditions [ x1 x2 ]' are specified in MATLAB’s Command prompt as x1=0. Example B.16. we double click on the Scope block. and u ( t ) is any input. x2=0.16. a. As before.27) where y ( t ) is the output representing the voltage or current of the network. The waveform for the function v C ( t ) for Example B. We will express (B.5. to start the simulation we click clicking on the icon. Figure B.

we will select appropriate values for the coefficients a 3.+ 2 ------.28). Third Edition Copyright © Orchard Publications B−15 . x 2. It is known that the solution of the differential equation 4 d y d y ------. we will display the waveform of the output y ( t ) . The differential equation of (B. and x 4 . we must define four state variables that will be used with the four first−order state equations.34) Also.31) and in matrix form · x1 · x2 · x3 · x4 0 0 = 0 –a0 1 0 0 –a1 0 1 0 –a2 0 0 1 –a3 0 x2 + 0 u(t) x3 0 1 x4 x1 (B.32) is written as · x = Ax + bu (B. and a 0 so that the new set of the state equations will represent the differential equation of (B.Simulink and its Relation to MATLAB b. therefore.29) In our set of state equations.125 [ ( 3 – t ) – 3t cos t ] 2 (B. 1. x 3 . the output is where y = Cx + du Numerical Analysis Using MATLAB® and Excel®.28) subject to the initial conditions y ( 0 ) = y' ( 0 ) = y'' ( 0 ) = y''' ( 0 ) = 0 .32) In compact form. and using Simulink.28) is of fourth−order. has the solution y ( t ) = 0. and we relate them to the terms of the given differential equation as x1 = y ( t ) dy x 2 = ----dt d y x 3 = -------2 dt 2 d y x 4 = -------3 dt 3 (B.30) We observe that · x1 = x2 · x2 = x3 · x3 = x4 d y · --------.= x 4 = – a 0 x 1 – a 1 x 2 – a 2 x 3 – a 3 x 4 + u ( t ) 4 dt 4 (B. We denote the state variables as x 1.33) (B. (B. a 1.+ y ( t ) = sin t 2 4 dt dt 2 (B. a 2.

0 b= 0.28) if we let a3 = 0 a2 = 2 a1 = 0 a0 = 1 u ( t ) = sin t and thus the differential equation of (B. By inspection. 0 1 · x= .37) where · x1 · x2 · x3 · x4 0 0 A= 0 –a0 1 0 0 0 0 1 0 –2 0 0 .34) is expressed as x1 y = [1 0 0 0] ⋅ x2 x3 x4 + [ 0 ]u ( t ) (B.35) and since the output is defined as relation (B.Introduction to Simulink® · x1 · x2 · x3 · x4 0 0 A= 0 –a0 1 0 0 –a1 0 1 0 –a2 0 0 .36) 2. and u = sin t (B.38) Since the output is defined as in matrix form it is expressed as B−16 Numerical Analysis Using MATLAB® and Excel®. 1 –a3 x1 x= x2 x3 x4 y ( t ) = x1 .27) will be reduced to the differential equation of (B.28) can be expressed in state−space form as · x1 · x2 · x3 · x4 0 0 = 0 –a0 1 0 0 0 0 1 0 –2 0 0 1 0 0 + 0 sin t x3 0 1 x4 x2 x1 (B. the differential equation of (B. 0 b= 0. and u = u ( t ) (B. 0 1 · x= . Third Edition Copyright © Orchard Publications . 1 0 x1 x= x2 x3 x4 y ( t ) = x1 .

Simulink and its Relation to MATLAB x1 y = [1 0 0 0] ⋅ x2 x3 x4 + [ 0 ] sin t (B. −a0 −a1 −a2 −a3] B: [0 0 0 1]’ C: [1 0 0 0] D: [0] Initial conditions: x0 Numerical Analysis Using MATLAB® and Excel®.17.17. we double−click on the state−space block and we enter the following parameter values in the Function Block Parameters: A: [0 1 0 0.2 We now double−click on the Signal Generator block and we enter the following in the Function Block Parameters: Wave form: sine Time (t): Use simulation time Amplitude: 1 Frequency: 2 Units: Hertz Next. 0 0 0 1. Third Edition Copyright © Orchard Publications B−17 . We connect these four blocks and the complete block diagram is as shown in Figure B. we drag the Signal Generator block on the Example_1_2 model window. and we save this model as Example_1_2. Block diagram for Example B. we click and drag the State−Space block from the Continuous on Simulink Library Browser. on the Simulink Library Browser we click on the Create a new model (blank page icon on the left of the top bar). Figure B. We also add the Display block found under Sinks on the Simulink Library Browser. we start Simulink by clicking on the Simulink icon.39) We invoke MATLAB. 0 0 1 0. and we click and drag the Scope block from the Commonly Used Blocks on the Simulink Library Browser. On the Simulink Library Browser we select Sources.

We change the Simulation Stop time to 25 .2 using four Integrator blocks by this approach would have been more time consuming. Waveform for Example B. and z 3 in the system of the equations a1 z1 + a2 z2 + a3 z3 + k1 = 0 a4 z1 + a5 z2 + a6 z3 + k2 = 0 a7 z1 + a8 z2 + a9 z3 + k3 = 0 (B. Figure B. z 2 .40) B−18 Numerical Analysis Using MATLAB® and Excel®.Introduction to Simulink® Absolute tolerance: auto Now. we double click on the Scope block. we will create a model that will produce the simultaneous solution of three equations with three unknowns. a1=0. We could have obtained the solution of Example B. To see the output waveform. Third Edition Copyright © Orchard Publications . and we start the simulation by clicking on the icon.18. Examples B.18.3 Using Algebraic Constraint blocks found in the Math Operations library. we obtain the waveform shown in Figure B. a2=2.2 The Display block in Figure B. a3=0. The model will display the values for the unknowns z 1 .1 and B. we switch to the MATLAB Command prompt and we type the following: >> a0=1. x0=[0 0 0 0]’.2 have clearly illustrated that the State−Space is indeed a powerful block. and Gain blocks found in the Commonly Used Blocks library. then clicking on the Autoscale icon. Display blocks found in the Sinks library. Example B.17 shows the value at the end of the simulation stop time.

a6=4. we observe the values of the unknowns as z 1 = 2 . Model for Example B. a5=5. a3=−1.19. This enables us to specify algebraic equations for index 1 differential/algebraic systems (DAEs). The output must affect the input through some feedback path. a8=1. The block outputs the value necessary to produce a zero at the input..Simulink and its Relation to MATLAB The model is shown in Figure B. a4=1. We can improve the efficiency of the algebraic loop solver by providing an Initial guess for the algebraic state z that is close to the solution value.19. a7=−6. the Initial guess parameter is zero. Third Edition Copyright © Orchard Publications B−19 . The Algebraic Constraint block constrains the input signal f ( z ) to zero and outputs an algebraic state z . z 2 = – 3 .. a2=−3. After clicking on the simulation icon. we go to MATLAB’s Command prompt and we enter the following values: a1=2. By default. Figure B.. a9=2. and z 3 = 5 . k1=−8.These values are shown in the Display blocks of Figure B.19. Numerical Analysis Using MATLAB® and Excel®. k2=−7. k3=5.3 Next.

2 Simulink Demos At this time.19 represented as a subsystem The Display blocks in Figure B. ISBN 0−9744239−7−1. k1=14. † The contents of the Subsystem block are not lost. a2=−1. we can group all blocks and lines in the model of Figure B. Third Edition Copyright © Orchard Publications . Then.* For instance. B. a3=4.20 show the values of z 1 .1. and z 3 for the values specified in MATLAB’s Command prompt. Figure B. Section 2. These blocks are described in Section 2.1. a5=6.Introduction to Simulink® An outstanding feature in Simulink is the representation of a large model consisting of many blocks and lines. Introduction to Simulink with Engineering Applications.20† where in MATLAB’s Command prompt we have entered: a1=5... the reader can follow the steps delineated in The MathWorks Simulink User’s Manual to run the Demo Models beginning with the thermo model. should be ready to learn Simulink’s additional capabilities. a4=11. to be shown as a single Subsystem block. and this model will be shown as in Figure B. we choose Create Subsystem from the Edit menu. z 2 . a9=15. * The Subsystem block is described in detail in Chapter 2. a8=4.20. We can double−click on the Subsystem block to see its contents. a6=9. The model of Figure B. k3=9. a7=−8. The Subsystem block replaces the inputs and outputs of the model with Inport and Outport blocks. Chapter 2. This model can be seen by typing thermo in the MATLAB Command prompt. k2=−6. It is highly recommended that the reader becomes familiar with the block libraries found in the Simulink Library Browser. the reader with no prior knowledge of Simulink.19 except the display blocks.. ISBN 0−9744239−7−1. Page 2−2. B−20 Numerical Analysis Using MATLAB® and Excel®. Introduction to Simulink with Engineering Applications. Page 2−2.

compute the Euclidean norm of the matrix A .1 The Norm of a Matrix A norm is a function which assigns a positive length or size to all vectors in a vector space. −3 −6 8 1. defined as –2 5 A = –3 –6 7 –5 4 –9 –4 8 3 –8 9 1 2 –1 Solution: At the MATLAB command prompt.5)) are usually drawn as arrows in a two−dimensional cartesian coordinate system starting at the origin (0. we enter A=[−2 5 −4 9. (2. other than the zero vector.Appendix C Ill−Conditioned Matrices T his appendix supplements Chapters 4 and 14 with concerns when the determinant of the coefficient matrix is small.0). 4 −9 −8 −1]. Example C. C.g. Third Edition Copyright © Orchard Publications C−1 . 7 −5 3 2. is defined as A = 2 ∑ ∑ Aij 2 i=1j=1 n n (C. The Euclidean norm assigns to each vector the length of its arrow. norm(A) and MATLAB outputs Numerical Analysis Using MATLAB® and Excel®. denoted as A .1 Using the MATLAB function norm(A). We will introduce a reference against which the determinant can be measured to classify a matrix as a well− or ill−conditioned.. An example is the two−dimensional Euclidean space denoted as R . The elements of the Euclidean vector space (e. The Euclidean norm of a matrix A .1) and it is computed with the MATLAB function norm(A).

We recall from Chapter 4 that if the determinant of a square matrix A is singular. that is.1) above. C−2 Numerical Analysis Using MATLAB® and Excel®.2 Using the MATLAB function cond(A). if det ( A ) = 0 . Example C. the inverse of A is undefined.5539 C. 7 −5 3 2. The condition number of a matrix A is computed with the MATLAB function cond(A). Please refer to Chapter 4. Matrices with condition number close to unity are said to be well−conditioned matrices. cond(A) and MATLAB outputs ans = 2.2 Condition Number of a Matrix The condition number of a matrix A is defined as k( A) = A ⋅ A –1 (C. −3 −6 8 1. Third Edition Copyright © Orchard Publications . compute the condition number of the matrix A defined as –2 5 A = –3 –6 7 –5 4 –9 –4 8 3 –8 9 1 2 –1 Solution: At the MATLAB command prompt. we enter A=[−2 5 −4 9.2) where A is the norm of the matrix A defined in relation (C.Appendix C Ill−Conditioned Matrices ans = 14. Page 4−22. 4 −9 −8 −1]. and those with very large condition number are said to be ill−conditioned matrices.3724 This condition number is relatively close to unity and thus we classify matrix A as a well-conditioned matrix.

.7 8 1 1 -.. a mn are the coefficients of the system.3) Shown below is an example of the 5 × 5 Hilbert matrix. that is.. a m1 x 1 + a m2 x 2 + …+a mn x n = b m where x 1.-..e. …..-.4 5 1 1 -.. Third Edition Copyright © Orchard Publications C−3 ...-. . A unit fraction is the reciprocal of this integer. 1 ⁄ 3...j)-th entry: a 11 a 12 … a 1n a 21 a 22 … a 2n … … … … a m1 a m1 a m1 a m1 Numerical Analysis Using MATLAB® and Excel®. The coefficient matrix is the m × n matrix with the coefficient a ij as the (i. 1 ⁄ n . x 2. …. . i.Hilbert Matrices Now.4) * In general.. Accordingly. we classify such a matrix as ill−conditioned.8 9 (C. 1 ⁄ 2. a system with m linear equations and n unknowns can be written as a 11 x 1 + a 12 x 2 + …+a 1n x n = b 1 a 21 x 1 + a 22 x 2 + …+a 2n x n = b 2 . … are unit fractions. a 12. almost singular. Thus.-. .3 Hilbert Matrices Let n be a positive integer.-.6 7 1 1 -. C. let us consider that the coefficient matrix* is very small.5 6 1 1 -. 1 -1 1 -2 1 -3 1 -4 1 -5 1 -2 1 -3 1 -4 1 -5 1 -6 1 -3 1 -4 1 -5 1 -6 1 -7 1 1 -. x n are the unknowns and the numbers a 11.. 1 ⁄ 1. A Hilbert matrix is a matrix with unit fraction elements B ij = 1 ⁄ ( i + j – 1 ) (C.

585 0. Third Edition Copyright © Orchard Publications .3 Compute the determinant and the condition number of the 6 × 6 Hilbert matrix using MATLAB.4951e+007 This is a large number and if the coefficient matrix is multiplied by this number.4 Let Ax = b where A = 0. Example C. seven decimal places might be lost.256 Compute the values of the vector x . Let us consider another example.728 0.187 x2 0. cond(hilb(6)) ans = 1.585 0.379 and b = 0.379 ⋅ x 1 = 0.256 C−4 Numerical Analysis Using MATLAB® and Excel®. for the 6 × 6 Hilbert matrix. We can find the condition number of a matrix A with the cond(A) MATLAB function.464 0.728 0.Appendix C Ill−Conditioned Matrices MATLAB’s function hilb(n) displays the Hilbert n × n matrix. Solution: Here.3673e-018 This is indeed a very small number and for all practical purposes this matrix is singular.187 0.464 0. Example C. we enter det(hilb(6)) and MATLAB outputs ans = 5. Thus. we are asked to find the values of x 1 and x 2 of the linear system 0. Solution: At the MATLAB command prompt.

585 0. b=[0..464]. we define A and b .0171 but these are not the given values of the vector b .728 0.256]'.378.4341 3.e.0037 condition=cond(A) condition = 328. i.9428 1.187 0. A=[0. Example C.585 0. so let us check the determinant and the condition number of the matrix A . determinant = det(A) determinant = -0.6265 Therefore.Hilbert Matrices Using MATLAB.9428 Check: A=[0. Numerical Analysis Using MATLAB® and Excel®.8852]'.728 0. and we use the left division operation. x=b\A x = 2.464]. b=A*x 1. Third Edition Copyright © Orchard Publications C−5 . 0. 0. x=[2.8852 b = 2.4 above should serve as a reminder that when we solve systems of equations using matrices. we conclude that this system of equations is ill-conditioned and the solution is invalid. we should check the determinants and the condition number to predict possible floating point and roundoff errors.378.

com. MA. Other references indicated in footnotes throughout this text.References and Suggestions for Further Study A. Natick. ISBN-13: 978−1−934404−01−2 2.mathworks. ISBN 0-4866127-2-4 7. and Technology with MATLAB and Excel Computations. Getting Started with MATLAB 2. Using MATLAB Graphics 4. Circuit Analysis II with MATLAB Applications. ISBN 0−9709511−5−9 4. CRC Standard Mathematical Tables. The following publications by The MathWorks. ISBN 0-9744239-9-8 6. 01760. www. are highly recommended for further study. They are available from The MathWorks. 3 Apple Hill Drive. ISBN 0-8493-0626-4 . 1. ISBN 0-9744239-7-1 5. Signals and Systems with MATLAB Computing and Simulink Modeling. Statistics Toolbox B. Mathematics for Business. Third Edition. Circuit Analysis I with MATLAB Applications. are listed below. 1. Science. Handbook of Mathematical Functions. Third Edition. Introduction to Simulink with Engineering Applications. ISBN 0−9709511−2−4 3. Using MATLAB 3. Financial Toolbox 5.

x) MATLAB function 15-3 BESSELJ(x. 7-8 default color in MATLAB 1-14 default line in MATLAB 1-15 default marker in MATLAB 1-14 default values in MATLAB 1-11 degree of differential equation 5-3 demo in MATLAB 1-2 determinant . 1-27 Editor/Debugger in MATLAB 1-1. 12-11 column vector 1-19 command screen in MATLAB 1-1 command window in MATLAB 1-1 commas in MATLAB 1-7 comment line in MATLAB 1-2 Commonly Used Blocks in Simulink B-7 complementary solution A-1 complex conjugate 1-4 complex numbers 1-2.Index Symbols % (percent) symbol 1-2 %d MATLAB symbol 2-5 %e MATLAB symbol 2-21 %s MATLAB symbol 2-21 %u MATLAB symbol 2-21 A abs(z) MATLAB function 1-24 absolute cell in Excel 2-19 absolutely convergent 15-10 Adams’ method 9-13 Add Trendline Excel feature 8-6 adjoint of a matrix . 2-15 autoscale icon in Simulink B-12 axis MATLAB command 1-17. 1-21 elements of a matrix . 12-9 exponential form of complex numbers 3-14 exponential form of the Fourier series 6-29 eye(n) MATLAB function 4-6.see matrix diff(s) MATLAB function 2-6 difference equations A-1 difference operator 7-4.see matrix collect(s) MATLAB function 7-15. 1-22 B backward substitution. 1-2 eigenvalues 5-30 eigenvectors 5-39 element-by-element division in MATLAB 1-21 element-by-element exponentiation in MATLAB 1-21 element-by-element multiplication in MATLAB 1-19. 14-10 Bessel function of negative order n 15-2 Bessel function of n 15-1 Bessel functions 15-1 Bessel functions of the first kind 15-7 Bessel functions of the second kind 15-7 besselj(n.see matrix eps in MATLAB 1-22.n) Excel function 15-3 beta distribution 13-20 beta function 13-17 beta(m.see matrix conj(A) MATLAB function 4-8 conj(x) MATLAB function 4-8 conjugate of a complex number 3-12 connected network 16-15 constraints in linear programming 16-1 Contents Pane in Simulink B-7 conv(a. 8-6 Chebyshev polynomials 15-22 Chebyshev polynomials of the first kind 15-22 Chebyshev polynomials of the second kind 15-22 Cholesky factorization 14-23 classification of differential equations 5-2 clc MATLAB command 1-2 clear MATLAB command 1-2 coefficient matrix . 8-4 cubic interpolarion in MATLAB 7-25 cubic spline interpolarion in MATLAB 7-25 curve fitting 8-1 curved regression 8-7.b) MATLAB function 1-6 Cramer’s rule 4-18.k) MATLAB function 14-24 diagonal elements of a matrix . 33 EXP(GAMMALN(n)) Excel function 13-5 expand(s) MATLAB function 7-13. 6-31 even symmetry 6-7 exit MATLAB command 2.see finite differences dipole 15-12 direct terms in MATLAB 12-1 directed network 16-15 disp(x) MATLAB function 2-5 Display block in Simulink B-18 display formats in MATLAB 1-31 distinct poles 12-2 distinct roots of characteristic equation 5-9 divided differences 7-1 division of complex numbers 3-13 dot division operator in MATLAB 1-21 dot exponentation operator in MATLAB 1-21 dot multiplication operator in MATLAB 1-21 dsolve(s) MATLAB function 9-5 dynamic programming 16-4 E Editor window in MATLAB 1-1.q) MATLAB function 1-6. 11-1 differences .see matrix algebraic constrain block in Simulink B-18 algebraic form of the Legendre polynomials 15-17 alternate form of the trigonometric Fourier series 6-25 alternating current 3-1 angle(z) MATLAB function 1-24 angular velocity 3-2 antidifference 7-12 approximations with Excel 2-7 associated Legendre differential equation 15-18 associated Legendre functions of the first and second kind 15-18 AutoFill Excel feature 2-9.see matrix diagonal of a matrix .n) MATLAB function 13-19 BETADIST Excel function 13-21 bisection method for root approximation 2-19 box MATLAB command 1-12 C Casorati’s determinant 11-2 Cayley-Hamilton theorem 5-30 characteristic (auxiliary) equation 5-8 characteristic equation of a second order difference equation 11-3 chart type in Excel 2-10 Chart Wizard Excel feature 2-10. 3-11 complex poles 12-5 complex roots of characteristic equation 5-9 cond(A) MATLAB function C-2 condition number of a matrix . 14-24 eye(size(A)) MATLAB function 4-7 F factor(p) MATLAB function 12-3 factorial polynomials 7-6 Fibonacci numbers 11-7 figure window in MATLAB 1-14 finite differences 7-1 first divided difference 7-1 first harmonic 6-1 fixed point format 2-21 Flip Block command in Simulink B-11 forced response 5-8 forcing function A-1 format MATLAB command 1-31 format specifiers in MATLAB 2-21 IN1 .see matrix cofactors . 8-14 cycle 3-2 cyclic frequency 3-3 D Data Analysis Toolpack in Excel 8-7 data points in MATLAB 1-14 decibel 12 decimal format 2-21 deconv(p. 1-27 equating the numerators procedure in partial fraction expansion 12-13 Erlang distribution 13-16 error function 10-4 error in method of least squares 8-3 Euclidean norm C-1 Euler’s identities 3-14 even functions 6-7.see matrix diag(v.see matrix configuration parameters in Simulink B-12 congugate of a matrix .

34 lower triangular matrix . 8-7 Legendre functions 15-10 Legendre functions of the second kind 15-11 Legendre polynomials 15-11 Legendre polynomials in trigonometric form 15-18 legendre(n. C-2 inverse of 4-23 lower triangular 4-6 main diagonal elements of 4-1 main diagonal of 4-1 minor of determinant 4-13 non-singular 4-22 scalar 4-6 singular 4-22 size of 4-7 skew-Hermitian 4-9 skew-symmetric 4-8 square 4-1 symmetric 4-8 trace of 4-2 transpose of 4-7 unitary 14-25 upper triangular 4-5 well-conditioned C-2 zero matrix .a. 14-14 M Maclaurin power series 6-41.y.y) MATLAB command 1-17 method of Frobenius 15-1 method of least squares 8-2.y.yi) MATLAB function 7-25 interp2(x. A-1 method of variation of parameters 5-20 m-file in MATLAB 1-1 1-26. 1-27.y. 14-9 Genenbauer 15-22 general solution of a differential equation 5-6 generalized factorial function 13-1 generating function for Bessel functions of the first kind of integer order 15-9 generating function for Legendre polynomials 15-12 Goal Seek Excel feature 2-16 Gram-Schmidt orthogonalization procedure 5-39.see matrix imag(z) MATLAB function 1-24 imaginary axis 3-10 imaginary number 3-10 IN2 improper integral 13-1 improper rational function 12-1 increments between points in MATLAB 1-14 in-phase sinusoids 3-3 input(‘string’) MATLAB command 2-2 int(f. 7-6 main diagonal elements .see matrix isoprofit line 16-2 J j operator 3-11 L L’ Hôpital’s rule 13-2 lagging sinudoid 3-3 Lagrange’s interpolation method 7-17 Laguerre polynomials 15-21 leading sinusoid 3-3 least squares 8-2.see matrix matrix left division in MATLAB 4-26 matrix multiplication in MATLAB 1-19. 11-2. A-1 nearest neighbor interpolarion 7-25 network analysis 16-14 Neumann functions 15-7 . 14-7 Gregory-Newton Backward Interpolation Formula 7-21 Gregory-Newton Forward Interpolation Formula 7-19 grid MATLAB command 1-11 gtext MATLAB command 1-14.x) MATLAB function 15-19 Legendre’s equation 15-10 lims = MATLAB function 1-27 line graph 16-4 line spectrum 6-33 linear factor 1-9 linear interpolarion 7-25 linear programming 16-1 linear regression 8-2 linspace MATLAB command 1-14 ln (natural logarithm) 1-12 log (common logarithm) 1-12 log(x) MATLAB function 1-12 log10(x) MATLAB function 1-12 log2(x) MATLAB function 1-12 loglog MATLAB command 1-12.y.see matrix homogeneous difference equation 11-2 Hz (Hertz) 3-3 I identity matrix .see matrix Math Operations Library in Simulink B-11 MATLAB Demos 1-2 matrix (matrices) 4-1 adjoint of 4-22 coefficient C-3 cofactors of 4-11 condition number of C-2 conformable for addition 4-2 conformable for multiplication 4-4 conformable for subtraction 4-2 congugate of 4-8 determinant of 4-9 diagonal elements of 4-1 diagonal of 4-6 elements of 4-1 Hermitian 4-9 Hilbert C-3 identity 4-6 ill-conditioned 4-22. 8-3 least squares line 8-2 least-squares curve 8-2 least-squares parabola 8-2.z. 1-29 fzero(‘function’.x) MATLAB function 2-7 G Gain block in Simulink B-18 gamma distribution 13-16 gamma function 13-1 gamma(n) MATLAB function 13-3.’method’) MATLAB function 7-25 interpolation 7-1 interpolation with MATLAB 7-24 interval halving 2-19 inverse of a matrix .xi.z) MATLAB command 1-17 mesh(Z) MATLAB function 7-32 meshgrid(x. 8-3 method of Picard 15-1 method of undetermined coefficients 5-10.xi.b) MATLAB function 10-5 interp1(x. 2-4 fundamental frequency 6-1 fundamental theorem of integral calculus 7-12 fundamental theorem of sum calculus 7-13 fzero MATLAB function 1-27.y.yi.see matrix main diagonal of a matrix . 13-10 GAMMADIST Excel function 13-16 GAMMALN Excel function 13-5 Gaussian elimination method 4-20.x0) MATLAB function 12-18 fzero(f.see matrix ill-conditioned matrix . 6-22 half-wave symmetry 6-7. 6-31 help in MATLAB 1-2.see matrix lsqnonneg MATLAB function 14-28 LU factorization method 14-9 lu(A) MATLAB function 14-12.see matrix MINVERSE Excel function 4-28 MMULT Excel function 4-28.z. 1-15 Hermitian matrix . 4-29 modified Bessel functions 15-7 modulation index 15-4 multiple poles 12-6 multiplication of complex numbers 3-12 N NaN in MATLAB 1-27 natural response 5-8.xi) MATLAB function 7-24 interp1(x.’method’) MATLAB function 7-25 interp2(x. 1-20 mesh(x.forward substitution 14-10 Fourier analysis 3-2 Fourier series 6-1 fplot MATLAB command 1-27 fprintf MATLAB command 7-29 frequency 3-2 Frequency Modulation (FM) 15-4 frequency response 1-11 full-wave rectifier with even symmetry 6-24 function block parameters in Simulink B-10 function files in MATLAB 1-26. 15-25 H half-wave rectifier 6-19.xi.see matrix hilb(n) MATLAB function C-4 Hilbert matrix . 1-27 Milne’s method 9-15 minimum span problems 16-15 minor of determinant .

6-14. 6-14.see matrix V VLOOKUP Excel function 7-23 W Wallis’s formulas 13-16 Weber functions 15-7 well-conditioned matrix . 6-49 start simulation in Simulink B-12 state equations 5-24 state transition matrix 5-28 state variables 5-24 State-Space block in Simulink B-12 Stirling’s asymptotic series for the G(n) function 13-9 string in MATLAB 1-17 subplot MATLAB command 1-18 surface zonal harmonics 15-11 svd(A) MATLAB function 14-28 sym.6 residue(r. 12.see matrix solution of the homogeneous ODE 5-8 solutions of ODEs 5-6 space equations 5-24 spectrum analyzer 33 spherical harmonics 15-18 sprintf MATLAB command 2-5 sqrt MATLAB function 10-12 square matrix .y) MATLAB function 10-3. 6-31 T Taylor series 5-24.Newton’s divided difference interpolation method 7-15 Newton-Cotes 8-panel rule 10-10 non-homogeneous difference equation 11-2 non-homogeneous ODE 5-6 non-singular matrix . 14-2 orthogonal system 15-9 orthogonal trajectories 14-2 orthogonal unit vectors 14-5 orthogonal vectors 5-39. syms MATLAB symbolic expressions 12-4 symbolic expressions in MATLAB 12-3 Symbolic Math Toolbox in MATLAB 12-4 symmetric matrix . 8-11 power series 6-40 proper rational function 12-1 Q QR factorization 14-25 qr(A) MATLAB function 14-25 quad MATLAB function 10-10 quad8 MATLAB function 10-10 quadratic curve 8-1 quadratic factor 1-9 quit MATLAB command 1-2 R radian frequency 3-2 rational polynomial 1-8 rationalization of the quotient 3-13 real axis 3-10 real number 3-11 real(z) MATLAB function 1-24 recursion A-1 recursive method A-1 regression 8-1 regression analysis 8-7 relative cell in Excel 2-19 repeated poles 5-9. 6-41.see matrix transpose of a matrix .p. 6-16.see matrix upper triangular matrix . 6-44 Taylor series expansion method 9-1 text MATLAB command 1-14. 3-3 periodic waveform 3-2 phasor 3-2 plot area in Excel 6 plot MATLAB command 1-9. 1-15 plot3 MATLAB command 1-16 polar form of complex numbers 3-15 polar plot in MATLAB 1-24 polar(theta. 6-31 odd symmetry 6-7 ODE (Ordinary Differential Equation) 5-3 ode23 MATLAB function 9-9 ode45 MATLAB function 9-9 one-dimensional wave equation 5-3 optimum path policy 16-5 order of a differential equation 5-3 ordinary differential equation 5-3 oriented network 16-15 orthogonal basis 14-5 orthogonal functions 6-2.see matrix trapezoidal rule 10-1 trapz(x.r) MATLAB function 1-24 poles 12-2 poly MATLAB function 1-4 polyder MATLAB function 1-7 polyfit(x.see matrix skew-Hermitian matrix . 1-17 third harmonic 6-1 title(‘string’) in MATLAB 1-12 trace of a matrix . 9-5 S sawtooth waveform 6-10. 15-18 roots of polynomials 1-3 roots(p) MATLAB function 1-3. 10-5 Tree Pane in Simulink B-7 Trendline Excel feature 8-9 triangular waveform 6-11. 6-48. 1-12. 6-18 scalar matrix .n) MATLAB function 8-11 polynomial construction from known roots in MATLAB 1-4 polyval(p.k) MATLAB function 12-1 revolutions per second 3-5 Rodrigues’ formula 15-12. 14-4 orthonormal basis 14-5 out-of-phase sinusoids 3-3 overdetermined system 8-3 P parabolic curve 8-1 partial differential equation (PDE) 5-3 partial fraction expansion 12-1 PDE (Partial Differential Equation) 5-3 Pearson correlation coefficient 8-10 period 3-2.see matrix zeros 12-2 zlabel MATLAB command 1-17 IN3 .see matrix square waveform 6-9. 6-19 trigonometric Fourier series 6-1 trigonometric relations 3-5 two-dimensional plots 7-32 type of a diferential equation 5-2 U ultraspherical functions 15-22 undetermined system 8-3 unit fraction C-3 unitary matrix . 11-2 X xlabel MATLAB command 1-12 XY (Scatter) in Excel 8-6 Y ylabel MATLAB command 1-12 Z zero matrix .see matrix Singular Value Decomposition 14-28 Sinks library B-18 sinusoids 3-2 size of a matrix .see matrix symmetry 6-7.see matrix Scope block in Simulink B-12 script file in MATLAB 1-26 second divided difference 7-1 second harmonic 6-1 semicolons in MATLAB 1-7 semilogx MATLAB command 1-12 semilogy MATLAB command 1-12 simple differential equations 5-1 simplex method 16-4 Simpson’s rule 10-6 Simulation drop menu in Simulink B-12 simulation start icon in Simulink B-12 Simulink icon B-7 Simulink Library Browser B-8 singular matrix . 1-8 rotating vector 3-5 round(n) MATLAB function 1-24 row vector 1-3. 14-1.x) MATLAB function 1-5.see matrix norm C-1 norm(A) MATLAB function C-1 numeric expressions in MATLAB 12-4 numerical evaluation of Fourier coefficients 6-36 O odd functions 6-8.see matrix skew-symmetric matrix .see matrix while end in MATLAB 2-4 Wronskian determinant 5-10. 1-19 Runge-Kutta method 5-24.y.

Sign up to vote on this title

UsefulNot useful- Hohn W.bull _ Linear and Non-Linear Numerical Analysis of Foundations
- Experimental and Numerical Analysis on Behaviour of Externally Bonded RC T Beams Using GFRP Composites
- Real Analysis
- matlab
- Numerical Analysis Using MATLAB and Excel Spreadsheets- (2007)
- BOOK_Numerical Analysis Using MATLAB and Excel - 3rdEd - ST.karris - Orchard 2007
- Zmatlab Tut Sheet
- Matlab Presentation
- Algebra II Mod1 Module Overview and Assessments
- Matlab Tutorial
- MatlabIntro_2
- MECH1004 - Slides - Section 16 Greyscale 6 to Page
- Using Adams/Controls - MD Adams 2010
- Lab1_DSP
- MATLAB Tutorials
- Francis Scheid Schaums Outline of NuSvcmerical Analysis, Second Edition 1989
- 2013-jcp-cpr