3 An explicit method

Guided by the fact that we only seek approximations to y ( t ) at t -values that are a distance h apart we could use a forward difference formula to approximate the derivative in the differential equation. This leads to

y ( t + h ) y ( t ) h f ( t , y )

and we use this as the inspiration for the numerical method

y n + 1 y n = h f ( n h , y n )

For clarity we denote f ( n h , y n ) as f n . The procedure for implementing the method (called Euler’s method - pronounced “Oil-er’s method" - is summarised in the following Key Point.

Key Point 4

Euler’s method for approximating the solution of

d y d t = f ( t , y ) , y ( 0 ) = y 0

is as follows. We choose a time step h , then

y ( h ) y 1 = y 0 + h f ( 0 , y 0 ) y ( 2 h ) y 2 = y 1 + h f ( h , y 1 ) y ( 3 h ) y 3 = y 2 + h f ( 2 h , y 2 ) y ( 4 h ) y 4 = y 3 + h f ( 3 h , y 3 )

In general, y ( n h ) is approximated by y n = y n 1 + h f n 1  .

This is called an explicit method, but the reason why will be clearer in a page or two when we encounter an implicit method. First we look at an Example.

Example 1

Suppose that y = y ( t ) is the solution to the initial value problem

d y d t = 1 ( t + y ) 2 , y ( 0 ) = 0.9

Carry out two time steps of Euler’s method with a step size of h = 0.125 so as to obtain approximations to y ( 0.125 ) and y ( 0.25 ) .

Solution

In general, Euler’s method may be written  y n + 1 = y n + h f n  and here f ( t , y ) = 1 ( t + y ) 2 .

For the first time step we require f 0 = f ( 0 , y 0 ) = f ( 0 , 0.9 ) = 1.23457 and therefore

y 1 = y 0 + h f 0 = 0.9 + 0.125 × ( 1.23457 ) = 0.745679

For the second time step we require f 1 = f ( h , y 1 ) = f ( 0.125 , 0.745679 ) = 1.31912 and therefore

y 2 = y 1 + h f 1 = 0.745679 + 0.125 × ( 1.31912 ) = 0.580789

We conclude that

y ( 0.125 ) 0.745679 y ( 0.25 ) 0.580789

where these approximations are given to 6 decimal places.

The simple, repetitive nature of this process makes it ideal for computational implementation, but this next exercise can be carried out by hand.

Task!

Suppose that y = y ( t ) is the solution to the initial value problem

d y d t = y 2 , y ( 0 ) = 0.5

Carry out two time steps of Euler’s method with a step size of h = 0.01 so as to obtain approximations to y ( 0.01 ) and y ( 0.02 ) .

For the first time step we require f 0 = f ( 0 , y 0 ) = f ( 0 , 0.5 ) = ( 0.5 ) 2 = 0.25 and therefore

y 1 = y 0 + h f 0 = 0.5 + 0.01 × ( 0.25 ) = 0.4975

For the second time step we require f 1 = f ( h , y 1 ) = f ( 0.01 , 0.4975 ) = ( 0.4975 ) 2 = 0.24751 and therefore

y 2 = y 1 + h f 1 = 0.4975 + 0.01 × ( 0.24751 ) = 0.495025

We conclude that

y ( 0.01 ) 0.497500 y ( 0.02 ) 0.495025 to six decimal places.

The following Task involves the so-called logistic approximation that may be used in modelling population dynamics.

Task!

Given the logistic population dynamic model

d y d t = 2 y ( 1 y ) , y ( 0 ) = 1.2

carry out two time steps of Euler’s method with a step size of h = 0.125 to obtain approximations to y ( 0.125 ) and y ( 0.25 ) .

For the first time step we require f 0 = f ( 0 , y 0 ) = f ( 0 , 1.2 ) = 2 × 1.2 ( 1 1.2 ) = 0.48 and therefore

y 1 = y 0 + h f 0 = 1.2 + 0.125 × ( 0.48 ) = 1.14



For the second time step we require f 1 = f ( h , y 1 ) = f ( 0.125 , 1.14 ) = 0.3192 and therefore

y 2 = y 1 + h f 1 = 1.14 + 0.125 × ( 0.3192 ) = 1.1001



We conclude that

y ( 0.125 ) 1.14 y ( 0.25 ) 1.1001
Task!

The following initial value problem models the population of the United Kingdom, suppose that

d P d t = 2.5 × 1 0 3 P , P ( 0 ) = 58.043

where P is the population in millions, t is measured in years and t = 0 corresponds to the year 1996.

  1. Show that Euler’s method applied to this initial value problem leads to

    P n + 1 = ( 1 + 2.5 × 1 0 3 h ) n × 58.043

    where P n is the approximation to P ( n h ) .

  2. Use a time step of h equal to 6 months to approximate the predicted population for the year 2050.

In general P n + 1 = P n + h f n where, in this case, f ( h , P n ) = 2.5 × 1 0 3 P n hence

P n + 1 = P n + 2.5 × 1 0 3 h P n and so P n + 1 = ( 1 + 2.5 × 1 0 3 h ) P n

But P n will have come from the previous time step ( P n = ( 1 + 2.5 × 1 0 3 h ) P n 1 ) and P n 1 will have come from the time step before that ( P n 1 = ( 1 + 2.5 × 1 0 3 h ) P n 2 ). Repeatedly applying this observation leads to

P n + 1 = ( 1 + 2.5 × 1 0 3 h ) n × 58.043

since P 0 = P ( 0 ) = 58.043 .

For a time step of 6 months we take h = 1 2 (in years) and we require 108 time steps to cover the 54 years from 1996 to 2050. Hence

UK population (in millions) in 2050 P ( 54 ) P 108 = ( 1 + 2.5 × 1 0 3 × 1 2 ) 108 × 58.043 = 66.427

where this approximation is given to 3 decimal places.

3.1 Accuracy of Euler’s method

There are two issues to consider when concerning ourselves with the accuracy of our results.

  1. How accurately does the differential equation model the physical process?
  2. How accurately does the numerical method approximate the solution of the differential equation?

Our aim here is to address only the second of these two questions.

Let us now consider an example with a known solution and consider just how accurate Euler’s method is. Suppose that

d y d t = y y ( 0 ) = 1.

We know that the solution to this problem is y ( t ) = e t , and we now compare exact values with the values given by Euler’s method. For the sake of argument, let us consider approximations to y ( t ) at t = 1 . The exact value is y ( 1 ) = 2.718282 to 6 decimal places. The following table shows results to 6 decimal places obtained on a spreadsheet program for a selection of choices of h .

h Euler approximation Difference between exact to   y ( 1 ) = 2.718282 value and Euler approximation ̲ ̲ ̲ 0.2 y 5 = 2.488320 0.229962 0.1 y 10 = 2.593742 0.124539 0.05 y 20 = 2.653298 0.064984 0.025 y 40 = 2.685064 0.033218 0.0125 y 80 = 2.701485 0.016797

Notice that the smaller h is, the more time steps we have to take to get to t = 1 . In the table above each successive implementation of Euler’s method halves h . Interestingly, the error halves (approximately) as h halves. This observation verifies something we will see in Section 32.2, that is that the error in Euler’s method is (approximately) proportional to the step size h . This sort of behaviour is called first-order , and the reason for this name will become clear later.

Key Point 5

Euler’s method is first order. In other words, the error it incurs is approximately proportional to h .