Numerical solution of differential equations

Numerical solution of differential equations

Spec 6.1 · Edexcel A-Level Further Maths: Revision notes

Studying this course? Keep your progress in one place.

Key facts

  • A numerical method starts at (x0,y0)(x_0,y_0) and moves in equal steps of step length hh, so xn=x0+nhx_n=x_0+nh.
  • Forward difference (Euler): yn+1=yn+h f(xn,yn)y_{n+1}=y_n+h\,f(x_n,y_n).
  • Central difference: yn+1=yn−1+2h f(xn,yn)y_{n+1}=y_{n-1}+2h\,f(x_n,y_n), which needs two starting values.
  • Second-order equations use yn+1=2yn−yn−1+h2f(xn,yn)y_{n+1}=2y_n-y_{n-1}+h^2f(x_n,y_n) when there is no first derivative term.
  • A smaller hh or a central difference gives a better estimate; measure it with percentage error.

Step length and approximations

Each derivative is replaced by a difference approximation using values of yy at equally spaced xx-values.

Many differential equations cannot be solved exactly. A numerical method starts from a known point and moves in equal steps of step length hh. The notation yny_n means the approximation to y(xn)y(x_n).

Each derivative is replaced by a difference approximation using nearby values yn−1y_{n-1}, yny_n, yn+1y_{n+1}. Smaller steps usually give more accurate results but need more calculation.

  • Forward(dydx)n=yn+1−ynh\left(\dfrac{dy}{dx}\right)_n=\dfrac{y_{n+1}-y_n}{h}
  • Central(dydx)n=yn+1−yn−12h\left(\dfrac{dy}{dx}\right)_n=\dfrac{y_{n+1}-y_{n-1}}{2h}
  • Second derivative(d2ydx2)n=yn+1−2yn+yn−1h2\left(\dfrac{d^2y}{dx^2}\right)_n=\dfrac{y_{n+1}-2y_n+y_{n-1}}{h^2}
  1. 1

    Start

    Use the known point (x₀, y₀)

  2. 2

    Choose h

    Fix the step length

  3. 3

    Apply the formula

    Compute the next y from earlier values

  4. 4

    Update

    Move on to the next x and repeat

The pattern every numerical method follows.

If x0=1x_0=1 and h=0.5h=0.5, what is x3x_3?

Forward difference (Euler)

Euler's method steps forward using the gradient at the start of each interval.

Substituting the forward difference yn+1−ynh\frac{y_{n+1}-y_n}{h} into dydx=f(x,y)\frac{dy}{dx}=f(x,y) and rearranging gives yn+1=yn+h f(xn,yn)y_{n+1}=y_n+h\,f(x_n,y_n). This is Euler's method.

Each step uses the gradient at the start of the interval, so errors build up. Set out a table of nn, xnx_n, yny_n and f(xn,yn)f(x_n,y_n) so no step is skipped.

0.10.20.30.40.50.60.70.811.21.41.61.822.2xy11.2431.5842.044exact: y = 2eˣ − x − 1
Exact values at each step. Euler gives 1.2, 1.48 and 1.856, all lower.

Worked example

dydx=x+y\frac{dy}{dx}=x+y, y(0)=1y(0)=1, h=0.2h=0.2. Find y3y_3 and the percentage error, given the exact solution y=2ex−x−1y=2e^x-x-1.

For dydx=2x\frac{dy}{dx}=2x, y(0)=1y(0)=1, h=0.5h=0.5, what is y1y_1?

Central difference method

The central difference is centred on xnx_n, so it is more accurate, but it needs two starting values.

The central difference (dydx)n=yn+1−yn−12h\left(\frac{dy}{dx}\right)_n=\frac{y_{n+1}-y_{n-1}}{2h} is more accurate than the forward difference because it is centred on xnx_n.

Substituting into dydx=f(x,y)\frac{dy}{dx}=f(x,y) gives yn+1=yn−1+2h f(xn,yn)y_{n+1}=y_{n-1}+2h\,f(x_n,y_n).

Every step looks back two values, so you need y0y_0 and y1y_1. Find y1y_1 by the forward difference method.

0.20.40.60.811.21.41.61.82123456xyyₙ₋₁yₙyₙ₊₁y = eˣcentral difference chordtangent at x = 1
Illustrative y = eˣ. The central chord from x = 0.5 to 1.5 is almost parallel to the tangent at x = 1, so it estimates the gradient well.
  • Central difference stepyn+1=yn−1+2h f(xn,yn)y_{n+1}=y_{n-1}+2h\,f(x_n,y_n)

Worked example

dydx=x−y\frac{dy}{dx}=x-y, y(0)=1y(0)=1, h=0.1h=0.1. Find y3y_3.

Why must y1y_1 be found separately in the central difference method?

Second-order equations

Replace d2ydx2\frac{d^2y}{dx^2} by its difference approximation, and any dydx\frac{dy}{dx} by the central difference.

For a second-order equation d2ydx2=f(x,y)\frac{d^2y}{dx^2}=f(x,y), replace the second derivative by yn+1−2yn+yn−1h2\frac{y_{n+1}-2y_n+y_{n-1}}{h^2}. This gives yn+1=2yn−yn−1+h2f(xn,yn)y_{n+1}=2y_n-y_{n-1}+h^2f(x_n,y_n).

If the equation also contains dydx\frac{dy}{dx}, replace it by the central difference too. Multiply through by h2h^2 to clear fractions, then collect the yn+1y_{n+1}, yny_n and yn−1y_{n-1} terms.

0.20.40.60.811.21.41.61.820.511.522.533.54xyyₙ₋₁ = 0.25yₙ = 1yₙ₊₁ = 2.25y = x²
Illustrative values: y = x² with h = 0.5. The second difference (2.25 − 2×1 + 0.25) ÷ 0.5² = 2 equals y″ = 2.
  • Second-order stepyn+1=2yn−yn−1+h2f(xn,yn)y_{n+1}=2y_n-y_{n-1}+h^2f(x_n,y_n)

Worked example

Find a recurrence for d2ydx2=−y\frac{d^2y}{dx^2}=-y with h=0.1h=0.1.

For d2ydx2=−y\frac{d^2y}{dx^2}=-y with h=0.2h=0.2, what is the recurrence?

Starting a second-order method

Use the central difference at n=0n=0 with the initial conditions to find y1y_1 and the extra value y−1y_{-1}.

The formula needs y0y_0 and y1y_1, but the initial conditions give y0y_0 and dydx\frac{dy}{dx} at x0x_0.

Use the central difference at n=0n=0: y1−y−12h=(dydx)0\frac{y_1-y_{-1}}{2h}=\left(\frac{dy}{dx}\right)_0. This brings in y−1y_{-1}. Write the recurrence with n=0n=0 and solve the two equations for y1y_1 and y−1y_{-1}.

A simpler start is y1=y0+h(dydx)0y_1=y_0+h\left(\frac{dy}{dx}\right)_0.

  1. 1

    Central difference at n = 0

    Links y₁ and y₋₁ to the gradient

  2. 2

    Recurrence at n = 0

    A second equation in y₁ and y₋₁

  3. 3

    Solve

    Find y₁, then carry on with the recurrence

Finding the first value.

Worked example

y0=0y_0=0, dydx=1\frac{dy}{dx}=1 at x0x_0, h=0.1h=0.1, and yn+1=1.99yn−yn−1y_{n+1}=1.99y_n-y_{n-1}. Find y1y_1 and y2y_2.

With y0=0y_0=0 and dydx=1\frac{dy}{dx}=1 at x0x_0, why is y−1=0y_{-1}=0 wrong?

Judging accuracy

Compare with the exact value using percentage error, and improve it with a smaller step or a central difference.

Compare an estimate with an exact value using the percentage error: exact−estimateexact×100\frac{\text{exact}-\text{estimate}}{\text{exact}}\times100.

Errors grow as more steps are taken. To improve an estimate, use a smaller step length hh, so each difference approximation is closer to the true derivative, or use the central difference rather than the forward difference. Always say why.

0.20.40.60.811.21.41.61.822.212345678xy11.52.253.3755.0625Exact y = eˣEuler, h = 0.5
Illustrative: dy/dx = y, y(0) = 1, h = 0.5. Steps fall below y = eˣ; at x = 2 the estimate 5.0625 has about 31.5% error.
  • Percentage errorexact−estimateexact×100\dfrac{\text{exact}-\text{estimate}}{\text{exact}}\times100

Worked example

d2ydx2+2dydx+y=0\frac{d^2y}{dx^2}+2\frac{dy}{dx}+y=0, y(0)=1y(0)=1, y′(0)=0y'(0)=0, h=0.5h=0.5. Estimate y(1)y(1) and find the percentage error, given the exact value 0.73580.7358.

Which change would improve a numerical estimate?

Try an exam question

The differential equation dydx=x+y\frac{dy}{dx}=x+y has y=1y=1 when x=0x=0. Use the forward difference method with step length h=0.2h=0.2 to estimate yy when x=0.4x=0.4. State one way to improve the estimate.

[4 marks]

That's the notes covered.

Carry on to the next subtopic.

Try a question

Find the approximation y1y_1 to y(0.2)y(0.2).

1 mark, marked against the mark scheme

Revision notes