Numerical methods for solving ODEs

Similar documents
Numerical Methods - Initial Value Problems for ODEs

Higher Order Taylor Methods

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

2.1 Differential Equations and Solutions. Blerina Xhabli

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

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

Euler s Method, cont d

Initial value problems for ordinary differential equations

Consistency and Convergence

Fourth Order RK-Method

Math 128A Spring 2003 Week 12 Solutions

Numerical Differential Equations: IVP

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

Initial value problems for ordinary differential equations

dt 2 The Order of a differential equation is the order of the highest derivative that occurs in the equation. Example The differential equation

Chapter 1: Introduction

The integrating factor method (Sect. 1.1)

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

Section 7.2 Euler s Method

9.2 Euler s Method. (1) t k = a + kh for k = 0, 1,..., M where h = b a. The value h is called the step size. We now proceed to solve approximately

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

APPLICATIONS OF FD APPROXIMATIONS FOR SOLVING ORDINARY DIFFERENTIAL EQUATIONS

Section 2.1 Differential Equation and Solutions

FORTRAN 77 Lesson 7. Reese Haywood Ayan Paul

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

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

Calculus for the Life Sciences

Chap. 20: Initial-Value Problems

Homogeneous Equations with Constant Coefficients

Linear Multistep Methods I: Adams and BDF Methods

We begin exploring Euler s method by looking at direction fields. Consider the direction field below.

Chapter 2: First Order DE 2.4 Linear vs. Nonlinear DEs

Introduction to Initial Value Problems

Chapter 11 ORDINARY DIFFERENTIAL EQUATIONS

1.2. Direction Fields: Graphical Representation of the ODE and its Solution Let us consider a first order differential equation of the form dy

Numerical Analysis MTH603. dy dt = = (0) , y n+1. We obtain yn. Therefore. and. Copyright Virtual University of Pakistan 1

1 Error Analysis for Solving IVP

Ordinary differential equation II

Harman Outline 1A Calculus CENG 5131 PDF

INTRODUCTION TO COMPUTER METHODS FOR O.D.E.

multistep methods Last modified: November 28, 2017 Recall that we are interested in the numerical solution of the initial value problem (IVP):

Ordinary Differential Equations

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

Ordinary Differential Equations I

Introductory Numerical Analysis

ECE257 Numerical Methods and Scientific Computing. Ordinary Differential Equations

ENGI Parametric Vector Functions Page 5-01

A Brief Introduction to Numerical Methods for Differential Equations

Numerical solution of ODEs

Chapter 6 - Ordinary Differential Equations

Section 7.4 Runge-Kutta Methods

Lecture Notes on Numerical Differential Equations: IVP

Multistep Methods for IVPs. t 0 < t < T

Ordinary Differential Equations I

Lecture 5: Single Step Methods

Problem Score Possible Points Total 150

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

x 1. x n i + x 2 j (x 1, x 2, x 3 ) = x 1 j + x 3

5. Hand in the entire exam booklet and your computer score sheet.

Math 132 Lab 3: Differential Equations

On linear and non-linear equations. (Sect. 1.6).

Variable Step Size Differential Equation Solvers

10 Numerical Solutions of PDEs

Math 252 Fall 2002 Supplement on Euler s Method

MecE 390 Final examination, Winter 2014

8. Set up the integral to determine the force on the side of a fish tank that has a length of 4 ft and a heght of 2 ft if the tank is full.

Ordinary Differential Equations

1 Ordinary Differential Equations

Problem Score Possible Points Total 150

Lecture 42 Determining Internal Node Values

Ordinary Differential Equations I

Math Homework 3 Solutions. (1 y sin x) dx + (cos x) dy = 0. = sin x =

Qualitative analysis of differential equations: Part I

Lecture Notes for Math 251: ODE and PDE. Lecture 7: 2.4 Differences Between Linear and Nonlinear Equations

5. Ordinary Differential Equations. Indispensable for many technical applications!

Simple ODE Solvers - Derivation

Initial Value Problems for. Ordinary Differential Equations

Solving systems of first order equations with ode Systems of first order differential equations.

Outline Calculus for the Life Sciences II. Pollution in a Lake 1. Introduction. Lecture Notes Numerical Methods for Differential Equations

DON T PANIC! If you get stuck, take a deep breath and go on to the next question. Come back to the question you left if you have time at the end.

Runge-Kutta methods. With orders of Taylor methods yet without derivatives of f (t, y(t))

Fall 2003 Math 308/ Numerical Methods 3.6, 3.7, 5.3 Runge-Kutta Methods Mon, 27/Oct c 2003, Art Belmonte

(1) Rate of change: A swimming pool is emptying at a constant rate of 90 gal/min.

3.5: Euler s Method (cont d) and 3.7: Population Modeling

SIMPLE MULTIVARIATE OPTIMIZATION

MA108 ODE: Picard s Theorem

Ordinary differential equations - Initial value problems

1 Systems of First Order IVP

Part IB Numerical Analysis

Matrix Solutions to Linear Systems of ODEs

MTH 452/552 Homework 3

Review. The derivative of y = f(x) has four levels of meaning: Physical: If y is a quantity depending on x, the derivative dy

Polytechnic Institute of NYU MA 2132 Final Practice Answers Fall 2012

Section 2.1 (First Order) Linear DEs; Method of Integrating Factors. General first order linear DEs Standard Form; y'(t) + p(t) y = g(t)

Ordinary Differential Equations (ODEs)

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

Numerical Methods - Boundary Value Problems for ODEs

Ordinary Differential Equations

Projects and Investigations to accompany Mathematics for Electrical Engineering and Computing

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

Transcription:

Chapter 2 Numerical methods for solving ODEs We will study two methods for finding approximate solutions of ODEs. Such methods may be used for (at least) two reasons the ODE does not have an exact solution or, the solution is difficult to find even if we know or could find the exact solution we are only interested in obtaining a approximate solution (for example to estimate the solutions at a given time or to draw a plot of the solution.) The methods to be considered are both easy to use but are not as fast or as reliably accurate as the methods most often used on a computer to solve real problems. Nevertheless they illustrate the important aspects of the techniques involved in numerical integration of ODEs. 2.1 Euler s method Consider the initial value problem dy dt = f(t, y), y(a) = A. (2.1) We will assume that this has a unique solution y(t). The value of this solution at t = a + h may be approximated using Taylor s theorem to obtain y(a + h) y(a) + h dy dt (a), and then using the ODE (2.1) to express the derivative of y in terms of y and t, y(a + h) y(a) + hf(a, y(a)). If we define t 0 := a, y 0 := y(a), t 1 := a + h, we can express the above result in the following way; y 1 := y 0 + hf(t 0, y 0 ) gives an approximation to y(t 1 ). This method of approximating the solution to an initial value problem is usually called Euler s method. The absolute error (or sometimes just error) ε and the relative error ε r in this approximation are ε = y(t 1 ) y 1, ε r = y(t 1) y 1. y(t 1 ) Figure 2.1 gives a geometrical interpretation of Euler s method in which the solution between t = t 0 and t = t 1 is approximated by the tangent to the solution curve at (t 0, y 0 ). We wish to repeat this process through a number of steps in time and to describe this it is useful to extend the above notation; t 2 := t 1 + h, y 2 := y 1 + hf(t 1, y 1 ) t 3 := t 2 + h, y 3 := y 2 + hf(t 2, y 2 )..... 18

Figure 2.1: Geometrical interpretation of Euler s method that is, t 0 := a, t i+1 := t i + h for i = 0, 1, 2,... (2.2) y 0 := y(t 0 ), y i+1 := y i + hf(t i, y i ) for i = 0, 1, 2,.... (2.3) Here y i gives an approximation to y(t i ) and the lines joining (t 0, y 0 ) to (t 1, y 1 ) to to (t n, y n ) gives an approximation to the solution curve y as a function of t on the time interval [t 0, t n ], that is [a, a + nh], as shown in Figure 2.2. Figure 2.2: Approximate solution found by Euler s method Euler s method algorithm To approximate the solution to the initial value problem (2.1) on the interval [a, b] Euler s method expressed in algorithmic form as follows Pseudo code Set t=a and y=a Repeat while t < b { Set F=f(t,y), t=t+h and y=y+hf } Maple code t:=a; y:=a; ans:=[t,y]; while t<b do F:=f(t,y); t:=t+h; y:=y+h*f; ans:=ans,[t,y]; od; 19

This algorithm is illustrated in the following example. Example 2.1 Use Euler s method with h = 1.0, h = 0.5 and h = 0.25 to approximate y(1) where y(t) is the solution of the initial value problem dy dt = y + t, y(0) = 1. Show that the exact solution of this IVP is y(t) = 2e t t 1 and find the relative error in y(1) for each step length. Solution We use the algorithm described above with F = f(t, y) = y + t and work to six significant figures throughout. h = 1.0 F t y - 0.0 1.0 1.0 1.0 2.0 Therefore h = 1 give the approximation y 1 = 2.0 to y(1). h = 0.5 F t y - 0.0 1.0 1.0 0.5 1.5 2.0 1.0 2.5 Therefore h = 0.5 give the approximation y 2 = 2.5. h = 0.25 F t y - 0.0 1.0 1.0 0.25 1.25 1.5 0.5 1.625 2.125 0.75 2.15625 2.90625 1.0 2.88281 Therefore h = 0.25 give the approximation y 4 = 2.88281. For y(t) = 2e t t 1, dy dt = 2et 1 = y + t, y(0) = 2e 0 0 1 = 1, therefore y(t) = 2e t t 1 is the solution of the IVP. The exact answer is therefore y(1) = 2e 2 = 3.43656. The relative errors for the different values of h are h ε r 1.0 0.418023 0.5 0.272528 0.25 0.161135 Observe in the above table that as the step size h is halved, the relative error is also halved. For smaller h this phenomenon persists h ε r 0.1 0.0724795 0.01 0.00783632 0.001 0.000788579 20

and we see that the relative error is of the same order as the step size. In fact this relationship between error size and step length is true in general and we write ε r = O(h 1 ), and say that Euler s method is an order 1 method. The Maple code to carry out Euler s method in the case h = 0.25 is shown below; h:=0.25; f:=(t,y)->t+y; t:=0; y:=1; ans:=[t,y]; while t<1 do F:=f(t,y); t:=t+h; y:=y+h*f; ans:=ans,[t,y]; od: After this, ans stores the values of t and y as the sequence [0,1],[0.25,1.25],[0.5,1.6250],[0.75,2.156250],[1,2.88281250]. To plot the corresponding approximate solution curve, the following Maple code may be used and with(plots); pointplot([ans],style=line); with(plots); display({plot(2*exp(t)-t-1,t=0..1),pointplot([ans],style=line),pointplot([ans])}); which plots the exact solution, this curve and the points (t i, y i ) on the same axes. The resulting graph is shown in Figure 2.3. 2.2 The Euler predictor-corrector method This method is also sometimes called the improved Euler s method. The aim of this method is the same as Euler s method, to approximate y(t 1 ) = y(a + h) for the solution of the IVP (2.1). First, as in Euler s method the tangent to the solution through (t 0, y 0 ), of gradient f(t 0, y 0 ), is used predict an approximation z 1 to y(t 1 ), that is t 1 := t 0 + h, z 1 := y 0 + hf(t 0, y 0 ). The gradient of the solution curve through (t 1, z 1 ) is then used to correct the first approximation by using the line through (t 0, y 0 ) whose gradient is the average of f(t 0, y 0 ) and f(t 1, z 1 ) This is illustrated in Figure 2.4 y 1 := y 0 + h 2 (f(t 0, y 0 ) + f(t 1, z 1 )). Euler predictor-corrector method algorithm To approximate the solution to the initial value problem (2.1) on the interval [a, b] the Euler predictor corrector method expressed in algorithmic form as follows Pseudo code Set t=a and y=a Repeat while t < b { Set F=f(t,y), t=t+h and z=y+hf Set Z=f(t,z), y=y+h(f+z)/2 } Maple code t:=a; y:=a; ans:=[t,y]; while t<b do F:=f(t,y); t:=t+h; z:=y+h*f; Z:=f(t,z); y:=y+h*(f+z)/2; ans:=ans,[t,y]; od; 21

Euler's method and exact solution 3 2.5 2 1.5 1 0 0.2 0.4 t 0.6 0.8 1 Figure 2.3: Euler s method and exact solution in Maple Example 2.2 Repeat the numerical parts of Example 2.1 using the Euler predictor-corrector method rather than Euler s method. Compare the relative errors for the two methods for the different step lengths. Solution Here F = t + y and Z = t + z. In evaluating F and Z we always use the most recent values of the arguments; for F the values of t and y used are on the previous row but for Z they are on the same row. h = 1.0 F t z Z y - 0.0 - - 1.0 1.0 1.0 2.0 3.0 3.0 h = 0.5 22

Figure 2.4: The Euler predictor-corrector method F t z Z y - 0.0 - - 1.0 1.0 0.5 1.5 2.0 1.75 2.25 1.0 2.875 3.875 3.28125 h = 0.25 F t z Z y - 0.0 - - 1.0 1.0 0.25 1.25 1.50 1.3125 1.5625 0.50 1.70312 2.20312 1.78320 2.28320 0.75 2.35400 3.10400 2.45660 3.20660 1.00 3.25826 4.25826 3.38971 Here we tabulate the relative errors for the two methods and different step lengths h Euler ε r Euler p-c ε r 1.0 0.418023 0.127034 0.5 0.272528 0.0451934 0.25 0.161135 0.0136328 Using Maple we can also calculate approximations for smaller step lengths, together with the corresponding relative errors h Euler ε r Euler p-c ε r 0.1 0.072479 0.00244430 0.01 0.007836 0.00002616 0.001 0.000789 0.00000026 From the above tables it is clear that the Euler predictor-corrector relative error is proportional to the square of the step length, in the example at least. In fact, it may be shown that this is true generally for this method and so ε r = O(h 2 ), i.e. Euler predictor-corrector is an order 2 method. 23