Copyright © 2005. The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.

Slides:



Advertisements
Similar presentations
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Advertisements

259 Lecture 17 Working with Data in MATLAB. Overview  In this lecture, we’ll look at some commands that are useful for working with data!  fzero  sum,
1 Eng. Mohamed El-Taher Eng. Ahmed Ibrahim. 2 1.FUNCTION SUMMARY polyfun  Polynomial functions are located in the MATLAB polyfun directory. For a complete.
Dynamics of a four-bar linkage
Differential Equations Math Review with Matlab: Finding Solutions to Differential Equations S. Awad, Ph.D. M. Corless, M.S.E.E. D. Cinpinski E.C.E. Department.
CSE 123 Symbolic Processing. Declaring Symbolic Variables and Constants To enable symbolic processing, the variables and constants involved must first.
Numerical Differentiation and Quadrature (Integration) 1Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature Daniel Baur ETH Zurich,
Integrals 5.
Part 5 Chapter 19 Numerical Differentiation PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill.
High Accuracy Differentiation Formulas
Matlab Matlab is a powerful mathematical tool and this tutorial is intended to be an introduction to some of the functions that you might find useful.
Part 3 Chapter 8 Linear Algebraic Equations and Matrices PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The.
Linear Simultaneous Equations
6&7-2 Dynamics, two examples of the use of ode45. Numeric Integration using trapz and quad/quadl functions. Readings: Matlab by Pratap Chapter 5.4,5.5.
Matrix Mathematics in MATLAB and Excel
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Numerical Differentiation and Integration ~ Newton-Cotes.
1 Chapter 8 Calculus Operations with MATLAB We are now ready to see how calculus operations can be performed with MATLAB. It should be noted that a digital.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Numerical Differentiation and Integration Part 6 Calculus.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
Chapter 9 Introduction to MATLAB for Engineers, Third Edition
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
Chapters 5 and 6: Numerical Integration
Chapter 10 Review: Matrix Algebra
Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 8 Linear Algebraic Equations PowerPoint to accompany Copyright © 2010.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Introduction to MATLAB for Engineers Third Edition William J. Palm III Chapter 11 MuPAD PowerPoint to accompany Copyright © The McGraw-Hill Companies,
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
Mathematics of Cryptography Modular Arithmetic, Congruence,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Simpson Rule For Integration.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
MATLAB Basics. The following screen will appear when you start up Matlab. All of the commands that will be discussed should be typed at the >> prompt.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Chapter 5-The Integral Calculus, 2ed, by Blank & Krantz, Copyright 2011 by John Wiley & Sons, Inc, All Rights Reserved.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 3 - Chapter 9 Linear Systems of Equations: Gauss Elimination.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 22.
Numerical Differentiation and Quadrature (Integration)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Introduction to MATLAB for Engineers Third Edition William J. Palm III Chapter 10 Simulink PowerPoint to accompany Copyright © The McGraw-Hill Companies,
6.094 Introduction to programming in MATLAB Danilo Šćepanović IAP 2008 Lecture 3 : Solving Equations and Curve Fitting.
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical Calculus and Differential Equations.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
1 Time-Domain Representations of LTI Systems CHAPTER 2.11 Characteristics of Systems Described by Differential and Difference Equations and Difference.
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 27.
Introduction to MATLAB 7
Math 3120 Differential Equations with Boundary Value Problems
Copyright ©2015 Pearson Education, Inc. All rights reserved.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 5 Integration and Differentiation.
Part 3 Chapter 9 Gauss Elimination PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill Companies,
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical Calculus and Differential Equations.
1 Matlab for Engineering Applications Introduced by Jen-Yang Chen Department of Electronic Engineering Ming Chuan University.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapters 22 and 23.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 3 - Chapter 8 Linear Algebraic Equations and Matrices.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 20 Numerical Integration of Functions.
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
CHAPTER 3 NUMERICAL METHODS
Introduction to Programming for Mechanical Engineers
Modeling and Simulation Dr. Mohammad Kilani
Introduction to Programming for Mechanical Engineers (ME 319)
Presentation transcript:

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III Chapter 7 Numerical Calculus and Differential Equations PowerPoint to accompany

Section 7.1 Numerical Integration Illustration of (a) rectangular and (b) trapezoidal numerical integration. Figure

Command quad(fun,a,b,tol) quadl(fun,a,b) dblquad(fun,a,b,c,d) triplequad(fun,a,b,c,d,e,f) Description Uses an adaptive Simpson’s rule to compute the integral of a function whose handle is fun, with a as the lower integration limit and b as the upper limit. Uses Lobatto quadrature to compute the integral. The syntax is identical to quad. Computes the double integral. Computes the triple integral. Numerical integration functions. Table (continued)

Table (continued) trapz(x,y) Uses trapezoidal integration to compute the integral of y with respect to x, where the array y contains the function values at the points contained in the array x. 7-4

Use the trapz function to compute the integral sin x dx   whose exact value is 2. Arbitrarily choosing 10 panels with equal widths of π/10, the script file is x = linspace(0,pi,10); y = sin(x); trapz(x,y) The answer is , which gives a relative error of 100( )/2) = 1%. More? See pages

MATLAB function quad implements an adaptive version of Simpson’s rule, while the quadl function is based on an adaptive Lobatto integration algorithm. To compute the sine integral, type >>A = The answer given by MATLAB is 2, which is correct. We could also type >> A = quad(‘sin’,0,pi) but use of a function handle is now the preferred method. 7-6

To integrate cos x 2 from 0 to 10, first create the function file function c2 = cossq(x) % cosine squared function. c2 = cos(x.^2); Note that we must use array exponentiation. The quad function is called as follows: An anonymous function can also be used: 7-7

Although the quad and quadl functions are more accurate than trapz, they are restricted to computing the integrals of functions and cannot be used when the integrand is specified by a set of points. For such cases, use the trapz function. 7-8 More? See pages

Section 7.2 Numerical differentiation: Illustration of three methods for estimating the derivative dy  dx. Figure

MATLAB provides the diff function to use for computing derivative estimates. Its syntax is d = diff(x), where x is a vector of values, and the result is a vector d containing the differences between adjacent elements in x. That is, if x has n elements, d will have n  1 elements, where d  [x(2)  x(1), x(3)  x(2),..., x(n)  x(n  1)]. For example, if x = [5, 7, 12, -20], then diff(x) returns the vector [2, 5, -32]. 7-10

Command d = diff(x) b = polyder(p) b = polyder(p1,p2) [num, den] = polyder(p2,p1) Description Returns a vector d containing the differences between adjacent elements in the vector x. Returns a vector b containing the coefficients of the derivative of the polynomial represented by the vector p. Returns a vector b containing the coefficients of the polynomial that is the derivative of the product of the polynomials represented by p1 and p2. Returns the vectors num and den containing the coefficients of the numerator and denominator polynomials of the derivative of the quotient p 2  p 1, where p1 and p2 are polynomials. Numerical differentiation functions. Table 7.2–1 7-11

MATLAB can also be used to compute gradients. See Table For examples, see pages

Section 7.3 First-Order Differential Equations The ode solvers. When used to solve the equation dy/dt  f (t, y), the basic syntax is (using ode45 as the example): [t,y] = tspan, y0) where ydot is the handle of the function whose inputs must be t and y and whose output must be a column vector representing dy/dt; that is, f (t, y). The number of rows in this column vector must equal the order of the equation More? See pages

Application of an ode solver to find the response of an RC circuit. Figure

The circuit model for zero input voltage v is dy/dt + 10y = 0 First solve this for dy/dt: dy/dt  10y Next define the following function file. Note that the order of the input arguments must be t and y. function ydot = RC_circ(t,y) ydot = -10*y; 7-15

The function is called as follows, and the solution plotted along with the analytical solution y_true. [t, y] = [0, 0.4], 2); y_true = 2*exp(-10*t); plot(t,y,’o’,t,y_true), xlabel(’Time(s)’),... ylabel(’Capacitor Voltage’) Note that we need not generate the array t to evaluate y_true, because t is generated by the ode45 function. The plot is shown on the next slide. 7-16

Free response of an RC circuit. Figure More? See pages

Application example: Draining of a spherical tank. Example and Figure

Plot of water height in a spherical tank. Figure More? See pages

Section 7.4 Extension to Higher-Order Equations To use the ODE solvers to solve an equation higher than order 2, you must first write the equation as a set of first- order equations. 7-20

This form is sometimes called the Cauchy form or the state-variable form. dx 1 /dt  x 2 dx 2 /dt  f (t)  x1 x1  7 5 x2x For example,

Suppose that f (t)  sin t. Then the required file is function xdot = example1(t,x) % Computes derivatives of two equations xdot(1) = x(2); xdot(2) = (1/5)*(sin(t)-4*x(1)-7*x(2)); xdot = [xdot(1); xdot(2)]; Note that: xdot(1) represents dx 1 /dt, xdot(2) represents dx 2 /dt, x(1) represents x 1, and x(2) represents x More? See pages

Suppose we want to solve (7.4–1) for 0  t  6 with the initial conditions x 1 (0)  3, x 2 (0)  9. Then the initial condition for the vector x is [3, 9]. To use ode45, you type [t, x] = [0, 6], [3, 9]); 7-23

Each row in the vector x corresponds to a time returned in the column vector t. If you type plot(t,x), you will obtain a plot of both x 1 and x 2 versus t. Note that x is a matrix with two columns; the first column contains the values of x 1 at the various times generated by the solver. The second column contains the values of x 2. Thus to plot only x 1, type plot(t,x(:,1)). 7-24

A pendulum example. Figure 7.4–1 7-25

The pendulum angle as a function of time for two starting positions. Figure More? See pages

Section 7.5 Special Methods for Linear Equations A mass and spring with viscous surface friction. 7-27

Displacement and velocity of the mass as a function of time. Figure More? See pages

Command sys = ss(A, B, C, D) [A, B, C, D] = ssdata(sys) sys = tf(right,left) [right, left] = tfdata(sys) Description Creates an LTI object in state-space form, where the matrices A, B, C, and D correspond to those in the model dx/dt  Ax  Bu, y  Cx  Du. Extracts the matrices A, B, C, and D corresponding to those in the model dx/dt  Ax  Bu, y  Cx  Du. Creates an LTI object in transfer-function form, where the vector right is the vector of coefficients of the right-hand side of the equation, arranged in descending derivative order, and left is the vector of coefficients of the left-hand side of the equation, also arranged in descending derivative order. Extracts the coefficients on the right- and left-hand sides of the reduced-form model. LTI object functions. Table 7.5– More? See pages

Command impulse(sys) initial(sys,x0) lsim(sys,u,t) step(sys) Description Computes and plots the unit-impulse response of the LTI object sys. Computes and plots the free response of the LTI object sys given in state-model form, for the initial conditions specified in the vector x0. Computes and plots the response of the LTI object sys to the input specified by the vector u, at the times specified by the vector t. Computes and plots the unit-step response of the LTI object sys. Basic syntax of the LTI ODE solvers. Table More? See pages

Free response of the model given by (7.5-5) through (7.5-8) for x 1 (0)  5 and x 2 (0)   2. Figure

Step response of the model given by (7.5-6) through (7.5-8) and the model (8.7–10), for zero initial conditions. Figure

An armature-controlled dc motor. Figure

Voltage input and resulting velocity response of a dc motor. Figure More? See pages

Square-wave response of the model (7.5-13). Figure ¨ 7-35.