ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical Calculus and Differential Equations.

Slides:



Advertisements
Similar presentations
Dynamics of a four-bar linkage
Advertisements

Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Ordinary Differential Equations Equations which are.
Chapter 4 Roots of Equations
Transfer Functions Convenient representation of a linear, dynamic model. A transfer function (TF) relates one input and one output: The following terminology.
Constrained Fitting Calculation the rate constants for a consecutive reaction with known spectrum of the reactant A = (A A + A B + A C ) + R = C E T =
Ch 5.1: Review of Power Series Finding the general solution of a linear differential equation depends on determining a fundamental set of solutions of.
Initial-Value Problems
Dr. Jie Zou PHY Chapter 9 Ordinary Differential Equations: Initial-Value Problems Lecture (II) 1 1 Besides the main textbook, also see Ref.: “Applied.
8-1 Chapter 8 Differential Equations An equation that defines a relationship between an unknown function and one or more of its derivatives is referred.
Development of Empirical Models From Process Data
Ch 2.1: Linear Equations; Method of Integrating Factors
Chapter 17 Objectives Recognizing that Newton-Cotes integration formulas are based on the strategy of replacing a complicated function or tabulated data.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Numerical Solutions of Ordinary Differential Equations
NUMERICAL SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
Ordinary Differential Equations S.-Y. Leu Sept. 21, 2005.
Ordinary Differential Equations S.-Y. Leu Sept. 21,28, 2005.
Chapter 6 Numerical Interpolation
1 Chapter 9 Differential Equations: Classical Methods A differential equation (DE) may be defined as an equation involving one or more derivatives of an.
Ordinary Differential Equations (ODEs)
Differential Equations and Boundary Value Problems
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.
Numerical Solution of Ordinary Differential Equation
MATH 685/ CSI 700/ OR 682 Lecture Notes Lecture 10. Ordinary differential equations. Initial value problems.
Numerical solution of Differential and Integral Equations PSCi702 October 19, 2005.
Fin500J Topic 7Fall 2010 Olin Business School 1 Fin500J Mathematical Foundations in Finance Topic 7: Numerical Methods for Solving Ordinary Differential.
1 Chapter 6 Numerical Methods for Ordinary Differential Equations.
PART 7 Ordinary Differential Equations ODEs
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Chapter 4 Transients.
Boyce/DiPrima 9th ed, Ch 8.4: Multistep Methods Elementary Differential Equations and Boundary Value Problems, 9th edition, by William E. Boyce and Richard.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
Chapter 9 Introduction to MATLAB for Engineers, Third Edition
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
ELECTRICA L ENGINEERING Principles and Applications SECOND EDITION ALLAN R. HAMBLEY ©2002 Prentice-Hall, Inc. Chapter 4 Transients Chapter 4 Transients.
EE3561_Unit 8Al-Dhaifallah14351 EE 3561 : Computational Methods Unit 8 Solution of Ordinary Differential Equations Lesson 3: Midpoint and Heun’s Predictor.
1 Tips for solving Project 1 Reactor SO 3 SO 2 +O 2.
Ordinary Differential Equations
Integration of 3-body encounter. Figure taken from
Scientific Computing Numerical Solution Of Ordinary Differential Equations - Euler’s Method.
Modified by Albert W.J. Hsue,
Chapter 4 Transients. 1.Solve first-order RC or RL circuits. 2. Understand the concepts of transient response and steady-state response.
Beginning Programming for Engineers
CHAPTER 3 NUMERICAL METHODS
Ordinary Differential Equations (ODEs) 1Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Michael Sokolov ETH Zurich, Institut.
Eigenvalues The eigenvalue problem is to determine the nontrivial solutions of the equation Ax= x where A is an n-by-n matrix, x is a length n column.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical Calculus and Differential Equations.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 7 - Chapter 25.
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
Please remember: When you me, do it to Please type “numerical-15” at the beginning of the subject line Do not reply to my gmail,
Advanced Engineering Mathematics, 7 th Edition Peter V. O’Neil © 2012 Cengage Learning Engineering. All Rights Reserved. CHAPTER 4 Series Solutions.
Ch 2.1: Linear Equations; Method of Integrating Factors A linear first order ODE has the general form where f is linear in y. Examples include equations.
Dr. Mujahed AlDhaifallah ( Term 342)
Today’s class Ordinary Differential Equations Runge-Kutta Methods
Lecture 40 Numerical Analysis. Chapter 7 Ordinary Differential Equations.
Ordinary Differential Equations
ERT 210/4 Process Control & Dynamics DYNAMIC BEHAVIOR OF PROCESSES :
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Lecture 39 Numerical Analysis. Chapter 7 Ordinary Differential Equations.
Sec 232: The coefficient tableau 2ed order RK method Expand all f around (x,y) using Taylor expansion in 2d and then choose constants such that the equation.
This chapter is concerned with the problem in the form Chapter 6 focuses on how to find the numerical solutions of the given initial-value problems. Main.
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.
Keywords (ordinary/partial) differencial equation ( 常 / 偏 ) 微分方程 difference equation 差分方程 initial-value problem 初值问题 convex 凸的 concave 凹的 perturbed problem.
Engineering Problem Solution
Class Notes 18: Numerical Methods (1/2)
Sec:25.3 RUNGE-KUTTA METHODS.
Sec:5.4 RUNGE-KUTTA METHODS.
Presentation transcript:

ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical Calculus and Differential Equations

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 2 Numerical Methods for Differential Equations The Euler Method  Consider the equation (8.5-1) r(t) : a known function  From the definition of derivative, ( is small enough) (8.5-2)  Use (8.5-2) to replace (8.5-1) by the following approximation : (8.5-3)

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 3 Numerical Methods for Differential Equations  Assume that the right side of (8.5-1) remains constant over the time interval. Then equation (8.5-3) can be written in more convenient form as follows: (8.5-4), where : step size  The Euler method for the general first-order equation is (8.5-5)  The accuracy of the Euler method can be improved by using a smaller step size. However, very small step sizes require longer runtimes and can result in a large accumulated error because of round-off effects.

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations Euler method for the free response of dy/dt = –10y, y(0) = 2 r= -10; deltaT = 0.01 ; % step size t=[0:deltaT:0.5]; % our vector of time values y(1)=2; % initial value at t=0 for k=1: length(t)-1 % for every value in t vector y(k+1) = y(k) + r*y(k)*deltaT; end y_true = 2*exp(-10*t); plot(t,y,'o',t,y_true), xlabel('t'), ylabel('y'); 4

Euler method solution for the free response of dy/dt  –10y, y(0)  2. Figure 8.5–1 8-19

Euler method solution of dy/dt  sin t, y(0)  0. Figure 8.5– More? See pages

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 7 Numerical Methods for Differential Equations The Predictor-Corrector Method  The Euler method can have a serious deficiency in problems where the variables are rapidly changing because the method assumes the variables are constant over time interval. (8.5-7) (8.5-8)  Suppose instead we use the average of the right side of (8.5-7) on the interval. (8.5-9), where (8.5-10)

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 8 Numerical Methods for Differential Equations  Let Euler predictor: (8.5-11) Trapezoidal corrector: (8.5-12)  This algorithm is sometimes called the modified Euler method. However, note that any algorithm can be tried as a predictor or a corrector.  For purposes of comparison with the Runge-Kutta methods, we can express the modifided Euler method as (8.5-13) g1 is deltaY given by f(t k,y k ) (8.5-14) g2 is deltaY given by f(t k+1,y k+1 ) (8.5-15)

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations Modified Euler solution of dy/dt = –10y, y(0) = 2 r= -10; deltaT = 0.01 ; % same step size as before y(1)=2; t=[0:deltaT:0.5]; % our vector of time values for k=1:length(t)-1 g1 = deltaT*r*y(k); % estimate of deltaY at t(k),y(k) g2 = deltaT*r*(y(k) + g1); % est of deltaY at t(k+1),y(k+1) y(k+1) = y(k) + 0.5*(g1 + g2); end y_true = 2*exp(-10*t); plot(t,y,'o',t,y_true), xlabel('t'), ylabel('y'); 9

Modified Euler solution of dy/dt  –10y, y(0)  2. Figure 8.5–3 8-21

Modified Euler solution of dy/dt  sin t, y(0)  0. Figure 8.5– More? See pages

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 12 Numerical Methods for Differential Equations Runge-Kutta Methods  The second-order Runge-Kutta methods: (8.5-17), where : constant weighting factors (8.5-18) (8.5-19)  To duplicate the Taylor series through the h 2 term, these coefficients must satisfy the following: (8.5-19) (8.5-19)

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 13 Numerical Methods for Differential Equations  The fourth-order Runge-Kutta methods: (8.5-23) (8.5-24) Apply Simpson’s rule for integration

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 14 Numerical Methods for Differential Equations MATLAB ODE Solvers ode23 and ode45  MATLAB provides functions, called solvers, that implement Runge-Kutta methods with variable step size.  The ode23 function uses a combination of second- and third-order Runge-Kutta methods, whereas ode45 uses a combination of fourth- and fifth-order methods. ODE solvers Solver name Description ode23 Nonstiff, low-order solver. ode45 Nonstiff, medium-order solver. ode113 Nonstiff, variable-order solver. ode23s Stiff, low-order solver. ode23t Moderately stiff, trapezoidal-rule solver. ode23tb Stiff, low-order solver. ode15s Stiff, variable-order solver.

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 15 Stiff? Stiff Differential Equations  A stiff differential equation is one whose response changes rapidly over a time scale that is short compared to the time scale over which we are interested in the solution.  A small step size is needed to solve for the rapid changes, but many steps are needed to obtain the solution over the longer time interval, and thus a large error might accumulate.  The four solvers specifically designed to handle stiff equations: ode15s (a variable-order method), ode23s (a low-order method), ode23tb (another low- order method), ode23t (a trapezoidal method).

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 16 Numerical Methods for Differential Equations Solver Syntax Basic syntax of ODE solvers Command Description [t, y] = ode23( ‘ydot’, tspan, y0) Solves the vector differential equation specified in function file ydot, whose inputs must be t and y and whose output must be a column vector representing ; that is,. The number of rows in this column vector must equal the order of the equation. The vector tspan contains the starting and ending values of the independent variable t, and optionally, any intermediate values of t where the solution is desired. The vector y0 contains. The function file must have two input arguments t and y even for equations where is not a function of t. The syntax is identical for the other solvers.

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations Lets try these on the problem we've been solving 17

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 18 Numerical Methods for Differential Equations Response of an RC Circuit (RC=0.1s, v(0)=0V, y(0)=2V)

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 19 Numerical Methods for Differential Equations Effect of Step Size  The spacing used by ode23 is smaller than that used by ode45 because ode45 has less truncation error than ode23 and thus can use a larger step size.  ode23 is sometimes more useful for plotting the solution because it often gives a smoother curve. Numerical Methods and Linear Equations  It is sometimes more convenient to use a numerical method to find the solution.  Examples of such situations are when the forcing function is a complicated function or when the order of the differential equation is higher than two. Use of Global Parameters  The global x y z command allows all functions and files using that command to share the values of the variables x, y, and z.

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 20

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 21 Extension to Higher-Order Equations The Cauchy form or the state-variable form  Consider the second-order equation (8.6-1) (8.6-2)  If,, then The Cauchy form or state-variable form

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 22 Extension to Higher-Order Equations Solve (8.6-1) for with the initial conditions. ( Suppose that and use ode45.) %Define the function function xdot=example1(t,x) xdot(1)=x(2); xdot(2)=(1/5) * (sin(t) - 4*x(1) - 7*x(2)); xdot = [xdot(1) ; xdot(2)]; %then, use it: [t, x] = ode45('example1',[0,6],[3,9]); plot(t,x); xdot(1) xdot(2) x(1) x(2) The initial condition for the vector x. The time interval of interest

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 23 Extension to Higher-Order Equations Matrix Methods ( Letting, ) (Matrix form) (Compact form) (8.6-6) (8.6-7)

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 24

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 25

The following is extra credit (2 pts) 26

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 27 Extension to Higher-Order Equations Characteristic Roots from the eig Function  Substituting,  Cancel the terms  Its roots are s = and s = (8.6-8) A nonzero solution will exist for A1 and A2 if and only if the deteminant is zero

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 28 Extension to Higher-Order Equations  MATLAB provides the eig function to compute the characteristic roots.  Its syntax is eig(A) The matrix A for the equations (8.6-8) and (8.6-9) is  To find the time constants, which are the negative reciprocals of the real parts of the roots, you type tau = -1./real (r). The time constants are and

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 29 Extension to Higher-Order Equations Programming Detailed Forcing Functions ▪ Apply Kirchhoff’s voltage low and Newton’s low (8.6-10) (8.6-11) ( matrix form ) : motor’s current, : rotational velocity L: inductance, R: resistance, I: inertia, : torque constant, : back emf constant, c: viscous damping constant, : applied voltage Letting

Acsl, Postech MATLAB 입문 : Chapter 8. Numerical Calculus and Differential Equations 30