MathsFurther Pure 1 › Numerical methods for differential equations

Numerical methods for differential equations

Replace derivatives by differences and a differential equation becomes arithmetic. Step along the solution one h at a time, and Simpson's rule measures the area you pass over.

Builds on Locating roots and iteration and Second order equations.

IN THIS TOPIC

  • Quote and apply the forward and central difference formulae for dy/dx.
  • Step a first or second order equation forward with a stated step length h.
  • Apply Simpson's rule with an even number of strips and judge its accuracy.

COMMON MISCONCEPTION

A differential equation with no closed-form solution cannot be evaluated at a particular point.

Derivatives as differences

Over a short step h, a derivative is nearly a gradient between two sampled points. Two approximations for the first derivative carry most of this topic.

dydxyn+1-ynh or yn+1-yn-12h\frac{dy}{dx} \approx \frac{y_{n+1} - y_{n}}{h} \text{ or } \frac{y_{n+1} - y_{n-1}}{2h}NOT IN THE BOOKLET — LEARN IT

Neither difference formula is in the booklet, so learn both. The first is the forward difference, which uses the step ahead. The second is the central difference, which straddles the point with a step each side and is the more accurate for the same h. Rearrange either for yn+1 and you have a recipe for the next value, so a solution nobody can write down still gets tabulated. Having no formula is not the same as having no values.

Stepping dy/dx = x + y from (0, 1) with h = 0.1: the forward difference undershoots, the central difference lands closer0.10.2forward stepsexactcentral: 1.240forward: 1.220
FIG. 1Stepping y' = x + y from (0, 1) with h = 0.1: the forward difference undershoots the true curve, the central difference lands much closer.

WORKED EXAMPLE

Two steps, two methods

For dy/dx = x + y with y = 1 at x = 0 and h = 0.1, estimate y at x = 0.2.

Forward difference: y₁ = 1 + 0.1(0 + 1) = 1.1, then y₂ = 1.1 + 0.1(0.1 + 1.1) = 1.22.

Central difference from x = 0.1: y₂ = y₀ + 2h(x₁ + y₁) = 1 + 0.2(1.2) = 1.24.

The exact solution 2e0.2 − 1.2 is 1.2428, so the central difference is out by 0.003 where the forward difference is out by 0.023. Nearly ten times better, from the same two evaluations.

Second order equations

The second derivative gets its own approximation, (yn+1 − 2yn + yn-1)/h², which is the central difference applied twice. Substitute it into the equation, rearrange for yn+1, and you have a recurrence that reaches back two steps instead of one.

That reach is why a second order problem always gives you two starting values. With only y₀ the recurrence has nothing to work with, so the first step comes from the initial conditions and the recurrence takes over afterwards. Lay the values out in a table with columns for x, y and whatever the equation needs, and the arithmetic stops going wrong.

Simpson's rule

Where the trapezium rule joins sample points with straight lines, Simpson's rule threads a parabola through each consecutive triple of points, so the strips must come in pairs.

abydxh3(y0+4y1+2y2++4yn-1+yn)\text{∫}_{a}^{b} y \, dx \approx \frac{h}{3}(y_{0} + 4y_{1} + 2y_{2} + … + 4y_{n-1} + y_{n})NOT IN THE BOOKLET — LEARN IT

The booklet prints the trapezium rule and nothing else, so Simpson's rule has to be memorised. Check the 1, 4, 2, 4, …, 4, 1 pattern of weights before evaluating anything. Ends weighted 1, odd-indexed points weighted 4, even-indexed interior points weighted 2. An odd number of strips leaves a parabola with nothing to fit, and the rule simply does not apply.

Simpson's rule with four strips on 1/(1 + x²): weights 1, 4, 2, 4, 1 and an answer good to five decimal places×1×4×2×4×1area ≈ 0.785392π/4 = 0.785398y = 1/(1 + x²)
FIG. 2Simpson's rule on 1/(1 + x²): each pair of strips carries a parabolic cap, and four strips already pin π/4 to five decimal places.

WORKED EXAMPLE

π to five decimal places, from four strips

Use Simpson's rule with four strips to estimate ∫1/(1 + x²) dx from 0 to 1.

h = 0.25 and the five ordinates are 1, 0.941176, 0.8, 0.64, 0.5.

Weighted sum: 1 + 4(0.941176) + 2(0.8) + 4(0.64) + 0.5 = 9.424706.

Multiply by h/3 to get 0.785392. The exact value is π/4 = 0.785398, so four strips already hold five decimal places.

GUIDED PRACTICE

One step of a second order equation

For y'' = x − y with y = 2 at x = 0 and y = 2.1 at x = 0.1, use the central second-difference approximation with h = 0.1 to estimate y at x = 0.2.

Show the working

The approximation gives (y₂ − 2y₁ + y₀)/h² = x₁ − y₁.

So y₂ = 2y₁ − y₀ + h²(x₁ − y₁) = 4.2 − 2 + 0.01(0.1 − 2.1).

y₂ = 2.2 − 0.02 = 2.18. Two starting values were needed, and that is why the question supplied them.

ASSESSMENT FOCUS

  • Quote the difference formula you are using before substituting, since the choice is itself a method mark.
  • Work to more decimal places than the answer demands, then round once at the end.
  • Simpson's rule needs an even number of strips, so an odd number of intervals means you have misread the question.
  • Lay the arithmetic out as a table of x and y values, because examiners follow tables and not paragraphs.
  • Say which approximation is the more accurate if asked to compare, and give the reason in terms of the step either side.

CHECK YOURSELF

Using the forward difference with h = 0.2, take one step of dy/dx = y − x from y = 1 at x = 0.

Show a hint

y₁ = y₀ + h × (dy/dx at the start).

Show the answer

The gradient at the start is 1 − 0 = 1, so y₁ = 1 + 0.2 = 1.2 at x = 0.2. One step, one gradient, no lookahead.

The forward difference steps ahead; the central difference straddles the point and is the more accurate.

Second order equations use (yn+1 − 2yn + yn-1)/h² and need two starting values.

Simpson: h/3 with weights 1, 4, 2, …, 4, 1, and an even number of strips or no rule at all.

WORKBOOK

Printable practice for this topic: original exam-style questions with room to work, and a fully worked answer book. Free to use; please do not redistribute or sell.

7 questions on this topicAnswer them one at a time and mark yourself against the worked answer.Practise this topic

Or read them with their worked answers on the numerical methods for differential equations questions page.

CHECK YOUR PROGRESS

Rate how confident you feel with each objective for this lesson. Ratings are saved in this browser, on this device, unless you sign in.

  • Quote and apply the forward and central difference formulae for dy/dx.
  • Step a first or second order equation forward with a stated step length h.
  • Apply Simpson's rule with an even number of strips and judge its accuracy.

Open the full revision checklist to see every objective in the course in one place.