Mathwords logoMathwords

Heun's Method — Definition, Formula & Example

Heun's method is a step-by-step way to approximate the solution of a differential equation. At each step it averages the slope at your current point with the slope at a predicted next point, then uses that average to move forward.

For the initial value problem y′=f(x,y)y' = f(x, y), y(x0)=y0y(x_0) = y_0, Heun's method is the explicit two-stage Runge–Kutta scheme that uses an Euler predictor and a trapezoidal corrector. It is also called the improved Euler method or the explicit trapezoidal method. It is second-order accurate: for a smooth ff, the local truncation error is O(h3)O(h^3) and the global error is O(h2)O(h^2). Euler's method, by contrast, has global error O(h)O(h). A few textbooks attach Heun's name to other Runge–Kutta variants, so check which scheme your course means.

Key Formula

k1=f(xn,yn),k2=f(xn+h,  yn+hk1),yn+1=yn+h2(k1+k2)k_1 = f(x_n, y_n), \quad k_2 = f(x_n + h,\; y_n + h k_1), \quad y_{n+1} = y_n + \frac{h}{2}\left(k_1 + k_2\right)
Where:
  • xn,ynx_n, y_n = Current point on the approximate solution
  • hh = Step size in x
  • k1k_1 = Slope at the start of the step
  • k2k_2 = Slope at the Euler-predicted end of the step
  • yn+1y_{n+1} = Approximate value of y at xnx_n + h

How It Works

First compute the slope k1k_1 at your current point. Take a trial Euler step with that slope to predict the next yy-value. Next, evaluate the slope k2k_2 at that predicted point. Finally, step from the original point using the average 12(k1+k2)\tfrac{1}{2}(k_1 + k_2). Euler's method stops after the first slope. Heun's method spends one extra evaluation of ff per step to correct for the curve bending away from its tangent line.

Worked Example

Problem: Use one step of Heun's method with h=0.5h = 0.5 to approximate y(0.5)y(0.5), given dydx=x+y\dfrac{dy}{dx} = x + y and y(0)=1y(0) = 1.
Step 1: Find the slope at the starting point (0,1)(0, 1).
k1=f(0,1)=0+1=1k_1 = f(0, 1) = 0 + 1 = 1
Step 2: Predict the endpoint with an Euler step, then find the slope there at (0.5,1.5)(0.5, 1.5).
y~=1+0.5(1)=1.5,k2=f(0.5,1.5)=0.5+1.5=2\tilde{y} = 1 + 0.5(1) = 1.5, \qquad k_2 = f(0.5, 1.5) = 0.5 + 1.5 = 2
Step 3: Average the two slopes and take the corrected step from the original point.
y1=1+0.52(1+2)=1+0.25(3)=1.75y_1 = 1 + \frac{0.5}{2}(1 + 2) = 1 + 0.25(3) = 1.75
Answer: Heun's method gives y(0.5)≈1.75y(0.5) \approx 1.75. The exact solution is y=2ex−x−1y = 2e^x - x - 1, so y(0.5)=2e0.5−1.5≈1.797y(0.5) = 2e^{0.5} - 1.5 \approx 1.797. Euler's method with the same step gives only 1.51.5. Its error is about 0.2970.297, while Heun's error is about 0.0470.047.

Why It Matters

Heun's method is usually the first higher-order solver taught in a differential equations or numerical analysis course. It introduces the predictor-corrector idea and leads directly to the classical fourth-order Runge–Kutta method. Engineers and physics programmers use it for simple simulations, such as projectile motion with drag, when Euler's method drifts too far from the true solution.

Common Mistakes

Mistake: Forgetting to halve the sum of the slopes and writing yn+1=yn+h(k1+k2)y_{n+1} = y_n + h(k_1 + k_2).
Correction: The method uses the average slope, so the update is yn+h2(k1+k2)y_n + \tfrac{h}{2}(k_1 + k_2). In the example above, the incorrect version gives 1+0.5(1+2)=2.51 + 0.5(1 + 2) = 2.5 instead of the correct 1.751.75.

Related Terms