Ordinary differential equation II

Similar documents
Scientific Computing: An Introductory Survey

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

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

Lecture 5: Single Step Methods

Ordinary Differential Equations

Consistency and Convergence

Numerical solution of ODEs

Numerical Methods - Initial Value Problems for ODEs

Math 128A Spring 2003 Week 12 Solutions

ECE257 Numerical Methods and Scientific Computing. Ordinary Differential Equations

Ordinary differential equations - Initial value problems

Ordinary Differential Equations II

Euler s Method, cont d

Ordinary Differential Equations II

Initial value problems for ordinary differential equations

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

Applied Math for Engineers

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

Differential Equations

Ordinary Differential Equations: Initial Value problems (IVP)

NUMERICAL SOLUTION OF ODE IVPs. Overview

Initial value problems for ordinary differential equations

AN OVERVIEW. Numerical Methods for ODE Initial Value Problems. 1. One-step methods (Taylor series, Runge-Kutta)

Numerical Differential Equations: IVP

Solving Ordinary Differential equations

1 Error Analysis for Solving IVP

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

Numerical Methods for Differential Equations

Solving scalar IVP s : Runge-Kutta Methods

Ordinary Differential Equations I

Mini project ODE, TANA22

Numerical Methods for Differential Equations

Ordinary Differential Equations

Numerical Methods for the Solution of Differential Equations

CHAPTER 5: Linear Multistep Methods

CS520: numerical ODEs (Ch.2)

Ordinary Differential Equations

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

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

4 Stability analysis of finite-difference methods for ODEs

Differential Equations

Chap. 20: Initial-Value Problems

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

Mathematics for chemical engineers. Numerical solution of ordinary differential equations

1 Ordinary Differential Equations

Ordinary Differential Equations

A Brief Introduction to Numerical Methods for Differential Equations

EXAMPLE OF ONE-STEP METHOD

Ordinary Differential Equations I

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

Higher Order Taylor Methods

Module 4: Numerical Methods for ODE. Michael Bader. Winter 2007/2008

Lecture Notes on Numerical Differential Equations: IVP

Fourth Order RK-Method

Lecture IV: Time Discretization

Review Higher Order methods Multistep methods Summary HIGHER ORDER METHODS. P.V. Johnson. School of Mathematics. Semester

(f(x) P 3 (x)) dx. (a) The Lagrange formula for the error is given by

MTH 452/552 Homework 3

Lecture 4: Numerical solution of ordinary differential equations

Chapter 6 - Ordinary Differential Equations

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

Backward error analysis

Part IB Numerical Analysis


1 Ordinary differential equations

Research Article Diagonally Implicit Block Backward Differentiation Formulas for Solving Ordinary Differential Equations

2 Numerical Methods for Initial Value Problems

Lecture V: The game-engine loop & Time Integration

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

Numerical Analysis II. Problem Sheet 9

Section 7.4 Runge-Kutta Methods

Numerical Methods for Initial Value Problems; Harmonic Oscillators

Solving Ordinary Differential Equations

Ordinary Differential Equations (ODEs)

Ordinary Differential Equations I

FIRST-ORDER ORDINARY DIFFERENTIAL EQUATIONS II: Graphical and Numerical Methods David Levermore Department of Mathematics University of Maryland

Modeling & Simulation 2018 Lecture 12. Simulations

[ ] is a vector of size p.

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

THE TRAPEZOIDAL QUADRATURE RULE

Ordinary Differential Equations

Ordinary Differential Equations

AM205: Assignment 3 (due 5 PM, October 20)

Graded Project #1. Part 1. Explicit Runge Kutta methods. Goals Differential Equations FMN130 Gustaf Söderlind and Carmen Arévalo

Introduction to the Numerical Solution of IVP for ODE

Computational Techniques Prof. Dr. Niket Kaisare Department of Chemical Engineering Indian Institute of Technology, Madras

INTRODUCTION TO COMPUTER METHODS FOR O.D.E.

Numerical Methods for Initial Value Problems; Harmonic Oscillators

Numerical Solution of ODE IVPs

Chapter 10. Initial value Ordinary Differential Equations

Integration of Ordinary Differential Equations

The Definition and Numerical Method of Final Value Problem and Arbitrary Value Problem Shixiong Wang 1*, Jianhua He 1, Chen Wang 2, Xitong Li 1

Solving PDEs with PGI CUDA Fortran Part 4: Initial value problems for ordinary differential equations

CHAPTER 10: Numerical Methods for DAEs

Numerical methods for solving ODEs

You may not use your books, notes; calculators are highly recommended.

Chapter 9b: Numerical Methods for Calculus and Differential Equations. Initial-Value Problems Euler Method Time-Step Independence MATLAB ODE Solvers

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

Chapter 5 Exercises. (a) Determine the best possible Lipschitz constant for this function over 2 u <. u (t) = log(u(t)), u(0) = 2.

2.29 Numerical Fluid Mechanics Fall 2011 Lecture 20

Transcription:

Ordinary Differential Equations ISC-5315 1 Ordinary differential equation II 1 Some Basic Methods 1.1 Backward Euler method (implicit method) The algorithm looks like this: y n = y n 1 + hf n (1) In contrast to the explicit forward Euler method we need to solve a non-linear equation at each time step. Backward Euler is also of order 1 and O(h) convergent like forward Euler, but it is more stable than forward Euler. Example: Logistic population growth function N (t) = rn(t)(1 N(t) K ) (2) where r is the intrinsic growth rate, and K is the carrying capacity (maximum of individuals the environment will be able to support). backeuler[a_, b_, h_, n0_] := Module[{i, K, r, xx = {}, res, t}, res = n0; K = 200; r = 0.1; t = (b - a)/h; For[i = 0, i < t, i++, (*Solve[rn == res + h (r rn (1-rn/K)),rn]*) res = (-K + h K r + Sqrt[(-K + h K r)^2 + 4 h K r res])/(2 h r); AppendTo[xx, {h i, res}] ]; xx ] euler[a_, b_, h_, n0_] := Module[{K, r, i, xx = {}, res, t}, res = n0; K = 200; r = 0.1; t = (b - a)/h; For[i = 0, i < t, i++, res += h (r res (1 - res/k)); AppendTo[xx, {h i, res}] ]; xx ] 1 Peter Beerli; April 5, 2011

Ordinary Differential Equations ISC-5315 2 200 150 100 50 Figure 1: Comparison of solutions of the logistic population growth: dashed line is Backward Euler with h = 0.1 and also the analytical solution, solid line is the forward Euler with stepsize h = 0.01. 1.2 Midpoint method (explicit multistage method) The midpoint method is sometimes called modified Euler method and is also an example of a Runge-Kutta method, one needs to do more work but is considerably more accurate than the Euler methods. It is also explicit and can be built up easily. y n+1/2 = y n + h 2 f(t n, y n ) (3) y n+1 = y n + hf(t n+1/2, y n+1/2 ) (4) The midpoint method is a second order method: O(h 2 ) 1.3 Heun s method (predictor-corrector) Heun s method has several other names: modified Euler s method or the explicit trapezoidal rule. It can be seen as an extension of Euler s method into a two-stage second order Runge-Kutta method. It proceeds first to calculate an approximate y n + 1 using forward Euler and then refines that estimate: Figure 2: Illustration of the midpoint method (Wikipedia) ỹ n+1 = y n + hf(t n, y n ) (5) y n+1 = y n + h 2 (f(t n, y n ) + f(t n+1, ỹ n+1 ) (6) Heun s method is a predictor-corrector method using the forward Euler s method as predictor and the trapezoidal method as the corrector. 2 Evaluation of solutions We saw with the Euler method that we need to check our results. Without analytical results this is rather difficult and we need to develop a language to discuss such issues. We need to be able to explore the local truncation or discretization error (e.g. h = 0.01 and h = 0.1 in the Euler method). 2 Peter Beerli; April 5, 2011

Ordinary Differential Equations ISC-5315 3 We need to worry about the global error because we sum over larger numbers of small steps that propagate the local error. Consistency: Does the discrete approximation approach the exact solution as h goes to zero? (local discretization error) Convergence: Given consistency, how quickly does the discrete approximation approach the exact solution. Stability: How sensitive is the solution to perturbations in the initial conditions or the function? Stiffness 2.1 Consistency Let y(t i ) represent the exact solution to the discrete equations. Let Y (t i ) represent the exact solution to the IVP. Now ask whether y(t i ) approach Y (t i ) as h is reduced. We define a difference operator for a numerical method. For example for the Euler method we have N h (y n ) = y(t n) y(t n 1 ) h Let y = {y 0, y 1,..., y N } and Y = {Y 0, Y 1,..., Y N } then For the forward Euler method we then can rephrase f(t n 1, y n 1 ) (7) N h (y) = 0 (8) N h (Y) = d 0 (9) N h (y) = y n y n 1 h f n 1 (10) the local truncation error d is the residual, when the difference operator is applied to the exact solution N h (Y ) = Y n Y n 1 h f n 1 = d (11) where d is the local truncation error. For a consistent method d goes to zero as h goes to zero and the discrete solution approaches the continuous solution. 2.2 Convergence Example for consistency and convergence (local error): improvement of d using (11) on a very simply ODE. y (t) = sin t with y(0) = 1 2, its analytical is solution is y(t) = 1 1 2 cos t Replacing the Y n and Y n 1 with y(t n ) and y(t h), respectivelyand the f n 1 with y (t h) we can look ad the effect of different h on d. For an ODE over the interval [a, b] when we reduce h the local error decreases, but the number of steps increases N = (b a)/h, but for convergent methods the local error decreases at a faster rate than the global error increases, if convergent then lim y = Y Nh = (b a) (12) h 0 3 Peter Beerli; April 5, 2011

Ordinary Differential Equations ISC-5315 4 0.10 0.05 2 4 6 8 10 0.05 0.10 Figure 3: the difference between the true results and the Euler method for different stepsizes h = { 1 4, 1 8, 1 16 } (solid line, narrow dashing, wide dashing).) Convergence describes the rate at which the discrete solutions approach the continuous (true) solution. The global error is a method N h converges with order p, if for all n ɛ n = y n Y (t n ) with e 0 = 0 (13) ɛ n = O(h p ) (14) For the forward Euler method we can get the exact solution using a Taylor expansion around t n 1 Y n = Y n 1 + hy (t n 1 ) + h2 2! Y (ξ) (15) N h (Y (t n ) = Y n Y n 1 h f n 1 = O(h) (16) where N h is the local truncation error and the Euler method shows first order convergence Consider a general linear problem over t = [a, b] Applying Euler leads to d = O(h) (17) y (t) = λy(t) + g(t) (18) y n = (1 + hλ)y n 1 + hg(t n 1 ) (19) using the Taylor expansion (15) we get for this particular problem Y n = (1 + hλ)y n 1 + hg(t n 1 ) + h2 2! Y (ξ) (20) 4 Peter Beerli; April 5, 2011

Ordinary Differential Equations ISC-5315 5 the last term is the local error and is equivalent to To calculate the global error we fill in This difference equation can be solved and for general non-linear problem, it can be shown that it is For our simply problem y (t) = sin(t) we calculate hd n 1 (21) e n = Y n y N (22) = (1 + hλ)e n 1 hd n 1 (23) e n (b a)e λ (b a) O(h) (24) e n T e LT O(h) (25) e N = e N 1 + hd n 1 = e N 1 + h [(Y (t) Y (t h))/h sin(t h)] (26) For h = 1/4 : e N = 0.81655, h = 1/8 : e N = 0.409205, h = 1/16 : e N = 0.204526. 2.2.1 Summary Consistency relates to the size of the local error (hd n ) Convergence relates to the size of the global error which depends on the how local errors propagate All methods in the real-world are consistent and convergent: if you make h small enough you can solve the problem. 2.3 Absolute Stability is based on a test equation with complex λ and real y 0 with the exact solution y = λy, y 0 (27) y(t) = y 0 e λt (28) The behavior depends in values of λ and we can test how the numerical methods responds to this equation. The characteristics of the exact solution are: Re(λ) < 0 lim y(t) = 0 t (damped) (29) Re(λ) = 0 lim y(t) = y 0 t (oscillatory) (30) Re(λ) > 0 lim y(t) = t (unbounded) (31) We would want that the numerical solution has the same characteristics, particularly for λ 0. The region of absolute stability of a numerical solution is defined as the region on the complex plane defined by hλ, for which the solution the numerical scheme remains bounded. If it is bounded in the left-hand plane Re(hλ) < 0 the the methods is called A-stable. The right-hand plane behavior depends on the application: stable, unstable does not matter. (32) 5 Peter Beerli; April 5, 2011

Ordinary Differential Equations ISC-5315 6 2.3.1 Stability of the presented methods Forward Euler: Testing the absolute stability with the test equation, forward Euler method is it is stable if y n = y n 1 + hλy n 1 (33) y n = 1 + hλ y n 1 (34) 1 + hλ 1, (35) this is a disk with unit radius centered at ( 1, 0), therefore the Forward Euler method is not A-stable. Backward Euler: Testing the absolute stability with the test equation, backward Euler method is it is stable if y n = y n 1 + hλy n (36) y n 1 = y n 1 1 hλ (37)!"#$%&'%(')*+%,-."'/.0*$,$.1 1 + hλ 1, (38) this is the area outside a disk with unit radius centered at (1, 0), therefore the Backward Euler method is A-stable Figure!"#$%&'()&#(&*$#&#'$+$&,(%&-./0(.1#&-$#'(/&$"+.23 4: Stability regions for Forward and Backward Euler methods!! 6 Peter Beerli; April 5, 2011

Ordinary Differential Equations ISC-5315 7 2.4 Stiffness Normally the step-size h required for accurate estimation is smaller than the step-size required for stability. accuracy: discrete solution approaches true continuous solution stability: discrete solution doesn t blow up h accuracy h stability For stiff problems, the opposite is true. Stability is a bigger concern! h accuracy h stability A stiff equation is a differential equation for which certain numerical methods for solving the equation are numerically unstable, unless the step size is taken to be extremely small. It has proven difficult to formulate a precise definition of stiffness, but the main idea is that the equation includes some terms that can lead to rapid variation in the solution. (http://en.wikipedia.org/wiki/stiff equation) Stiffness depends on: the initial value problem interval of integration size and location accuracy requirements the region of absolute stability of the method There is a competition between accuracy and h stability. Usually, we are after a smooth and slowly varying solution, when perturbations of the data have rapidly varying solutions. A simple example: with solution adding the solution back into the problem has the solution y (t) = sin(t); y(0) = 1 (39) y(t) = cos(t) (40) y (t) = λ[y cos(t)] sin(t); y(t 0 ) = y 0 (41) y(t) = e λ(t t 0) [y 0 cos(t 0 )] + cos(t) (42) The term e λ(t t 0) [y 0 cos(t 0 )] is transient because it decays for Re(λ) < 0. Perturbations occur naturally because of truncation errors in numerical solutions, Figure 5 shows such perturbations of the exact function. If we use that particular problem y (t) = λ[y cos(t)] sin(t); y(0) = 1; λ = 10 (43) Solving this using the forward and backward Euler method using a λ = 10 and changing the stepsize h. I used these mathematica scripts to generate the plots in figure 6 7 Peter Beerli; April 5, 2011

!"#$$%&'' Ordinary Differential Equations ISC-5315 8!!"##$%$&'("&"'")*(+,&-"'",&.(/' 0 1(2 0 3 λ= 1 λ= 10!"#$!"#$ %&%#%'()*+&,%#%+&)'-)./0#102'#%+&!! Figure 5: Initial value perturbations by different values of t 0 at different values for λ euler[a_, b_, h_, \[Lambda]_] := Module[{i, xx = {}, res, t}, res = 0.5; t = (b - a)/h; For[i = 0, i < t, i++, res += h (\[Lambda] (res \[Minus] Cos[h i]) - Sin[h i]); AppendTo[xx, {h i, res}] ]; xx ] backeuler[a_, b_, h_, \[Lambda]_] := Module[{i, xx = {}, res, t}, res = 0.5; t = (b - a)/h; For[i = 0, i < t, i++, (*Solve[rn == res + h(l(rn\[minus]cos[i h + h])-sin[i h + h]),rn]*) res = (-res + h \[Lambda] Cos[h + h i] + h Sin[h + h i])/(-1 + h \[Lambda]); AppendTo[xx, {h i, res}] ]; xx ] 2.5 L-Stability Same test problem as A-stability but the test changes to lim Re(hλ) y = λy, y(0) = y 0 (44) y n y n 1 = 0. (45) 8 Peter Beerli; April 5, 2011

Ordinary Differential Equations ISC-5315 9 2 1 2 1 2 4 6 8 2 4 6 8 10 1 2 1 2 Figure 6: left graph uses h = 0.1, right graph uses h = 0.195, the dashed line is the backward Euler method, the solid line is the forward Euler. If the fraction approaches this limit then the solution is L-stable. Forward Euler: lim Re(hλ) y n y n 1 = 1 + hλ. (46) Backward Euler: lim Re(hλ) y n y n 1 = 1 0. (47) 1 hλ Therefore the Backward Euler method is L-stable, but Forward-Euler is not. Stiffness is quite common when multiple time scales are present in the problem, and this is a frequent problem in systems of ODEs. 9 Peter Beerli; April 5, 2011