Numerical integration and Euler methods

Approximate integrals with the trapezium rule and Simpson's rule, and differential equations with Euler and improved Euler steps.

More
Reading settings

Read offline with Premium

Save lessons and figures on this device with Premium.

Connect at least once every 30 days to confirm Premium. Topic checks, coaching and sync need a connection.

On this page

Reading settings

Appearance and reading tools for your lessons.

Live preview

Take a moment to read at your own pace. Choose the font and spacing that feel comfortable for you.

Pause after each idea, then explain it in your own words before moving on.

Narrower lines take effect when the screen has room.

Colour theme
Reading font
Line spacing
Reading width
Section links
Worked examples

Open example banners when a lesson starts. Hints and solutions stay closed until you open them.

Checking Premium access…

Explore Premium
Revision Mode

Hide questions, activities and worked examples to read the notes. Turn off to show the full lesson.

Checking Premium access…

Explore Premium

Enlarged diagram

Most integrals you meet in practice have no antiderivative you can write down: ∫₀¹ e^(-x²) dx is the standard example. Many differential equations have no closed-form solution either. A computer handles both in the same way: it works only with function values at equally spaced points and combines them with fixed weights. This lesson builds the trapezium rule and Simpson’s rule from the strip picture, explains when each over- or underestimates, and then steps through a differential equation with Euler’s method and the improved Euler method. In every case the skill being examined is the same: set up the values correctly, apply the right weights, and judge how accurate the answer is.

Replace each strip with a trapezium

Split [a,b] into n strips of equal width

h = (b-a)/n,

and write yᵣ = f(a + rh) for the ordinates, r = 0,1,…,n. On each strip, replace the curve by the straight line joining its two ordinates. Strip r then has area (h/2)(yᵣ₋₁ + yᵣ), and adding all n strips counts each interior ordinate twice:

∫ₐ^b f(x) dx ≈ h/2[y₀ + yₙ + 2(y₁ + y₂ + … + yₙ₋₁)].

The weights are 1,2,2,…,2,1. There are n + 1 ordinates for n strips; counting strips when you mean ordinates, or the reverse, is the most common setting-up error.

Four trapezia under a curve that bends downwards

The solid curve y = sin x rises from 0 at x = 0 to 1 at x = π/2 and falls back to 0 at x = π. The dashed polyline joins the points (0, 0), (π/4, 0.707107), (π/2, 1), (3π/4, 0.707107) and (π, 0), and the area below it is shaded. The polyline lies below the curve between the ordinates, leaving thin gaps; the shaded area is (π/4)(1 + √2) ≈ 1.896, compared with the exact area 2.

The solid curve y = sin x rises from 0 at x = 0 to 1 at x = π/2 and falls back to 0 at x = π. The dashed polyline joins the points (0, 0), (π/4, 0.707107), (π/2, 1), (3π/4, 0.707107) and (π, 0), and the area below it is shaded. The polyline lies below the curve between the ordinates, leaving thin gaps; the shaded area is (π/4)(1 + √2) ≈ 1.896, compared with the exact area 2.The solid curve y = sin x rises from 0 at x = 0 to 1 at x = π/2 and falls back to 0 at x = π. The dashed polyline joins the points (0, 0), (π/4, 0.707107), (π/2, 1), (3π/4, 0.707107) and (π, 0), and the area below it is shaded. The polyline lies below the curve between the ordinates, leaving thin gaps; the shaded area is (π/4)(1 + √2) ≈ 1.896, compared with the exact area 2.
y = sin x on 0 ≤ x ≤ π with four strips of width π/4. The shaded region is the trapezium-rule area: straight tops join the five ordinates. Every top lies on or below the curve, so the rule underestimates the exact area 2.
Open full-size graphOpen full-size graph
What to noticeThe curve is drawn from sampled values joined by short straight segments. The shaded area is exactly the trapezium-rule area because its top is the straight-line polyline through the five ordinates.
Figure data

This table is included in print while it is open.

Figure data: Four trapezia under a curve that bends downwards
Seriesxy
y = sin x0.0000000.000000
y = sin x0.0490870.049067
y = sin x0.0981750.098017
y = sin x0.1472620.146730
y = sin x0.1963500.195091
y = sin x0.2454370.242980
y = sin x0.2945240.290284
y = sin x0.3436120.336890
y = sin x0.3926990.382683
y = sin x0.4417860.427555
y = sin x0.4908740.471397
y = sin x0.5399610.514103
y = sin x0.5890490.555571
y = sin x0.6381360.595699
y = sin x0.6872230.634393
y = sin x0.7363110.671559
y = sin x0.7853980.707107
y = sin x0.8344860.740951
y = sin x0.8835730.773010
y = sin x0.9326600.803207
y = sin x0.9817480.831470
y = sin x1.0308350.857729
y = sin x1.0799220.881921
y = sin x1.1290100.903989
y = sin x1.1780970.923879
y = sin x1.2271850.941544
y = sin x1.2762720.956940
y = sin x1.3253590.970031
y = sin x1.3744470.980785
y = sin x1.4235340.989176
y = sin x1.4726220.995185
y = sin x1.5217090.998795
y = sin x1.5707961.000000
y = sin x1.6198840.998795
y = sin x1.6689710.995185
y = sin x1.7180580.989177
y = sin x1.7671460.980785
y = sin x1.8162330.970031
y = sin x1.8653210.956940
y = sin x1.9144080.941544
y = sin x1.9634950.923880
y = sin x2.0125830.903989
y = sin x2.0616700.881921
y = sin x2.1107580.857728
y = sin x2.1598450.831470
y = sin x2.2089320.803208
y = sin x2.2580200.773010
y = sin x2.3071070.740951
y = sin x2.3561940.707107
y = sin x2.4052820.671559
y = sin x2.4543690.634393
y = sin x2.5034570.595699
y = sin x2.5525440.555570
y = sin x2.6016310.514103
y = sin x2.6507190.471397
y = sin x2.6998060.427555
y = sin x2.7488940.382683
y = sin x2.7979810.336890
y = sin x2.8470680.290285
y = sin x2.8961560.242980
y = sin x2.9452430.195090
y = sin x2.9943300.146731
y = sin x3.0434180.098017
y = sin x3.0925050.049068
y = sin x3.1415930.000000
Trapezium tops0.0000000.000000
Trapezium tops0.7853980.707107
Trapezium tops1.5707961.000000
Trapezium tops2.3561940.707107
Trapezium tops3.1415930.000000

The figure shows why the error has a predictable sign. Where a curve bends downwards (it is concave, f''(x) < 0), each chord lies below the curve, so the trapezium rule underestimates. Where it bends upwards (f''(x) > 0), each chord lies above the curve and the rule overestimates. For sin x on [0,π] with four strips,

T₄ = (π/8)[0 + 2((square root of 2)/2 + 1 + (square root of 2)/2) + 0]; = (π/4)(1 + square root of 2); ≈ 1.896,

which is below the exact value 2. If f'' changes sign inside the interval, the two kinds of error partly cancel and you cannot predict the sign from a sketch alone.

Check your understanding 1

Four strips under a logarithm

Use the trapezium rule with 4 strips to estimate ∫₁² ln x dx, giving your answer to 4 decimal places. Then decide whether it is an overestimate or an underestimate without using the exact value.

The trapezium estimate is

Show answerHide answer

With h = 0.25 the ordinates are 0, 0.223144, 0.405465, 0.559616, 0.693147. Then

T₄ = 0.25/2[0 + 2(0.223144 + 0.405465 + 0.559616) + 0.693147]; = 0.125 × 3.069597; = 0.383700 (to 6 d.p.),

so the estimate is 0.3837 to 4 decimal places. Since d²/(dx²) ln x = -1/x² < 0, the curve bends downwards throughout and every chord lies below it: T₄ is an underestimate. The exact value 2 ln 2-1 ≈ 0.386294 confirms this.

Simpson’s rule fits parabolas

Simpson’s rule takes the strips in pairs. Through the three ordinates of a pair it fits a parabola, and the area under a parabola through (-h,y₀), (0,y₁) and (h,y₂) is exactly

(h/3)(y₀ + 4y₁ + y₂).

(Write the parabola as px² + qx + c: then y₁ = c and y₀ + y₂ = 2ph² + 2c, while its integral from -h to h is (2/3)ph³ + 2ch. Eliminating p and c gives the expression above.) Adding the pairs gives the rule, which needs an even number of strips:

∫ₐ^b f(x) dx ≈ h/3[y₀ + yₙ; + 4(y₁ + y₃ + … + yₙ₋₁); + 2(y₂ + y₄ + … + yₙ₋₂)].

Along the row of ordinates the weights run 1,4,2,4,2,…,4,1: odd-numbered ordinates are pair midpoints (weight 4), even-numbered interior ordinates are shared by two pairs (weight 2). Because a parabola can follow the bending of a curve, Simpson’s rule is usually far more accurate than the trapezium rule for the same ordinates; it is exact for every cubic.

Worked example 1

Two estimates of π/4

Estimate ∫₀¹1/(1 + x²) dx with 4 strips by the trapezium rule and by Simpson’s rule. Compare each estimate with the exact value π/4.

Show full solutionHide solution
  1. Tabulate the ordinates once

    Method

    Use h = (1-0)/4 = 0.25 and evaluate f(x) = 1/(1 + x²) at the five points.

    Reason

    Both rules use the same five ordinates; only the weights differ. Keep six decimal places so that rounding does not hide the difference between the rules.

    Working

    Answer

    r01234
    xᵣ00.250.50.751
    yᵣ10.9411760.80.640.5
  2. Apply the trapezium weights 1, 2, 2, 2, 1

    Reason

    The three interior ordinates each belong to two strips, so they are doubled.

    Working

    Answer

    T₄ = 0.25/2[1 + 2(0.941176 + 0.8 + 0.64) + 0.5]; = 0.125 × 6.262353; ≈ 0.782794.
  3. Apply the Simpson weights 1, 4, 2, 4, 1

    Method

    Weight y₁ and y₃ by 4 and y₂ by 2.

    Reason

    y₁ and y₃ are the midpoints of the two pairs of strips; y₂ is the shared end of both pairs.

    Working

    Answer

    S₄ = 0.25/3[1 + 4(0.941176 + 0.64) + 2(0.8) + 0.5]; = 9.424706/12; ≈ 0.785392.
  4. Compare with the exact value

    Working

    Answer

    π/4 ≈ 0.785398, so the trapezium error is about 0.0026 and the Simpson error about 0.000006: roughly four hundred times smaller from the same five function values.

With the aid of a computer: refine until the digits settle

In 9649 these rules are used “with the aid of a computer”: a spreadsheet or graphing calculator evaluates the ordinates and sums. Your job is to choose n, report the values and judge the accuracy. The usual method is to double n until the required digits stop changing. For I = ∫₀¹e^(-x²) dx ≈ 0.7468241:

Strips nTrapezium TₙError in TₙSimpson SₙError in Sₙ
20.7313700.0154540.74718043.6 × 10⁻⁴
40.7429840.0038400.74685543.1 × 10⁻⁵
80.7458660.0009590.74682612.0 × 10⁻⁶
160.7465850.0002400.74682431.2 × 10⁻⁷

Each doubling of n halves h. The trapezium error falls by a factor of about 4, and the Simpson error by a factor of about 16. Simpson’s estimates agree to four decimal places (0.7468) from n = 8; the trapezium rule needs n = 32, where T₃₂ ≈ 0.746764, before it rounds to the same value. When you report a numerical integral, state the rule, the number of strips and the evidence that the quoted digits are stable.

Stepping through a differential equation

For dy/(dx) = f(x,y) with y(x₀) = y₀, the gradient at a known point tells you the direction of the solution curve there. Euler’s method moves a short step h along that tangent:

yₙ₊₁ = yₙ + h f(xₙ,yₙ), xₙ₊₁ = xₙ + h.

The gradient changes during the step, so Euler’s method drifts away from the true curve. The improved Euler method first predicts the end of the step with an Euler step, then uses the average of the gradients at the start and at that predicted end:

uₙ₊₁ = yₙ + h f(xₙ,yₙ),; yₙ₊₁ = yₙ + h/2[f(xₙ,yₙ) + f (xₙ₊₁,uₙ₊₁)].

The predictor uₙ₊₁ is only used inside the second gradient; it is not the answer for that step.

Euler steps drift; improved Euler steps stay close

The solid curve y = e^(−x²) falls from 1 at x = 0 to about 0.367879 at x = 1. Euler points: (0, 1), (0.2, 1), (0.4, 0.92), (0.6, 0.7728), (0.8, 0.587328), (1, 0.399383). Improved Euler points: (0, 1), (0.2, 0.96), (0.4, 0.850944), (0.6, 0.697093), (0.8, 0.528676), (1, 0.372188). At x = 1 the Euler error is about 0.0315 and the improved Euler error about 0.0043.

The solid curve y = e^(−x²) falls from 1 at x = 0 to about 0.367879 at x = 1. Euler points: (0, 1), (0.2, 1), (0.4, 0.92), (0.6, 0.7728), (0.8, 0.587328), (1, 0.399383). Improved Euler points: (0, 1), (0.2, 0.96), (0.4, 0.850944), (0.6, 0.697093), (0.8, 0.528676), (1, 0.372188). At x = 1 the Euler error is about 0.0315 and the improved Euler error about 0.0043.The solid curve y = e^(−x²) falls from 1 at x = 0 to about 0.367879 at x = 1. Euler points: (0, 1), (0.2, 1), (0.4, 0.92), (0.6, 0.7728), (0.8, 0.587328), (1, 0.399383). Improved Euler points: (0, 1), (0.2, 0.96), (0.4, 0.850944), (0.6, 0.697093), (0.8, 0.528676), (1, 0.372188). At x = 1 the Euler error is about 0.0315 and the improved Euler error about 0.0043.
dy/dx = −2xy with y(0) = 1 and step h = 0.2. The exact solution is y = e^(−x²). Euler's method follows the gradient at the start of each step and stays above the falling curve; the improved Euler method averages the start and predicted end gradients and stays close to it.
Open full-size graphOpen full-size graph
What to noticeStraight segments join the computed points; each method only produces values at the step points. The exact curve is drawn from sampled values.
Figure data

This table is included in print while it is open.

Figure data: Euler steps drift; improved Euler steps stay close
Seriesxy
Exact y = e^(−x²)0.001.000000
Exact y = e^(−x²)0.020.999600
Exact y = e^(−x²)0.040.998401
Exact y = e^(−x²)0.060.996406
Exact y = e^(−x²)0.080.993620
Exact y = e^(−x²)0.100.990050
Exact y = e^(−x²)0.120.985703
Exact y = e^(−x²)0.140.980591
Exact y = e^(−x²)0.160.974725
Exact y = e^(−x²)0.180.968119
Exact y = e^(−x²)0.200.960789
Exact y = e^(−x²)0.220.952753
Exact y = e^(−x²)0.240.944027
Exact y = e^(−x²)0.260.934634
Exact y = e^(−x²)0.280.924595
Exact y = e^(−x²)0.300.913931
Exact y = e^(−x²)0.320.902668
Exact y = e^(−x²)0.340.890831
Exact y = e^(−x²)0.360.878447
Exact y = e^(−x²)0.380.865541
Exact y = e^(−x²)0.400.852144
Exact y = e^(−x²)0.420.838283
Exact y = e^(−x²)0.440.823987
Exact y = e^(−x²)0.460.809288
Exact y = e^(−x²)0.480.794216
Exact y = e^(−x²)0.500.778801
Exact y = e^(−x²)0.520.763074
Exact y = e^(−x²)0.540.747067
Exact y = e^(−x²)0.560.730811
Exact y = e^(−x²)0.580.714337
Exact y = e^(−x²)0.600.697676
Exact y = e^(−x²)0.620.680859
Exact y = e^(−x²)0.640.663916
Exact y = e^(−x²)0.660.646876
Exact y = e^(−x²)0.680.629770
Exact y = e^(−x²)0.700.612626
Exact y = e^(−x²)0.720.595473
Exact y = e^(−x²)0.740.578336
Exact y = e^(−x²)0.760.561244
Exact y = e^(−x²)0.780.544221
Exact y = e^(−x²)0.800.527292
Exact y = e^(−x²)0.820.510482
Exact y = e^(−x²)0.840.493812
Exact y = e^(−x²)0.860.477305
Exact y = e^(−x²)0.880.460980
Exact y = e^(−x²)0.900.444858
Exact y = e^(−x²)0.920.428956
Exact y = e^(−x²)0.940.413292
Exact y = e^(−x²)0.960.397882
Exact y = e^(−x²)0.980.382740
Exact y = e^(−x²)1.000.367879
Euler, h = 0.20.001.000000
Euler, h = 0.20.201.000000
Euler, h = 0.20.400.920000
Euler, h = 0.20.600.772800
Euler, h = 0.20.800.587328
Euler, h = 0.21.000.399383
Improved Euler, h = 0.20.001.000000
Improved Euler, h = 0.20.200.960000
Improved Euler, h = 0.20.400.850944
Improved Euler, h = 0.20.600.697093
Improved Euler, h = 0.20.800.528676
Improved Euler, h = 0.21.000.372188

Worked example 2

One curve, two methods

For dy/(dx) = -2xy with y(0) = 1, use a step h = 0.2 to estimate y(0.4) by Euler’s method and by the improved Euler method. Compare both with the exact solution y = e^(-x²).

Show full solutionHide solution
  1. Euler: follow the starting gradient each step

    Reason

    Each step uses only the gradient at its left-hand point.

    Working

    Answer

    y₁ = 1 + 0.2 × (-2 × 0 × 1) = 1,; y₂ = 1 + 0.2 × (-2 × 0.2 × 1) = 0.92.
  2. Improved Euler, first step

    Method

    Predict, then average the start and predicted-end gradients.

    Reason

    The gradient changes during the step; the average of its two end values follows the curve more closely than either alone.

    Working

    Answer

    f(0,1) = 0, u₁ = 1 + 0.2 × 0 = 1,; f(0.2,u₁) = -2(0.2)(1) = -0.4,; y₁ = 1 + 0.1 (0-0.4) = 0.96.
  3. Improved Euler, second step

    Method

    Start from the corrected value y₁ = 0.96, not from the predictor.

    Reason

    The predictor was only a tool for finding the end gradient of the first step.

    Working

    Answer

    f(0.2,0.96) = -0.384, u₂ = 0.96 + 0.2(-0.384) = 0.8832,; f(0.4,0.8832) = -2(0.4)(0.8832) = -0.70656,; y₂ = 0.96 + 0.1 (-0.384-0.70656) = 0.850944.
  4. Compare with the exact value

    Working

    Answer

    y(0.4) = e^(-0.16) ≈ 0.852144. Euler’s estimate 0.92 is about 0.068 too large; the improved estimate 0.850944 is about 0.0012 too small.

Spot the mistake 1

Which y belongs in the second gradient?

About 5 min

Continuing the same problem from (0.2, 0.96), a student writes the next improved Euler step as

y₂ = 0.96 + 0.1[f(0.2,0.96) + f(0.4,0.96)]; = 0.96 + 0.1 (-0.384-0.768); = 0.8448.

Find the error and correct the step.

Write your answer, then compare it with the solution

Show full solutionHide solution
  1. Locate the wrong input

    Method

    The end gradient was evaluated at the old height y = 0.96.

    Reason

    The end gradient must be taken where the solution is predicted to be at x = 0.4. The curve has moved down during the step, so the old height belongs to a different point.

    Working

    Answer

    Predict first: u₂ = 0.96 + 0.2(-0.384) = 0.8832. Then

    y₂ = 0.96 + 0.1[-0.384 + f(0.4,0.8832)]; = 0.96 + 0.1 (-0.384-0.70656); = 0.850944.

Check your understanding 2

Two methods, two steps

For dy/(dx) = x + y with y(0) = 1, use h = 0.1 to estimate y(0.2) by Euler’s method and by the improved Euler method. The exact solution is y = 2e^x-x-1.

Show answerHide answer

Euler’s method:

y₁ = 1 + 0.1 (0 + 1) = 1.1,; y₂ = 1.1 + 0.1 (0.1 + 1.1) = 1.22.

Improved Euler method:

u₁ = 1.1, y₁ = 1 + 0.05 [1 + (0.1 + 1.1)] = 1.11,; f(0.1,1.11) = 1.21, u₂ = 1.11 + 0.1 × 1.21 = 1.231,; f(0.2,1.231) = 1.431, y₂ = 1.11 + 0.05 (1.21 + 1.431) = 1.24205.

The exact value is 2e^(0.2)-1.2 ≈ 1.242806. Euler’s error is about 0.023 and the improved method’s about 0.0008. Both estimates are low because the solution curve bends upwards, so each starting gradient is too gentle.

Common mistakes

  • Using n ordinates instead of n + 1, so that h is wrong.
  • Giving every ordinate weight 2 in the trapezium rule, or forgetting to double the interior ones.
  • Using Simpson’s rule with an odd number of strips, or swapping the weights 4 and 2.
  • Predicting over- or underestimation from whether a curve is rising, instead of from the sign of f''(x).
  • In the improved Euler method, evaluating the end gradient at the old height, or carrying the predictor forward as the next value.
  • Rounding ordinates or intermediate values early. Keep at least two more digits than the answer requires.

Before you move on

Try it yourself 1

Distance from a speed log

Minimal support

A car’s speed v in m s⁻¹ is logged every 2 seconds:

t (s)02468
v (m s⁻¹)05.29.111.813.0

Estimate the distance travelled in the 8 seconds by the trapezium rule and by Simpson’s rule. Then decide, from the data alone, whether the trapezium estimate is likely to be too small or too large.

Try this before viewing the solution

Unit: m
Unit: m
The trapezium estimate is likely to be

Show full solutionHide solution
  1. Distance is the area under the speed–time graph

    Method

    With h = 2, apply both rules to the five recorded speeds.

    Reason

    There is no formula for v; the rules only need the tabulated values.

    Working

    Answer

    T = 2/2[0 + 2(5.2 + 9.1 + 11.8) + 13.0] = 65.2 m,; S = 2/3[0 + 4(5.2 + 11.8) + 2(9.1) + 13.0] = (2/3)(99.2) ≈ 66.1 m.
  2. Judge the direction of the error

    Working

    Answer

    The speed rises by 5.2, 3.9, 2.7 and 1.2 m s⁻¹ in successive intervals, so the graph bends downwards. Straight chords lie below such a curve, so the trapezium estimate 65.2 m is likely to be too small. Simpson’s estimate, about 66.1 m, follows the bending and is the better estimate.

Questions

Open the discussion

Syllabus and review details

Last reviewed:

Back to top