MATH 4810Computational Modelling

Module 02 · Unit 2.1 · Lesson 2 of 3

Modified Euler and Midpoint Methods

Use a trial step to improve the estimate of the derivative during the step. Two evaluations of f buy a full order of accuracy.

Duration ≈ 3 hours Prerequisite Lesson 1 Feeds Lab 3 · Assignment 2
  1. Lesson 1
  2. Lesson 2
  3. Lesson 3

1 Modelling context

Euler's method uses the derivative at the start of the step and holds it constant. The error is proportional to the curvature of the solution and to the square of the step size. One obvious way to improve the method is to use a better estimate of the average derivative over the step rather than the derivative at its start.

This lesson introduces two second-order methods that do exactly that. Both use the Euler prediction to take a trial step, evaluate the derivative at the trial point, and then combine the two derivatives to produce a more accurate estimate of the average rate of change.

The methods are conceptually simple but represent a genuine improvement. Halving the step size reduces the global error by a factor of four rather than two. In practical terms, achieving the same accuracy with modified Euler as with forward Euler requires dramatically fewer steps.

The cost-accuracy tradeoff

Both methods in this lesson require two evaluations of f per step, compared to one for Euler. If each evaluation is expensive, the extra cost must be weighed against the extra accuracy. For most problems, the second-order methods are a clear win.

2 Learning objectives

By the end of this lesson you will be able to

  • Derive the modified Euler (Heun) method from the trapezoidal rule.
  • Derive the midpoint method from a central-difference approximation.
  • Implement both methods in a spreadsheet and compare against Euler.
  • Demonstrate second-order convergence numerically.
  • Choose between the two methods based on the problem and the available information.

3 Prerequisite review

Predictor–corrector structure
A two-stage method in which a preliminary prediction is made and then corrected using information from the predicted point.
Trapezoidal rule
The integral of a function over an interval can be approximated by the average of its values at the endpoints times the interval width.
Central difference
The derivative at a point can be approximated using values at symmetric points on either side. The approximation is second-order accurate.
Order of a method
The exponent p in the global error scaling O(hp). Introduced in Lesson 1 and developed formally in Lesson 3.

4 Mathematical formulation

Both methods in this lesson are of the form

y_{n+1} = y_n + h Φ(t_n, y_n, h)

where Φ approximates the average slope over the interval [t_n, t_{n+1}]. The two methods differ in how that average is computed.

Modified Euler (Heun's method)

The idea is to use the trapezoidal rule on the integral form of the ODE. Integrating dy/dt = f(t, y) from t_n to t_{n+1}:

y(t_{n+1}) = y(t_n) + ∫ f(t, y) dt   over [t_n, t_{n+1}]

Approximating the integral by the trapezoidal rule:

y_{n+1} = y_n + (h/2) [ f(t_n, y_n) + f(t_{n+1}, y_{n+1}) ]

This is the implicit trapezoidal method. It is implicit because y_{n+1} appears on both sides. To obtain an explicit method, replace the y_{n+1} on the right-hand side with the Euler prediction:

ỹ_{n+1} = y_n + h f(t_n, y_n)                         (predictor)
y_{n+1} = y_n + (h/2)[ f(t_n, y_n) + f(t_{n+1}, ỹ_{n+1}) ]   (corrector)

This is modified Euler, also called Heun's method. It requires two evaluations of f per step: one at the start and one at the predicted endpoint.

Midpoint method

An alternative is to use the central-difference approximation to the derivative at the midpoint of the step:

y(t_{n+1}) = y(t_n) + h f(t_n + h/2, y(t_n + h/2)) + O(h³)

The value y(t_n + h/2) is itself unknown, so it is approximated using an Euler half-step:

k₁ = f(t_n, y_n)
k₂ = f(t_n + h/2,  y_n + (h/2) k₁)
y_{n+1} = y_n + h k₂

This is the midpoint method. It also requires two evaluations of f per step, but the second evaluation is at the midpoint rather than the endpoint.

Both methods are second-order

Both methods have local truncation error O(h³), and therefore global error O(h²). This is a full order better than Euler. The derivation of these orders is the subject of Lesson 3.

Slope estimates in Euler, modified Euler, and midpoint Three side-by-side diagrams. Euler uses the slope at the start of the step. Modified Euler uses the average of the slopes at the start and at the Euler-predicted endpoint. Midpoint uses the slope at the midpoint, estimated from an Euler half-step. A smooth curve represents the true solution in each panel. Euler slope at start only Modified Euler average of start and endpoint Midpoint slope at midpoint
Figure 2.4. Slope estimates in three methods. Euler uses the slope at the start; modified Euler uses the average of the slopes at the two endpoints; midpoint uses the slope at the middle of the step.

5 Worked example

Comparing Euler, modified Euler, and midpoint on dy/dt = y

Return to the problem from Lesson 1: dy/dt = y, y(0) = 1, with exact solution y(t) = et. Use a single step from t = 0 to t = 0.1 and compare the three methods.

Euler.

  • y_1 = 1 + 0.1 · 1 = 1.1
  • Exact: e0.1 ≈ 1.10517
  • Error: 0.00517

Modified Euler.

  • Predictor: ỹ_1 = 1 + 0.1 · 1 = 1.1
  • Corrector: y_1 = 1 + (0.1/2)( 1 + 1.1 ) = 1 + 0.105 = 1.105
  • Error: 1.10517 − 1.105 = 0.00017

Midpoint.

  • k₁ = f(0, 1) = 1
  • k₂ = f(0.05, 1 + 0.05 · 1) = f(0.05, 1.05) = 1.05
  • y_1 = 1 + 0.1 · 1.05 = 1.105
  • Error: 1.10517 − 1.105 = 0.00017

Comparison.

Euler's error for this single step is about 0.005. Modified Euler and midpoint both reduce the error to about 0.00017 — roughly a thirty-fold improvement. The extra evaluation of f per step has bought a substantial gain.

Effect over many steps.

Over a full interval [0, 1] with step size h = 0.1:

  • Euler: error ≈ 0.125
  • Modified Euler: error ≈ 0.0051
  • Midpoint: error ≈ 0.0051

Over the full interval, the difference between Euler and the second-order methods persists. Both second-order methods produce errors roughly 25 times smaller than Euler's at the same step size.

Effect of halving the step size.

Reducing h from 0.1 to 0.05 halves Euler's global error (factor of 2, consistent with first order). For the second-order methods, the error is reduced by roughly a factor of 4. This is the numerical signature of second-order convergence, and it is confirmed formally in Lesson 3.

6 Verification check

Checks to perform

  • Reproduce one step by hand. Compute the predictor and corrector for a single step and compare against the spreadsheet.
  • Verify both methods agree on a linear problem. When f(t, y) = a (a constant), all three methods should produce y_{n+1} = y_n + a h exactly. This tests the formulas.
  • Check the convergence order numerically. Run each method with h and h/2. The error ratio for Euler should be about 2; for the second-order methods, about 4.
  • Confirm the second evaluation uses the correct point. Modified Euler evaluates f at (t_{n+1}, ỹ_{n+1}); midpoint evaluates at (t_n + h/2, y_n + (h/2) k₁). A common error is to swap these.
  • Verify the weighting. Modified Euler uses the average (1/2)(k₁ + k₂); midpoint uses k₂ alone. The weights are not interchangeable.

7 Interpretation

The second-order methods are a substantially better default than Euler for most problems. The extra evaluation per step is usually cheap compared to the improvement in accuracy, and the methods are easy to implement.

Comparison of methods in this lesson
Method Evaluations per step Order Error on dy/dt = y, h = 0.1, t ∈ [0,1]
Euler 1 1 ≈ 0.125
Modified Euler 2 2 ≈ 0.0051
Midpoint 2 2 ≈ 0.0051

Doubling the evaluations per step reduced the error by a factor of roughly 25. The improvement is not linear in cost: each additional order of accuracy reduces the error more than proportionally at a fixed step size.

Which method should you use?

For most problems, the choice between modified Euler and midpoint is a matter of taste. Modified Euler is easier to remember and is related directly to the trapezoidal rule. Midpoint generalises more naturally to the higher-order methods developed in Unit 2.2, where the stage structure becomes the organising principle.

8 Uncertainty and limitations

The second-order methods improve accuracy but do not eliminate any of the fundamental limitations of one-step methods. They remain explicit methods subject to stability constraints and to the same qualitative dependence on the local curvature of the solution.

What the second-order methods do and do not address
Property Improvement Note
Truncation error Yes, by one order Local O(h³), global O(h²)
Roundoff error No Still accumulates; slightly more arithmetic per step
Stability Marginal Second-order methods have slightly larger stability regions than Euler, but remain conditionally stable
Stiffness No Explicit methods still require small steps for stability
Model-form error No A better method does not fix a wrong equation

Accuracy is not validity

A second-order method produces a more accurate solution to the equation you gave it. It does not make the equation more correct. If the ODE is the wrong model of the system, a second-order solution to the wrong model is still the wrong answer.

9 Common implementation errors

Watch for these

  • Swapping the predictor and corrector points. Modified Euler predicts at t_{n+1}, not t_n + h/2. Midpoint predicts at the midpoint, not the endpoint. Confusing the two produces a method that is neither.
  • Using the corrected value in the corrector twice. Modified Euler evaluates the corrector once, using the predictor value. Iterating the corrector without a convergence criterion introduces an uncontrolled amount of work for a negligible gain.
  • Applying midpoint with a non-uniform grid without adjusting the midpoint. The midpoint method assumes the step size is constant. On a non-uniform grid, the point t_n + h/2 must be computed from the actual step.
  • Mixing up the weights in modified Euler. Both evaluations enter with weight 1/2, not weights 1 and 0 or any other combination.
  • Assuming second-order means twice as accurate. The order refers to how the error scales with h, not to the error at a fixed h. The actual improvement depends on the problem.
  • Forgetting to verify the order numerically. The order is a theoretical property. Confirming it on your problem ensures the implementation matches the theory.

10 Independent modelling task

Your turn

  1. Use the same initial-value problem you chose in Lesson 1, with a known analytical solution.
  2. Implement modified Euler in your spreadsheet, alongside the Euler method. Use a clearly labelled input region for the step size and endpoint.
  3. Repeat the implementation for the midpoint method.
  4. Run all three methods at h = 0.2, h = 0.1, and h = 0.05. Compute the absolute error at the endpoint against the analytical solution.
  5. Tabulate the ratios of successive errors for each method. Confirm that the ratios are approximately 2 for Euler and approximately 4 for the second-order methods.
  6. Plot the three solutions alongside the analytical solution for one step size. Describe the qualitative difference between the methods.
  7. Compare the cost of the three methods in terms of evaluations of f per step and total evaluations over the interval. Determine the cost required to achieve a given accuracy level.

This comparison forms the basis of Laboratory 3 and the ODE component of Assignment 2.

11 Reflection prompt

Reflect before continuing

Doubling the evaluations per step reduced the error by a factor of about 25 in the worked example. Is that gain worth the additional cost in every problem?

Two or three sentences. Consider both the case where f is cheap to evaluate and the case where it is expensive.

12 Lesson summary

Key takeaways

  • Modified Euler (Heun) uses the average of the slopes at the two endpoints. The endpoint slope is evaluated at the Euler-predicted value.
  • Midpoint uses the slope at the middle of the step. The midpoint value is estimated from an Euler half-step.
  • Both are second-order. Local error is O(h³); global error is O(h²). Halving the step reduces the error by a factor of about four.
  • Both require two evaluations of f per step. The additional cost is usually a small price for the additional order.
  • Higher order is not higher validity. The methods produce more accurate solutions to the given ODE; they do not make the ODE more correct.

Coming next

Lesson 3 develops the formal theory of local and global error that underlies the convergence orders observed in this lesson.

§ Self-quiz, practice, and homework

Self-quiz

Q1

Modified Euler's method uses two evaluations of f per step at:

Show answer

The start and the endpoint. The endpoint is the Euler-predicted value.

Q2

Midpoint method uses the slope at:

Show answer

The middle of the step.

Q3

Both modified Euler and midpoint methods are:

Show answer

Second-order. Local error O(h³); global error O(h²).

Q4

Halving the step size in a second-order method reduces the global error by approximately:

Show answer

4. The error scales as h².

Q5

The corrector step in modified Euler uses:

Show answer

The average of the slope at the start and at the predicted endpoint.

Practice exercises

  1. Apply modified Euler by hand to dy/dt = −2y, y(0) = 1 with h = 0.1 for two steps. Compare against Euler and the exact solution at t = 0.2.
  2. Repeat exercise 1 with midpoint method. Compare the results.
  3. Show that modified Euler is exact when f(t, y) = a (constant).
  4. Write the modified Euler update rule for dy/dt = y − t and compute one step from (0, 1) with h = 0.2.

Homework problems

  1. Method comparison. Implement Euler, modified Euler, and midpoint in a spreadsheet for dy/dt = y − t, y(0) = 0. Run each at h = 0.2, 0.1, 0.05, 0.025. Tabulate the error at t = 2. Compute the observed order for each method. Confirm that Euler is first-order and the second-order methods are second-order.
  2. Cost comparison. For each method, compute the number of evaluations of f required to reach a target error of 10⁻⁴ at t = 2. Rank the methods by total cost.
  3. Derivation. Derive modified Euler from the integral form of the ODE. Then derive midpoint from a central-difference approximation of the derivative. Show that both reduce to the trapezoidal or midpoint rule for the integral.

Mini project

Choose an ODE with a known analytical solution. Implement all three methods (Euler, modified Euler, midpoint) and produce a comparison report. Include: convergence study tables, log-log error plots, cost comparison, and a recommendation for which method to use for the problem. This is the basis for Laboratory 3 and the ODE component of Assignment 2.

👤