4 An implicit method

Another approach that can be used to address the initial value problem

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

is to consider integrating the differential equation

d y d t = f ( t , y )

from t = n h to t = n h + h . This leads to

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

that is,

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

and the problem now becomes one of approximating the integral on the right-hand side.

If we approximate the integral using the simple trapezium rule and replace the terms by their approximations we obtain the numerical method

y n + 1 y n = 1 2 h f n + f n + 1

The procedure for time stepping with this method is much the same as that used for Euler’s method, but with one difference. Let us imagine applying the method, we are given y 0 as the initial condition and now aim to find y 1 from

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

And here is the problem: the unknown y 1 appears on both sides of the equation. We cannot, in general, find an explicit expression for y 1 and for this reason the numerical method is called an implicit method.

In practice the particular form of f may allow us to find y 1 fairly simply, but in general we have to approximate y 1 for example by using the bisection method, or Newton-Raphson. (Another approach that can be used involves what is called a predictor-corrector method, in other words, a “guess and improve" method, and we will discuss this again later in this Workbook.)

And then, of course, we encounter the problem again in the second time step, when calculating y 2 . And again for y 3 and so on. There is, in general, a genuine cost in implementing implicit methods, but they are popular because they have desirable properties, as we will see later in this Workbook.

Key Point 6

The trapezium 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 + 1 2 h f ( 0 , y 0 ) + f ( h , y 1 ) y ( 2 h ) y 2 = y 1 + 1 2 h f ( h , y 1 ) + f ( 2 h , y 2 ) y ( 3 h ) y 3 = y 2 + 1 2 h f ( 2 h , y 2 ) + f ( 3 h , y 3 ) y ( 4 h ) y 4 = y 3 + 1 2 h f ( 3 h , y 3 ) + f ( 4 h , y 4 )

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

In Example 2 the implicit nature of the method is not a problem because y does not appear on the right-hand side of the differential equation. In other words, f = f ( t ) .

Example 2

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

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

Carry out two time steps of the trapezium method with a step size of h = 0.2 so as to obtain approximations to y ( 0.2 ) and y ( 0.4 ) .

Solution

For the first time step we require f 0 = f ( 0 ) = 1 and f 1 = f ( 0.2 ) = 0.833333 and therefore

y 1 = y 0 + 1 2 h ( f 0 + f 1 ) = 1 + 0.1 × 1.833333 = 1.183333

For the second time step we also require f 2 = f ( 2 h ) = f ( 0.4 ) = 0.714286 and therefore

y 2 = y 1 + 1 2 h ( f 1 + f 2 ) = 1.183333 + 0.1 × 1.547619 = 1.338095

We conclude that

y ( 0.1 ) 1.183333 y ( 0.2 ) 1.338095

Example 3 has f dependent on y , so the implicit nature of the trapezium method could be a problem. However in this case the way in which f depends on y is simple enough for us to be able to rearrange for an explicit expression for y n + 1 .

Example 3

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

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

Carry out two time steps of the trapezium method with a step size of h = 0.1 so as to obtain approximations to y ( 0.1 ) and y ( 0.2 ) .

Solution

The trapezium method is y n + 1 = y n + h 2 ( f n + f n + 1 ) and in this case y n + 1 will appear on both sides because f depends on y . We have

y n + 1 = y n + h 2 1 t n 2 + 1 2 y n + 1 t n + 1 2 + 1 2 y n + 1 = y n + h 2 g ( t n ) 2 y n + g ( t n + 1 ) 2 y n + 1

where g ( t ) 1 ( t 2 + 1 ) which is the part of f that depends on t . On rearranging to get all y n + 1 terms on the left, we get

( 1 + h ) y n + 1 = y n + 1 2 h g ( t n ) 2 y n + g ( t n + 1 )

In this case h = 0.1 .

For the first time step we require g ( 0 ) = 1 and g ( 0.1 ) = 0.990099 and therefore

1.1 y 1 = 2 + 0.05 1 2 × 2 + 0.990099

Hence y 1 = 1.726823 , to six decimal places.

For the second time step we also require g ( 2 h ) = g ( 0.2 ) = 0.961538 and therefore

1.1 y 2 = 1.726823 + 0.05 0.990099 2 × 1.726823 + 0.961538

Hence y 2 = 1.501566 . We conclude that y ( 0.1 ) 1.726823 and y ( 0.2 ) 1.501566 to 6 d.p.

Task!

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

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

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

The trapezium method is y n + 1 = y n + h 2 ( f n + f n + 1 ) and in this case y n + 1 will appear on both sides because f depends on y . However, we can rearrange for y n + 1 to give

1.0625 y n + 1 = y n + 1 2 h g ( t n ) y n + g ( t n + 1 )

where g ( t ) = t is the part of f that depends on t .

For the first time step we require g ( 0 ) = 0 and g ( 0.125 ) = 0.125 and therefore

1.0625 y 1 = 2 + 0.0625 0 2 + 0.125

Hence y 1 = 1.772059 to 6 d.p.

For the second time step we also require g ( 2 h ) = g ( 0.25 ) = 0.25 and therefore

1.0625 y 2 = 1.772059 + 0.0625 0.125 1.772059 + 0.25

Hence y 2 = 1.58564 , to 6 d.p.

Example 4

The current i in a simple circuit involving a resistor of resistance R and an inductance loop of inductance L with applied voltage E satisfies the differential equation

L d i d t + R i = E

Consider the case where L = 1 , R = 100 and E = 1000 . Given that i ( 0 ) = 0 use a value of h = 0.001 in implementation of the trapezium method to approximate the current i at times t = 0.001 and t = 0.002 .

Solution

The current i satisfies

d i d t = 1000 100 i

and the trapezium approximation to this is

i n + 1 i n = h 2 ( 2000 100 i n + 1 100 i n )

Rearranging this for i n + 1 gives

i n + 1 = 0.904762 i n + 0.952381

It follows that

i ( 0.001 ) 0.904762 × 0 + 0.952381 = 0.952381 i ( 0.002 ) 0.904762 × 0.952381 + 0.952381 = 1.814059

where these approximations are given to 6 decimal places.

4.1 Accuracy of the trapezium method

Let us now consider an example with a known solution and consider just how accurate the trapezium method is. Suppose that we look at the same test problem we considered when looking at Euler’s method

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 the trapezium 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 Trapezium approximation Difference between exact to   y ( 1 ) = 2.718282 value and trapezium approximation ̲ ̲ ̲ 0.2 y 5 = 2.727413 0.009131 0.1 y 10 = 2.720551 0.002270 0.05 y 20 = 2.718848 0.000567 0.025 y 40 = 2.718423 0.000142 0.0125 y 80 = 2.718317 0.000035

Notice that each time h is reduced by a factor of 1 2 , the error reduces by a factor of (approximately) 1 4 . This observation verifies something we will see in Section 32.2, that is that the error in the trapezium approximation is (approximately) proportional to h 2 . This sort of behaviour is called second-order .

Key Point 7

The trapezium approximation is second order. In other words, the error it incurs is approximately proportional to h 2 .

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

    d y d t = t + y y ( 0 ) = 3

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

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

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

    Carry out two time steps of the trapezium method with a step size of h = 0.1 so as to obtain approximations to y ( 0.1 ) and y ( 0.2 ) .

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

    d y d t = t 2 y y ( 0 ) = 1.5

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

  4. The current i in a simple circuit involving a resistor of resistance R , an inductance loop of inductance L with applied voltage E satisfies the differential equation

    L d i d t + R i = E

    Consider the case where L = 1.5 , R = 120 and E = 600 . Given that i ( 0 ) = 0 use a value of h = 0.0025 in implementation of the trapezium method to approximate the current i at times t = 0.0025 and t = 0.005 .

  1. For the first time step we require f 0 = f ( 0 , y 0 ) = f ( 0 , 3 ) = 3 and therefore y 1 = y 0 + h f 0 = 3 + 0.05 × 3 = 3.15



    For the second time step we require f 1 = f ( h , y 1 ) = f ( 0.05 , 3.15 ) = 3.2 and therefore

    y 2 = y 1 + h f 1 = 3.15 + 0.05 × 3.2 = 3.31



    We conclude that

    y ( 0.05 ) 3.15 y ( 0.1 ) 3.31
  2. For the first time step we require f 0 = f ( 0 ) = 1 and f 1 = f ( 0.1 ) = 0.990099 and therefore y 1 = y 0 + 1 2 h ( f 0 + f 1 ) = 2 + 0.05 × 1.990099 = 2.099505



    For the second time step we also require f 2 = f ( 2 h ) = f ( 0.2 ) = 0.961538 and therefore

    y 2 = y 1 + 1 2 h ( f 1 + f 2 ) = 2.099505 + 0.05 × 1.951637 = 2.197087



    We conclude that

    y ( 0.05 ) 2.099505 y ( 0.1 ) 2.197087

    to six decimal places.

  3. The trapezium method is y n + 1 = y n + h 2 ( f n + f n + 1 ) and in this case y n + 1 will appear on both sides because f depends on y . However, we can rearrange for y n + 1 to give

    1.0625 y n + 1 = y n + 1 2 h g ( t n ) y n + g ( t n + 1 )

    where g ( t ) = t 2 is the part of f that depends on t .

    For the first time step we require g ( 0 ) = 0 and g ( 0.125 ) = 0.015625 and therefore

    1.0625 y 1 = 1.5 + 0.0625 0 1.5 + 0.015625

    Hence y 1 = 1.324449 .

    For the second time step we also require g ( 2 h ) = g ( 0.25 ) = 0.0625 and therefore

    1.0625 y 2 = 1.324449 + 0.0625 0.015625 1.324449 + 0.0625

    Hence y 2 = 1.173227 .

  4. Dividing through by L = 1.5 we find that the current i satisfies

    d i d t = 400 80 i

    and the trapezium approximation to this is

    i n + 1 i n = h 2 ( 800 80 i n + 1 80 i n )

    Rearranging this for i n + 1 gives

    i n + 1 = 0.818182 i n + 0.909091

    It follows that

    i ( 0.0025 ) 0.818182 × 0 + 0.909091 = 0.909091 i ( 0.005 ) 0.818182 × 0.909091 + 0.909091 = 1.652893