01 / 21

Improved Euler's Method
Heun's Method

A predictor-corrector approach to numerically solving ODEs with greater accuracy than basic Euler's method.

Differential Equations

Why Numerical Methods?

Most differential equations of the form \(\frac{dy}{dx} = f(x, y)\) cannot be solved analytically. Numerical methods let us build approximate solutions step-by-step, using only the slope function \(f(x,y)\).

Analytical
Exact formula for \(y(x)\): possible for only a few special cases.
Numerical
Table of \((x_n, y_n)\) values: works for virtually any ODE.

Quick Refresher: Euler's Method

Euler's method uses the slope at the current point to step forward:

This is a first-order method: halving step size \(h\) halves the error. The problem? It only samples the slope at the beginning of each interval, ignoring how the slope changes across the step.

\(x\) \(y\) True curve Euler steps Error

The Problem with Euler's Method

Euler uses the slope only at the left endpoint \(x_n\). If the slope is changing, this single sample leads to growing error. Imagine crossing a curving road by aiming at only where you started: you'll drift off course.

Undershoot
If the curve bends upward, the left slope is too small, and we fall below the true solution.
Overshoot
If the curve bends downward, the left slope is too large, and we rise above the true solution.

The Big Idea: Predict, then Correct

1
Predict: Use Euler's method to estimate \(\tilde{y}_{n+1}\) at the next point.
2
Evaluate: Compute the slope at that predicted point: \(f(x_{n+1}, \tilde{y}_{n+1})\).
3
Correct: Average the two slopes and take the real step using that average.

The Heun's Method Formulas

Here \(h\) is the step size, \(x_{n+1} = x_n + h\), and \(f(x,y) = \frac{dy}{dx}\) is the slope function given by the ODE.

Geometric Interpretation

\(x\) \(y\) True solution \((x_n, y_n)\) Slope at start Predicted Slope at end Average slope Corrected \(x_n\) \(x_{n+1}\)

Euler vs Heun: Key Distinction

Euler's Method Heun's Method
Slopes sampled 1 (left endpoint) 2 (left + right)
Order of accuracy \(\mathcal{O}(h)\) : first-order \(\mathcal{O}(h^2)\) : second-order
Function evaluations per step 1 2
Improvement factor Baseline Much more accurate per step

How to Apply Heun's Method

1
Identify: Write \(f(x,y)\), initial condition \((x_0, y_0)\), step size \(h\), and target \(x\).
2
Compute \(k_1\): \(k_1 = f(x_n, y_n)\). This is the slope at the current point.
3
Predict: \(\tilde{y}_{n+1} = y_n + h \cdot k_1\).
4
Compute \(k_2\): \(k_2 = f(x_n + h,\; \tilde{y}_{n+1})\). Slope at predicted point.
5
Correct: \(y_{n+1} = y_n + \dfrac{h}{2}(k_1 + k_2)\). Average the two slopes.
6
Repeat from Step 2 with \(x_{n+1} = x_n + h\) until you reach the target.

Worked Example: One Step

1
Setup: \(f(x,y) = x + y\), \(x_0 = 0\), \(y_0 = 1\), \(h = 0.1\).
2
Compute \(k_1\): \(k_1 = f(0, 1) = 0 + 1 = \) \(1\).
3
Predict: \(\tilde{y}_1 = 1 + 0.1(1) = \) \(1.1\).
4
Compute \(k_2\): \(k_2 = f(0.1, 1.1) = 0.1 + 1.1 = \) \(1.2\).
5
Correct: \(y_1 = 1 + \frac{0.1}{2}(1 + 1.2) = 1 + 0.05(2.2) = \) \(1.11\).

Example Results: Comparing Accuracy

For the ODE \(\frac{dy}{dx} = x + y\), \(y(0) = 1\), the exact solution is \(y = 2e^x - x - 1\). At \(x = 0.1\):

Method \(y(0.1)\) Error
Exact \(1.11034\) 0
Euler \(1.10000\) \(0.01034\)
Heun \(1.11000\) \(0.00034\)

Multi-Step Example: Two Iterations

S1
Step 1 (\(x_0=0, y_0=0\)): \(k_1 = 2(0) = 0\), predict \(\tilde{y}_1 = 0\), \(k_2 = 2(0.5) = 1\), correct \(y_1 = 0 + 0.25(0+1) = \) \(0.25\).
S2
Step 2 (\(x_1=0.5, y_1=0.25\)): \(k_1 = 2(0.5) = 1\), predict \(\tilde{y}_2 = 0.25 + 0.5(1) = 0.75\), \(k_2 = 2(1) = 2\), correct \(y_2 = 0.25 + 0.25(1+2) = \) \(1.00\).

Why It Works: Trapezoidal Integration

Integrating both sides of \(\frac{dy}{dx} = f(x,y)\) from \(x_n\) to \(x_{n+1}\):

Euler approximates this integral with a left rectangle. Heun approximates it with a trapezoid:

Left Rectangle (Euler) Trapezoid (Heun)

The trapezoidal rule captures the slope at both endpoints, giving a much better area estimate under the slope curve.

Compact Notation

Heun's method is often written using slope labels \(k_1\) and \(k_2\), which makes it easier to remember and extend:

\(k_1\)
\(k_1 = f(x_n, y_n)\)
Slope at current point.
\(k_2\)
\(k_2 = f(x_n + h,\; y_n + h k_1)\)
Slope at predicted point.
Update
\(y_{n+1} = y_n + \frac{h}{2}(k_1 + k_2)\)
Average and step.

Common Mistakes to Avoid

✕ Using \(\tilde{y}_{n+1}\) as final answer
The predictor value is not the answer. You must complete the corrector step: average the two slopes.
✕ Forgetting the \(\frac{1}{2}\) factor
The corrector divides \(h\) by 2. Writing \(h(k_1 + k_2)\) instead of \(\frac{h}{2}(k_1 + k_2)\) doubles the step.
✕ Evaluating \(k_2\) at \((x_n, \tilde{y}_{n+1})\)
\(k_2\) uses \(x_{n+1} = x_n + h\), not \(x_n\). The x-coordinate must advance too.
✕ Mixing up Euler and Heun results
Make sure you report the corrected \(y_{n+1}\), not the Euler predictor \(\tilde{y}_{n+1}\).

Summary: Numerical Methods Comparison

Property Euler Heun (Improved Euler) RK4
Order 1st 2nd 4th
Slopes per step 1 2 4
Local error \(\mathcal{O}(h^2)\) \(\mathcal{O}(h^3)\) \(\mathcal{O}(h^5)\)
Global error \(\mathcal{O}(h)\) \(\mathcal{O}(h^2)\) \(\mathcal{O}(h^4)\)
Complexity Simple Moderate More involved

Question 1 of 5

In Heun's method, the corrector step computes \(y_{n+1}\) using:

Question 2 of 5

Given \(\frac{dy}{dx} = y\), \(y(0)=1\), \(h=0.1\), what is \(k_1\) in the first step of Heun's method?

Question 3 of 5

Using the same ODE (\(\frac{dy}{dx} = y\), \(y(0)=1\), \(h=0.1\)), what is the predictor value \(\tilde{y}_1\)?

Question 4 of 5

Continuing: \(k_1 = 1\), \(\tilde{y}_1 = 1.1\). Now \(k_2 = f(0.1, 1.1) = 1.1\). What is the corrected value \(y_1\)?

Question 5 of 5

Heun's method is a second-order method. What does this mean for the global truncation error?