Lesson 4: Population, Taylor and Runge-Kutta Methods

Similar documents
Falling Mass and Improved Euler

Falling Mass and Euler Methods

Lesson 9: Predator-Prey and ode45

Lesson 13: Rapid Cooling and Euler-trapezoid

Lesson 13: Rapid Cooling and Euler-trapezoid

Lesson 9: Diffusion of Heat (discrete rod) and ode45

2015 Holl ISU MSM Ames, Iowa. A Few Good ODEs: An Introduction to Modeling and Computation

Lesson 14: Van der Pol Circuit and ode23s

Ordinary Differential Equations

Chap. 20: Initial-Value Problems

MTH 452/552 Homework 3

Fourth Order RK-Method

KINGS COLLEGE OF ENGINEERING DEPARTMENT OF MATHEMATICS ACADEMIC YEAR / EVEN SEMESTER QUESTION BANK

AIMS Exercise Set # 1

First In-Class Exam Solutions Math 246, Professor David Levermore Thursday, 20 September 2018

Section 7.4 Runge-Kutta Methods

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

Taylor Series and stationary points

Euler s Method, cont d

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

Math Assignment 2

Mathematics 22: Lecture 11

An Overly Simplified and Brief Review of Differential Equation Solution Methods. 1. Some Common Exact Solution Methods for Differential Equations

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

Ordinary Differential Equations (ODE)

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

Lecture 4: Numerical solution of ordinary differential equations

3 Applications of partial differentiation

1 (t + 4)(t 1) dt. Solution: The denominator of the integrand is already factored with the factors being distinct, so 1 (t + 4)(t 1) = A

Ordinary Differential Equations

NUMERICAL ANALYSIS PROBLEMS

Consistency and Convergence

Numerical and Statistical Methods

PH36010: Numerical Methods - Evaluating the Lorenz Attractor using Runge-Kutta methods Abstract

FORTRAN 77 Lesson 7. Reese Haywood Ayan Paul

13 Numerical Solution of ODE s

Euler s Method and Logistic Growth (BC Only)

Numerical and Statistical Methods

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

Use separation of variables to solve the following differential equations with given initial conditions. y 1 1 y ). y(y 1) = 1

Ordinary Differential Equations II

Integration of Ordinary Differential Equations

x x2 2 + x3 3 x4 3. Use the divided-difference method to find a polynomial of least degree that fits the values shown: (b)

Introduction to standard and non-standard Numerical Methods

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

INTRODUCTION TO COMPUTER METHODS FOR O.D.E.

Math 128A Spring 2003 Week 12 Solutions

1 Lecture 8: Interpolating polynomials.

δ Substituting into the differential equation gives: x i+1 x i δ f(t i,x i ) (3)

Ordinary Differential Equations: Initial Value problems (IVP)

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

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

Do not turn over until you are told to do so by the Invigilator.

Higher Order Taylor Methods

Numerical Methods - Initial Value Problems for ODEs

Numerical Differential Equations: IVP

First In-Class Exam Solutions Math 246, Professor David Levermore Tuesday, 21 February log(2)m 40, 000, M(0) = 250, 000.

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

Manifesto on Numerical Integration of Equations of Motion Using Matlab

Ordinary differential equations. Phys 420/580 Lecture 8

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

Chapter 11 ORDINARY DIFFERENTIAL EQUATIONS

Brownian Motion. An Undergraduate Introduction to Financial Mathematics. J. Robert Buchanan. J. Robert Buchanan Brownian Motion

Math 308 Week 8 Solutions

Differential Equations

R Function Tutorial in Module 8.2

Physics 584 Computational Methods

Tutorial 2. Introduction to numerical schemes

Numerical Solution of Differential Equations

Lecture 28 The Main Sources of Error

Math Numerical Analysis Mid-Term Test Solutions

ECE257 Numerical Methods and Scientific Computing. Ordinary Differential Equations

FIRST-ORDER SYSTEMS OF ORDINARY DIFFERENTIAL EQUATIONS III: Autonomous Planar Systems David Levermore Department of Mathematics University of Maryland

MECH : a Primer for Matlab s ode suite of functions

Solution. Your sketch should show both x and y axes marked from 5 to 5 and circles of radius 1, 3, and 5 centered at the origin.

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

Ordinary Differential Equations II

Ordinary Differential Equations

Differential equations

Unit 2: Modeling in the Frequency Domain Part 2: The Laplace Transform. The Laplace Transform. The need for Laplace

Ordinary differential equation II

Solutions of the Sample Problems for the First In-Class Exam Math 246, Fall 2017, Professor David Levermore

Lecture 8: Calculus and Differential Equations

Lecture 8: Calculus and Differential Equations

551614:Advanced Mathematics for Mechatronics. Numerical solution for ODEs School of Mechanical Engineering

Mon Jan Improved acceleration models: linear and quadratic drag forces. Announcements: Warm-up Exercise:

Lecture 7 - Separable Equations

MAT 275 Laboratory 4 MATLAB solvers for First-Order IVP

Name of the Student: Unit I (Solution of Equations and Eigenvalue Problems)

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

Logistic Map, Euler & Runge-Kutta Method and Lotka-Volterra Equations

Computers, Lies and the Fishing Season

MATH107 Vectors and Matrices

1 Partial differentiation and the chain rule

Module Two: Differential Calculus(continued) synopsis of results and problems (student copy)

Ordinary Differential Equations

ODE Runge-Kutta methods

MA102: Multivariable Calculus

The problems that follow illustrate the methods covered in class. They are typical of the types of problems that will be on the tests.

Expanding brackets and factorising

Transcription:

Lesson 4: Population, Taylor and Runge-Kutta Methods 4.1 Applied Problem. Consider a single fish population whose size is given by x(t). The change in the size of the fish population over a given time interval is approximately equal to the product of the change in time, t, the difference in the birth rate and death rate, b - d, and the "present" fish population, x(t). This may be written as x(t + t) - x(t) t (b - d) x(t) where t is between t and t + t. The simplest model is for b - d being a constant. A second model is the logistic model where b - d = c(m - x) with c, M constant and M is the maximum population size. A third model may involve harvesting, -h(t), or stocking, +s(t), at a given rate. We want to be able to predict the fish population size as a function of these parameters. In this lesson we will focus on the logistic model, and in the lesson five we will account for harvesting or stocking of the lake. In both these lessons we have assumed there are no predator fish that significantly alter the fish population; we will study this in lesson seven. 4.2 Differential Equation Model. A differential equation can be formed from the above approximation by dividing by t and letting it go to zero. The approximation will get better as t goes to zero

2 because the population size in the interval will vary less as t goes to zero. The above approximation becomes x' = (b - d)x. If (b - d) are constant, then the solution is x(t) = x(0) e (b - d)t. If b - d = c(m - x), then the solution can be found in terms of a more complicated expression with an exponential function, provided c and M are constants! In more sophisticated models this is not the case, and so, we are forced to consider numerical solution to these models. A variation of the logistic model that includes harvesting is x' = c(m - x)x - h(t). 4.3 Taylor Numerical Method. We wish to have a higher order approximation scheme, and so, we apply the fourth order Taylor polynomial approximation to u(t + h) and a = t. Let u have five continuous derivatives so that for some C between t and t + h we have u(t + h) = u(t) + u t (t) h + u tt (t) h 2 /2 + u ttt (t) h 3 /6 + u tttt (t) h 4 /24 + u (5) (C) h 5 /120. Since u is a solution of the differential equation, one can compute the higher order derivatives by using the chain rule, for example, u tt = f t (t,u(t)) 1 + f u (t,u(t)) u t = f t (t,u(t)) 1 + f u (t,u(t)) f(t,u(t)). If f(t,u) is complicated, then these calculations will become costly. However, for simpler cases it is very powerful. Consider the Newton's law of cooling where f(t,u) = c(usur - u). Then the n th derivative of u has the form (-c) n-1 f(u). The above Taylor polynomial with variable h is

3 u(t + h) = u(t) + f(u(t)) h + (-c) 1 f(u(t)) h 2 /2 + (-c) 2 f(u(t)) h 3 /6 This suggests the following algorithm + (-c) 3 f(u(t)) h 4 /24 + (-c) 4 f(c)h 5 /120. u k+1 = u k + f(u k ) h - cf(u k ) h 2 /2 + c 2 f(u k ) h 3 /6 - c 3 f(u k ) h 4 /24. Since the error in Taylor's theorem is of order 5, the discretization error might have an error of order 4. This is the case provided the solution has 5 continuous derivatives. The following Matlab code in the m-file tayerr.m illustrated the order of convergence for the cooling problem with c = 1/26, ysur = 70 and y(0) = 200. The errors are computed at time equal to 10.0, and the steps sizes are reduced by 50% of the previous step size. The table indicates the fourth order Taylor method has an error that is proportional the step size raised to the fourth. Matlab m-file tayerr.m: Euler and Fourth Order Taylor Errors clear; kk = 40; T = 10.0; dt = T/kk; u0 = 200.; c = 1/26; usur = 70.; uk = u0; ut = u0; for k = 1:kk uk = uk + dt*c*(usur -uk); uex = usur + (u0 -usur)*exp(-c*k*dt); utp = ut; ut = ut + dt*c*(usur -utp); ut = ut - (dt^2)/2*c*(c*(usur -utp)); ut = ut + (dt^3)/6*c^2*(c*(usur -utp)); ut = ut - (dt^4)/24*c^3*(c*(usur -utp)); erreul = abs(uk - uex); errtay = abs(ut - uex); end kk erreul errtay

4 Table: Discretization Errors with Euler Order One and Taylor Order Four K (h = 10/K) Euler Error Taylor Error 5 (2.000) 1.3696 105.89 10-7 10 (1.000) 0.6693 6.4089 10-7 20 (0.500) 0.3309 0.3941 10-7 40 (0.250) 0.1645 0.0244 10-7 The n th order Talyor method for approximating the solution of ut = f(t,u(t)) with u(0) given is u k+1 = u k + f(t k, u k ) h + f (1) ( t k, u k ) h 2 /2 +... + f (n-1) ( t k, u k ) h n /n! where f (i) is the i th derivative of the composed function f(t, u(t)). Example. In the above Newton's model of cooling the derivatives of the composed function are f (i) = (-c) i f(u) provided f(u) = c(u sur - u) with u sur equal to a constant. Example. In the calculations below we consider the second order Taylor method, but for more general f(t, u(t)). u k+1 = u k + f(t k, u k ) h + f (1) ( t k, u k ) h 2 /2 = u k + f(t k, u k ) h + (f t (t k, u k ) + f u (t k, u k ) f(t k, u k )) h 2 /2.

5 4.4 Runge-Kutta Numerical Method. The Taylor method for more accurate numerical solutions of ordinary differential equations requires the computation of a number of partial derivatives of f(t,u), and this made its implementation difficult for higher order methods. Here we will show how one can make use a number of function evaluations of just f(t,u) and still obtain higher order methods based on the Taylor method. The second order Taylor algorithm is u k+1 = u k + h [f(t k, u k ) + (f t (t k, u k ) + f u (t k, u k ) f (t k, u k ))h/2]. In order to avoid some of the partial derivatives, we may evaluate f(t,u) at a number of points. The location of these points can be found by using the two variable version of Taylor polynomials for f(x,y). The derivation can be done via the one variable problem where F(t) = f(a+th,b+tk). Use the extended mean value theorem F(0+1) = F(0) + F (1) (0)(1-0) + F (2) (c)(1-0) 2 /2 where c is in [0,1]. The first and second order derivatives of F(t) must be computed via the chain rule: F (1) = f x h + f y k = (D x h + D y k)f F (2) = (D x h + D y k) 2 f = (D x h + D y k)f x h + (D x h + D y k)f y k = f xx hh + 2f xy hk + f yy kk. Therefore, the second order Taylor polynomial with error in two variables is f(a+h,b+k) = f(a,b) + f x (a,b) h + f y (a,b) k + ( f xx (a+ch,b+ck)hh + 2f xy (a+ch,b+ck)hk + f yy (a+ch,b+ck)kk)/2.

6 This multilinear approximation of a function of two variables is the model, which allows us to simplify the Taylor method for the numerical solution of ordinary differential equations. Consider the above second order Taylor method. We want to replace the expression in the square brackets with a suitable evaluation of f at f(t k + α, u k + β). The α and β can be chosen via the second order Taylor polynomial error in two variables with a = t k, h = α, b = u k and k = β f(t k + α, u k + β) = f(t k,u k ) + f t (t k,u k ) α + f u (t k,u k ) β + O(α 2,αβ,β 2 ). In order to match this with the terms in the square bracket in the second order Taylor algorithm, let α = h/2 and β = f(t k,u k ) h/2 so that a variation of this method is u k+1 = u k + h [f(t k + h/2, u k + f(t k,u k ) h/2)]. This is known as the midpoint method or the second order Runge-Kutta method. The fourth order Runge-Kutta method can be formulated using a similar construction. It also can be viewed as Simpson's rule numerical approximation of the equivalent integral equation t+ h ut ( + h) = ut ( ) + fzuz (, ( ))dz. The integral can be approximated by (h/6)(k 1 + 4(k 2 /2 + k 3 /2) + k 4 ) where k 1 = f(t,u(t)), k 2 = f(t+h/2, u(t) + (h/2)k 1 ), k 3 = f(t+h/2, u(t) + (h/2)k 2 ) and t

7 k 4 = f(t+h, u(t) + hk 3 ). The fourth order Runge-Kutta method, where t and u(t) are replaced by t k and u k, is u k+1 = u k + (h/6)(k 1 + 2k 2 + 2k 3 + k 4 ) In order to show this scheme is fourth order convergent, that is, u(t+h) - u k+1 Ah 5, one must use the Taylor expansions, and in this case the solution should have continuous derivatives of order five. 4.5 Matlab Implementation. The following Matlab code for the Runge-Kutta fourth order method uses fixed step sizes. The logistic differential equation is solved where c =.01, M = 100 and x(0) = 10. Notice the solution approaches 100. The steady state solutions are defined by any constant where the right side is zero. This requires cx(m - x) = 0, and so, x = 0 or x = M. The right side of the differential equation is stored is the function file fpop.m, and the Runge-Kutta code is stored in the file rk4.m. This initial population is stored in x(1), and the values for c = 0.01 and M = 100 are in fpop.m. function fpop = fpop(t,x) fpop =.01*(100 - x)*x; %your name, your student number, lesson number clear; x(1) = 10.; T = 10; KK = 50 h = T/KK; t(1)= 0.; for k = 1:KK k1 = h*fpop(t(k),x(k)); k2 = h*fpop(t(k)+.5*h,x(k)+.5*k1); k3 = h*fpop(t(k)+.5*h,x(k)+.5*k2);

8 k4 = h*fpop(t(k)+h,x(k)+.5*k3); x(k+1) = x(k) + (k1 + 2*k2 + 2*k3 +k4)/6; t(k+1) = t(k) + h; end plot(t,x) title('your name, your student number, lesson number') xlabel('time') ylabel('population') 100 your name, your student number, lesson number 90 80 70 population 60 50 40 30 20 10 0 1 2 3 4 5 6 7 8 9 10 time 6.5 Numerical Experiments. 4.6 Numerical Experiments. In the following numerical experiments we keep c = 0.01 and M = 100 fixed, and vary the initial population. We have executed rk4.m with a number of initial conditions, stored the output, and plotted then all on the same graph. Notice if x(0) is positive, then the solution will always converge to the largest steady state solution. Unless x(0) = 0, the smallest steady state solution, the x(t) always goes away from the smallest steady state

9 solution. Here the largest steady state solution is called stable, and the smallest steady state solution is call unstable. Use the hold on command and six different initial populations 1, 30, 60, 90, 110 and 140. These should be stored in the array x of the rk4.m file. This is, execute rk4.m six times with different x(1) (x(1) = 1,, x(1) = 140). Note the abuse of notation: if x = x(t) is a function of t, then x(1) is a function evaluation at t = 1; if x is an array, then x(1) is the first entry in the array. 140 120 populations for different x(0) 100 80 60 40 20 0 0 1 2 3 4 5 6 7 8 9 10 time

10 4.7 Additional Calculations. Next we fix the initial condition x(0) = 10, M = 100*(1+.S), and vary the c. You may want to increase the final time from T = 10 to T = 20 or larger. (a). (b). State the logistic differential equation for c = 0.005 and M = 100*(1+.S). Modify the pop.m and rk4.m files. (c). Execute the rk4.m file for c = 0.005. (d). Use the hold on command and repeat (c) for c = 0.01, 0.015 and 0.02. (e). Examine the curves. What happens to the population as c increases?