What we ll do: Lecture 21. Ordinary Differential Equations (ODEs) Differential Equations. Ordinary Differential Equations

Similar documents
CS 450 Numerical Analysis. Chapter 9: Initial Value Problems for Ordinary Differential Equations

Numerical solution of ODEs

Differential Equations

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Lecture Notes to Accompany. Scientific Computing An Introductory Survey. by Michael T. Heath. Chapter 9

Numerical Methods for Initial Value Problems; Harmonic Oscillators

NUMERICAL SOLUTION OF ODE IVPs. Overview

Ordinary Differential Equations

Scientific Computing: An Introductory Survey

Numerical Methods for Initial Value Problems; Harmonic Oscillators

ECE257 Numerical Methods and Scientific Computing. Ordinary Differential Equations

Numerical Methods - Initial Value Problems for ODEs

Ordinary Differential Equations II

Ordinary differential equation II

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Chap. 20: Initial-Value Problems

Initial value problems for ordinary differential equations

Ordinary Differential Equations II

Chapter 11 ORDINARY DIFFERENTIAL EQUATIONS

Euler s Method, cont d

8.1 Introduction. Consider the initial value problem (IVP):

Ordinary Differential Equations

Lecture Notes on Numerical Differential Equations: IVP

Ordinary Differential Equations

Finite Differences for Differential Equations 28 PART II. Finite Difference Methods for Differential Equations

Chapter 6 - Ordinary Differential Equations

Lecture 5. Complex Numbers and Euler s Formula

CS520: numerical ODEs (Ch.2)

Initial value problems for ordinary differential equations

Consistency and Convergence

Math 660 Lecture 4: FDM for evolutionary equations: ODE solvers

APPLICATIONS OF FD APPROXIMATIONS FOR SOLVING ORDINARY DIFFERENTIAL EQUATIONS

[ ] is a vector of size p.

Scientific Computing with Case Studies SIAM Press, Lecture Notes for Unit V Solution of

Numerical Differential Equations: IVP

ODE Runge-Kutta methods

Mathematics for chemical engineers. Numerical solution of ordinary differential equations

Solving scalar IVP s : Runge-Kutta Methods

Math Numerical Analysis Homework #4 Due End of term. y = 2y t 3y2 t 3, 1 t 2, y(1) = 1. n=(b-a)/h+1; % the number of steps we need to take

Introduction to standard and non-standard Numerical Methods

Finite Difference and Finite Element Methods

Fourth Order RK-Method

4 Stability analysis of finite-difference methods for ODEs

2tdt 1 y = t2 + C y = which implies C = 1 and the solution is y = 1

Differential Equations

Integration of Ordinary Differential Equations

DELFT UNIVERSITY OF TECHNOLOGY Faculty of Electrical Engineering, Mathematics and Computer Science

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

1 Systems of First Order IVP

Applied Math for Engineers

Ordinary Differential Equations

The family of Runge Kutta methods with two intermediate evaluations is defined by

Simple ODE Solvers - Derivation

10 Numerical Solutions of PDEs

Chapter 8. Numerical Solution of Ordinary Differential Equations. Module No. 1. Runge-Kutta Methods

Numerical Methods for Partial Differential Equations. CAAM 452 Spring 2005 Lecture 2 Instructor: Tim Warburton

Numerical Methods for Differential Equations

Numerical Methods for Differential Equations

Introduction to the Numerical Solution of IVP for ODE

7 Hyperbolic Differential Equations

Solution via Laplace transform and matrix exponential

Ordinary Differential Equations

MB4018 Differential equations

Numerical Solution of Differential Equations

Modeling and Experimentation: Compound Pendulum

Second Order ODEs. CSCC51H- Numerical Approx, Int and ODEs p.130/177

1 Error Analysis for Solving IVP

Lecture 4: Numerical solution of ordinary differential equations

INTRODUCTION TO COMPUTER METHODS FOR O.D.E.

Selected HW Solutions

Numerical method for approximating the solution of an IVP. Euler Algorithm (the simplest approximation method)

Dynamics of Adaptive Time-Stepping ODE solvers

Ordinary Differential Equations (ODEs)

Lecture IV: Time Discretization

EXAMPLE OF ONE-STEP METHOD

Review. Numerical Methods Lecture 22. Prof. Jinbo Bi CSE, UConn

Numerical Methods for the Solution of Differential Equations

Section 7.4 Runge-Kutta Methods

MA/CS 615 Spring 2019 Homework #2

Solving Ordinary Differential Equations

Stability regions of Runge-Kutta methods. Stephan Houben Eindhoven University of Technology

Ordinary Differential Equations

Woods Hole Methods of Computational Neuroscience. Differential Equations and Linear Algebra. Lecture Notes

A Brief Introduction to Numerical Methods for Differential Equations

Numerical Methods for Differential Equations

The integrating factor method (Sect. 1.1)

Mathematics 22: Lecture 10

Solution: (a) Before opening the parachute, the differential equation is given by: dv dt. = v. v(0) = 0

The Finite Element Method for the Analysis of Non-Linear and Dynamic Systems: Non-Linear Dynamics Part I

2.29 Numerical Fluid Mechanics Fall 2011 Lecture 20

Physically Based Modeling: Principles and Practice Differential Equation Basics

The Plan. Initial value problems (ivps) for ordinary differential equations (odes) Review of basic methods You are here: Hamiltonian systems

4. Numerical analysis II

Physically Based Modeling Differential Equation Basics

Part 1. The diffusion equation

Ordinary Differential Equations: Initial Value problems (IVP)

25 Self-Assessment. 26 Eigenvalue Stability for a Linear ODE. Chapter 7 Eigenvalue Stability

Mathematics 22: Lecture 11

Lecture V: The game-engine loop & Time Integration

Finite Difference Methods for Boundary Value Problems

Transcription:

What we ll do: Lecture Ordinary Differential Equations J. Chaudhry Department of Mathematics and Statistics University of New Mexico Review ODEs Single Step Methods Euler s method (st order accurate) Runge-Kutta methods (higher order accuracy) Accuracy and stability of the methods J. Chaudhry (UNM) CS 357 / 34 Differential Equations J. Chaudhry (UNM) CS 357 / 34 Ordinary Differential Equations (ODEs) Its hard to model the state of a system Temperature in the room Pressure on the wing of an airplane Concentration of ions in a solvent and a million more However, its much simpler to model the rate of change of the state: differential equations Could involve change w.r.t to one variable (e.g. time): Ordinary Differential Equations Could involve change w.r.t multiple variables (e.g. x and y axis): Partial Differential Equations An ODE involves One function u(t) Its derivatives u (t), u (t), u (t), etc Order of ODE is the higest order derivative Examples: Generic First-order ODE u = f (t, u(t)) Harmonic Oscillator (Second-order ODE) mu (t) + cu (t) + ku(t) = f (t) m: mass, c damping coeff., k: elastic stiffness coeff, f (t): external force J. Chaudhry (UNM) CS 357 3 / 34 J. Chaudhry (UNM) CS 357 4 / 34

Initial Value Problems (IVPs) Numerical Solution of IVPs ODEs in previous examples have infinitely many solutions Get unique solution by specifying initial conditions (ICs) Examples: IVP = ODE + IC u = f (t, u(t)), t (a, b] u(a) = u a mu (t) + cu (t) + ku(t) = f (t), t (0, T] u(0) = A, u (0) = B Many important ODEs have no closed form solution Analytical methods of limited use in such scenarios Approximate the solution using numerics Consider first order ODE u = f (t, u(t)), t (a, b] u(a) = u a Discretize [a, b] into equi-spaced points: with h = t i t i = (b a)/n a = t 0 < t < t < < t n < t n = b J. Chaudhry (UNM) CS 357 5 / 34 Euler s method J. Chaudhry (UNM) CS 357 6 / 34 Euler Example Simplest numerical methods to solve IVPs Taylor s thm u(t + h) = u(t) + hu (t) + (h /)u (c), Let u i be approximation to exact solution u(t i ) Drop O(h ) terms and utilize u (t) = f (t, u) t < c < t + h Apply Euler s method with h = 0. to the IVP u = tu + t 3, t [0, ] u(0) = h = (b a)/n = n = 5. Step i t i u i f (t i, u i ) u i+ = u i + hf (t i, u i ) u 0 = u a for i = 0 to n 3 u i+ = u i + h f (t i, u i ) Listing : Euler Algorithm 0 0 0 0. 0.080.046 0.4.046 0.4806.377 3 0.6.377 0.8986.375 4 0.8.375.5660.6306 5.6306 J. Chaudhry (UNM) CS 357 7 / 34 J. Chaudhry (UNM) CS 357 8 / 34

Euler Example Accuracy of Euler s method Exact solution is u(t) = 3e t / t Euler method with h = 0., 0., 0.05 As h decreases, approximation converges to exact solution Compute the error at final time, t = Error, e = O(h p ) loglog plot 0 0.9.8.7 Exact Soln Euler (h=/5) Euler (h=/0) Euler (h=/0) 0 -.6 Error u(t).5.4 0 -.3.. 0 0. 0. 0.3 0.4 0.5 0.6 0.7 0.8 0.9 t p appears to be 0-3 0-4 0-3 0-0 - h J. Chaudhry (UNM) CS 357 9 / 34 Accuracy of Euler s method J. Chaudhry (UNM) CS 357 0 / 34 Accuracy of Euler s method: Some Theory Compute the error at final time, t = Error, e = O(h p ) p p log(e k/e k ) log(h k /h k ) Experiment k e k e k h k h k p 0 0.78 - /0 - - 0.0899 0.78 /0 /0 0.93 0.04603 0.0899 /40 /0 0.96 3 0.039 0.04603 /80 /40 0.98 4.07 0.039 /60 /80 0.99 Euler s method is first-order accurate method Can theoretically show this too Recall the derivation using Taylor s thm Exact solution Numerical soln u(t + h) = u(t) + hf (t, u) + O(h ) u i+ = u i + hf (t i, u i ) Assume u(t) = u i. Then the local error, u(t + h) u i+ is u(t + h) u i+ = O(h ) Global error is the error at final time: u(t n ) u n Local errors accumulates to give O(nh ) = O(h) accuracy since nh = (b a). The analysis for glocal error is complicated and we omit it. J. Chaudhry (UNM) CS 357 / 34 J. Chaudhry (UNM) CS 357 / 34

Systems of ODEs Euler method for first-order system of ODEs A first-order system of m ODEs has the form u = f (t, u, u,..., u m ) u = f (t, u, u,..., u m ) t (a, b]. u m = f m (t, u, u,..., u m ) In IVPs, each variable has its own initial condition: u (a) = u a u (a) = u a. u m (a) = u ma Apply scalar Euler s method to each component Example: apply Euler s method to u = u + u = f (t, u, u ), u (0) = 0 u = tu = f (t, u, u ), u (0) = Euler s method: u,i+ = u,i + h( u,i + u,i ) u,i+ = u,i + h( t i u,i ) J. Chaudhry (UNM) CS 357 3 / 34 Higher order equations J. Chaudhry (UNM) CS 357 4 / 34 Euler s method for Higher order equations Convert higher order ODE to system to first order ODEs Consider u + au + btu = c Introducte y = u y = u This leads to the following first-order ODE system y = y y = ay bty + c Now apply Euler s method! We get approximation to y = u. Solve the following IVP using Euler s method: u = (u ) uu + sin t, u(0) =, u (0) = 0, u (0) = Convert to first-order system: y = u, y = u, y 3 = u Euler s method: y = y, y (0) = y = y 3, y (0) = 0 y 3 = y 3 y y + sin t, y 3 (0) = y,i+ = y,i + hy,i y,i+ = y,i + hy 3,i y 3,i+ = y 3,i + h(y 3,i y,iy,i + sin t i ) J. Chaudhry (UNM) CS 357 5 / 34 J. Chaudhry (UNM) CS 357 6 / 34

Runge-Kutta Methods (RK) Two-stage RK methods Integration both sides of u (t) = f (t, u(t)) from t i to t i+ u(t i+ ) u(t i ) = ti+ t i f (t, u(t)) dt Runge-Kutta methods are popular methods to solve IVPs Euler method is a single-stage RK method (RK) Higher order methods derived using higher order Taylor series, higher order integration techniques etc. Higher order methods have more stages Now apply (simple) trapezoidal rule on the RHS Let u i u(t i ) u(t i+ ) u(t i ) = h [f (t i, u(t i )) + f (t i+, u(t i+ ))] + O(h 3 ) u i+ = u i + h [f (t i, u i ) + f (t i + h, u i+ )] + O(h 3 ) Approx u i+ on RHS by Euler s method u i+ = u i + h [f (t i, u i ) + f (t i + h, u i + f (t i, u i ) + O(h )] + O(h 3 ) J. Chaudhry (UNM) CS 357 7 / 34 RKa method J. Chaudhry (UNM) CS 357 8 / 34 RKb method RKa Drop O(h 3 ) terms. Get method called RKa u i+ = u i + h [f (t i, u i ) + f (t i + h, u i + hf (t i, u i )] Written as a two-stage method K = f (t i, u i ) K = f (t i + h, u i + hk ) u i+ = u i + h( K + K ) K and K are called stages. RKa has has local error of O(h 3 ) for a global error of O(h ). Integration both sides of u (t) = f (t, u(t)) from t i to t i+ u(t i+ ) u(t i ) = Now apply midpoint rule on the RHS ti+ t i f (t, u(t)) dt u(t i+ ) u(t i ) = h[f (t i + h, u(t i + h ))] + O(h3 ) Use Euler s method to approx u(t i + h ) u(t i) + (h/)f (t i, u(t i ) Get RKb method u i+ = u i + hf (t i + h, u i + h f (t i, u i )) J. Chaudhry (UNM) CS 357 9 / 34 J. Chaudhry (UNM) CS 357 0 / 34

RKb method RK4 method RKb Two-stage RKb method K = f (t i, u i ) K = f (t i + h, u i + h K ) u i+ = u i + hk Second order accurate as well RK4 Four stages Derived using Simpson s rule with two subintervals [t i, t i + h/] and [t i + h/, t i + h] K = f (t i, u i ) K = f (t i + h, u i + h K ) K 3 = f (t i + h, u i + h K ) K 4 = f (t i + h, u i + hk 3 ) u i+ = u i + h 6 (K + K + K 3 + K 4 ) Fourth order accurate Arguably the most widely use ODE integrator J. Chaudhry (UNM) CS 357 / 34 Geometric Interpretation of RK methods J. Chaudhry (UNM) CS 357 / 34 Stability: Euler method on a model problem Model problem (Dahlquist model problem) u (t) = λu(t), λ > 0, t [0, T] Euler (or RK) uses the slope at t i : u i = f (t i, u i ) RKa uses the slopes at t i and t i+ which are K and K RKb uses the slopes at t i and t i+ which are K and K RK4 uses the slopes t i K t i+ K +K 3 t i+ K 4 u(0) = u 0 Exact solution is: u(t) = u 0 e λt u 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0. 0. 0 0 0.05 0. 0.5 0. 0.5 0.3 0.35 0.4 0.45 0.5 t Solution u decays exponentially as t increases J. Chaudhry (UNM) CS 357 3 / 34 J. Chaudhry (UNM) CS 357 4 / 34

Stability: Euler method on a model problem What went wrong? Euler method for the model problem: u i+ = u i + h( λu i ) = ( hλ)u i, i = 0,,,... E.g. choose λ = 30, u 0 =, h = 0. u 0 0 0-0 -0-30 Euler method converges when h is small enough What about when h is not sufficiently small? Local accuracy of Euler method is nd order from Taylor series But these local errors can propagate and increase exponentially! Stability quantifies the propagation of errors In the example above we chose a step size for which Euler method was not stable -40 0 0. 0. 0.3 0.4 0.5 t Instead of exponential decay, the approximate solution has a growing oscillatory behavior! J. Chaudhry (UNM) CS 357 5 / 34 Amplification factor J. Chaudhry (UNM) CS 357 6 / 34 Amplification factor of Euler Method Euler method was u i+ = ( hλ)u i u i+ u i = hλ = G i = u i+ u i = hλ G i = u i+ /u i is called the amplification factor at time step i For Euler method, G i = hλ If amplification factor is less than one then numerical solution does not grow without bound. We say the numerical solution is stable For Euler method we need for stability G i < = hλ < = < hλ < = 0 < λh < This gives a step size restriction 0 < h < /λ In the earlier example h = 0., λ = 30 so hλ = 3 > = unstable J. Chaudhry (UNM) CS 357 7 / 34 J. Chaudhry (UNM) CS 357 8 / 34

Region of Stability Region of Stability for Euler s method Let with λ R > 0 λ = λ R + iλ I Why complex number? For system of ODEs λ represents the eigenvalues of the coefficient matrix. Remember the eigenvalues can be complex even if the matrix is real Region of stability: Region in the λh plane where the numerical solver is stable. That is, the region in which the amplification factor G i < G j = hλ = h(λ R + iλ I ) = ( hλ R ) ihλ i = ( hλ R ) + (hλ I ) < Region of stability is circle with center (0, ) and radius : hλ I hλ R J. Chaudhry (UNM) CS 357 9 / 34 Region of Stability for RKb For the model problem we get K = λu j, K = λ(u j h λu j) u j+ = u j ( hλ + (hλ) ) Amplification factor G j = u j+ u j = (hλ) + (hλ) < Want all z = hλ in the complex place such that z + z < Or, find all z such that for all φ [0, π] z + z < e iφ J. Chaudhry (UNM) CS 357 30 / 34 Region of Stability for RKb Solve the quadratic equation Two solutions Im(z) 0 - - z z + ( e iφ ) = 0 z, = ± ze iφ -0.5 0 0.5.5.5 Re(z) Region of stability is the region inside the curves J. Chaudhry (UNM) CS 357 3 / 34 J. Chaudhry (UNM) CS 357 3 / 34

Region of Stability for RK4 Region of Stability for RK4 After similar derivations as earlier we get G j = u j+ u j = (hλ) + (hλ) 6 (hλ)3 + 4 (λh)4 Want z = hλ such that G(z) = z + z 6 z3 + 4 z4 < Plot G j (z) for all possible z values and then plot the -contour of G j Listing : RK4 Stability [x,y] = meshgrid(linspace(-4,4,000), linspace(-4,4,000)); z = x + i*y; 3 contour(x,y, abs( - z + (/)*z.ˆ - (/6)*z.ˆ3 + (/4)*z.ˆ4 ),[, ], k- ); Im(z) 4 3 0 - - -3-4 - 0 3 4 Re(z) J. Chaudhry (UNM) CS 357 33 / 34 J. Chaudhry (UNM) CS 357 34 / 34