Differential Equations • Series and Numerical Methods

Improved Euler/Heun's Method

A smarter numerical technique that averages two slopes to approximate solutions of differential equations more accurately.

A changing curve with sigma and variable symbols for differential equations
Inside this lesson 10 sections 5 questions 8 figures

SECTION 1

Historical Context & Motivation

Many real-world phenomena — from population growth to the cooling of a cup of coffee — are described by differential equations, equations that relate a function to its rate of change. While some of these equations can be solved exactly with algebra and calculus, many cannot. For centuries, mathematicians have sought reliable ways to approximate solutions numerically — using step-by-step arithmetic rather than elegant formulas.

The simplest approach, Euler's method, uses the slope at the start of each step to predict the next value. It works, but it can drift away from the true answer quickly — especially when the solution curves sharply. Karl Heun, a German mathematician working in the late 1800s, proposed a clever fix: instead of relying on just one slope, why not check the slope at both ends of the step and average them? This idea became the Improved Euler method, also called Heun's method.

1768 • Euler's Original Method

Leonhard Euler publishes the first systematic numerical method for solving differential equations, using a single slope per step to march forward.

1900 • Heun's Improvement

Karl Heun introduces the predictor-corrector approach: use Euler's method to predict, then average two slopes to correct. This roughly halves the error at each step.

1901 • Runge–Kutta Framework

Carl Runge and Martin Kutta generalize the idea of combining multiple slope evaluations, placing Heun's method as a second-order member of a powerful family of methods.

1950s–today • Computer-Age Explosion

Digital computers make numerical methods practical for engineering, physics, and biology. Heun's method remains a popular teaching tool and a stepping stone to more advanced algorithms.

The central question Heun's method answers is straightforward: How can we get a more accurate step without doing a lot more work? By adding just one extra slope evaluation per step, the method delivers dramatically better results than basic Euler — setting the stage for even more powerful numerical techniques you may encounter in later courses.

SECTION 2

Core Principles & Definitions

Heun's method is built on a few key ideas that are easy to understand once you see how they fit together. Before diving into formulas, let's lay out the foundational concepts that make this method tick.

1

Initial Value Problem (IVP)

A differential equation dy/dx = f(x, y) paired with a starting point (x₀, y₀). The goal is to trace the solution curve forward from that known point.
2

Step Size (h)

The horizontal distance you advance on each step. Smaller steps generally mean more accuracy but require more calculations. Choosing the right h is a balance of precision and effort.
3

Predictor Step

An initial rough estimate using the Euler method. This 'prediction' is intentionally imperfect — it gives you a tentative endpoint to evaluate a second slope.
4

Corrector Step

The refined estimate that averages the slope at the start and the slope at the predicted endpoint. This average is the key ingredient that makes Heun's method more accurate.
5

Second-Order Accuracy

Heun's method is called 'second-order' because its error per step shrinks proportionally to h². If you cut h in half, the local error drops by roughly a factor of four.
✦

KEY TAKEAWAY

Think of Euler's method like crossing a foggy field by walking in a straight line based on the direction you're facing at the start. Heun's method is smarter: you walk partway, look around to check the slope at that new spot, then go back and split the difference between the two directions. You still take one step, but your path is much closer to the real trail.

SECTION 3

Visual Explanation

A picture is worth a thousand equations. The diagram below shows a single step of both Euler's method and Heun's method, starting from the same point on the true solution curve. Notice how Heun's result lands much closer to the actual curve.

Euler vs. Heun: One Step Comparisonxytrue solution(x₀, y₀)x₀x₀ + hEuler result(uses slope₁ only)Heun result(avg of slope₁ & slope₂)● true valueslope₁ = f(x₀, y₀)slope₂ = f(x₀+h, y_Euler)slope₁slope₂
Starting from the yellow point (x₀, y₀), the red dashed line shows Euler's method using only slope₁. The green solid line shows Heun's result, which averages slope₁ and slope₂ to land much closer to the true solution (purple curve).

In the diagram above, the yellow dot marks our known starting point. Euler's method draws a straight line using slope₁ (the slope at the starting point) and arrives at the red circle — notice it overshoots the true curve. Heun's method also computes slope₁ but then evaluates slope₂ at the Euler endpoint. By averaging these two slopes, the green line follows a more balanced trajectory that closely tracks the purple true-solution curve.

SECTION 4

Mathematical Framework

Let's formalize the ideas from the diagram. Suppose you have a differential equation dy/dx = f(x, y) with an initial condition y(x₀) = y₀, and you choose a step size h. Heun's method advances from (xₙ, yₙ) to (xₙ₊₁, yₙ₊₁) in two stages.

PREDICTOR (EULER STEP)

y~n+1=yn+h×f(xn,yn)ỹₙ₊₁ = yₙ + h × f(xₙ, yₙ)

ỹₙ₊₁ is the preliminary (predicted) value using the slope at the current point. This is identical to one step of basic Euler's method.

CORRECTOR (AVERAGED STEP)

yn+1=yn+(h/2)×[f(xn,yn)+f(xn+1,y~n+1)]yₙ₊₁ = yₙ + (h / 2) × [ f(xₙ, yₙ) + f(xₙ₊₁, ỹₙ₊₁) ]

The corrector takes the average of the slope at the start, f(xₙ, yₙ), and the slope at the predicted endpoint, f(xₙ₊₁, ỹₙ₊₁). This average slope is then used to take the real step.

ADVANCING x

xn+1=xn+hxₙ₊₁ = xₙ + h

The x-coordinate simply moves forward by the step size h on every iteration.

Here is the algorithm in plain English. First, compute slope₁ = f(xₙ, yₙ). Second, use slope₁ to predict ỹₙ₊₁ via a basic Euler step. Third, compute slope₂ = f(xₙ₊₁, ỹₙ₊₁) at the predicted point. Fourth, average the two slopes and use that average to take the final step from yₙ to yₙ₊₁. Then repeat.

💡

Why averaging works

Euler's method assumes the slope stays constant across the whole step — that's like assuming a car's speed doesn't change during a trip. Heun's method checks the speed at both the departure and the destination, then uses the average. If the curve is bending, this self-correcting mechanism captures the bend much better.

SECTION 5

Step-by-Step Algorithmic Flow

To solidify the algorithm, the flowchart below shows how one complete iteration of Heun's method unfolds. Follow the arrows from top to bottom, then loop back for the next step.

Heun's Method — One Iteration FlowchartSTART: Known (xₙ, yₙ)slope₁ = f(xₙ, yₙ)Evaluate the slope at the current pointỹₙ₊₁ = yₙ + h × slope₁Predictor: basic Euler stepslope₂ = f(xₙ + h, ỹₙ₊₁)Evaluate slope at the predicted pointyₙ₊₁ = yₙ + (h/2)(slope₁ + slope₂)Corrector: average the two slopesxₙ₊₁ = xₙ + hAdvance x↺ Repeat with new (xₙ₊₁, yₙ₊₁)
Each box represents one sub-step. The cyan box computes slope₁, the red box performs the predictor, the violet box computes slope₂, and the green box applies the corrector to produce the final answer for that step.

Notice that each iteration requires two evaluations of the function f(x, y) — once at the start and once at the predicted endpoint. Basic Euler uses only one evaluation, so Heun's method does roughly twice the work per step. However, because the error per step drops from order h² (Euler) to order h³ (Heun), you can often use a larger step size and still get better results. In practice, that means Heun's method is almost always a better deal.

Sub-StepWhat You ComputeFormula
1. Slope at startslope₁k₁ = f(xₙ, yₙ)
2. Predictorỹₙ₊₁ỹₙ₊₁ = yₙ + h × k₁
3. Slope at predictionslope₂k₂ = f(xₙ + h, ỹₙ₊₁)
4. Correctoryₙ₊₁yₙ₊₁ = yₙ + (h/2)(k₁ + k₂)

Summary of each sub-step in one Heun iteration

SECTION 6

Worked Example

Let's solve a concrete problem using Heun's method so you can see every calculation in action.

Approximate y(1) using Heun's method with h = 0.5

  1. 1

    Step 1 — State the Problem

    Given the initial value problem dy/dx = x + y with y(0) = 1, approximate y at x = 1 using two steps of Heun's method with step size h = 0.5. The exact solution is y = 2eˣ − x − 1, so we can check our accuracy at the end.
  2. 2

    Step 2 — First Step (x = 0 → x = 0.5)

    We start at (x₀, y₀) = (0, 1). Compute slope₁ = f(0, 1) = 0 + 1 = 1. Now the predictor: ỹ₁ = y₀ + h × slope₁ = 1 + 0.5 × 1 = 1.5. Next compute slope₂ = f(0.5, 1.5) = 0.5 + 1.5 = 2. Finally, the corrector: y₁ = y₀ + (h/2)(slope₁ + slope₂) = 1 + (0.25)(1 + 2) = 1 + 0.75 = 1.75.
    y₁ = 1.75 at x₁ = 0.5
  3. 3

    Step 3 — Second Step (x = 0.5 → x = 1.0)

    Now we start at (x₁, y₁) = (0.5, 1.75). Compute slope₁ = f(0.5, 1.75) = 0.5 + 1.75 = 2.25. The predictor gives ỹ₂ = 1.75 + 0.5 × 2.25 = 1.75 + 1.125 = 2.875. Then slope₂ = f(1.0, 2.875) = 1.0 + 2.875 = 3.875. The corrector: y₂ = 1.75 + (0.25)(2.25 + 3.875) = 1.75 + (0.25)(6.125) = 1.75 + 1.53125 = 3.28125.
    y₂ = 3.28125 at x₂ = 1.0
  4. 4

    Step 4 — Compare with the Exact Solution

    The exact value is y(1) = 2e¹ − 1 − 1 = 2e − 2 ≈ 3.43656. Our Heun approximation of 3.28125 has an error of about 0.155, or roughly 4.5%. For comparison, basic Euler with the same step size gives y(1) ≈ 3.0, an error of roughly 12.7%. Heun's method cut the error by nearly two-thirds with only twice the function evaluations.
    Heun error ≈ 4.5% vs. Euler error ≈ 12.7%
💡

Pro Tip

Organize your work in a table with columns for xₙ, yₙ, slope₁, ỹₙ₊₁, slope₂, and yₙ₊₁. This keeps you from losing track of intermediate values, especially when you have many steps.

SECTION 7

Strengths, Limitations & Comparisons

No numerical method is perfect for every situation. Understanding when Heun's method shines — and when you might need something stronger — is an important part of your numerical toolkit.

FeatureEuler's MethodHeun's Method
Order of accuracy1st order (error ~ h²)2nd order (error ~ h³)
Slope evaluations per step12
Ease of implementationVery simpleSlightly more work
Accuracy for same hLow — drifts quicklyNoticeably better
Best forQuick estimates, learning conceptsBetter estimates with modest effort

Euler vs. Heun at a glance

Limitations to Keep in Mind

  • Still not extremely accurate — for high-precision work, fourth-order Runge–Kutta (RK4) is the standard.
  • Stiff equations — when the solution has both very fast and very slow components, Heun's method can require impractically small steps.
  • Error accumulation — over many steps, errors still compound. Smaller h helps but increases computation.
✦

KEY TAKEAWAY

Heun's method sits in a sweet spot: it's only a small step up in complexity from Euler's method but delivers a big jump in accuracy. Think of it as upgrading from a flip phone to a smartphone — a little more technology under the hood, but a dramatically better experience. For even higher demands, you'd move to RK4, which is like a high-end laptop.

SECTION 8

Connection to the Runge–Kutta Family

Heun's method is actually the simplest member of a broader family called Runge–Kutta methods. The idea behind all Runge–Kutta methods is the same: sample the slope at several carefully chosen points within each step, then combine those samples with a weighted average. The more samples you take, the more accurately you can follow the curve.

MethodSlope EvaluationsOrderLocal Error
Euler (RK1)11stO(h²)
Heun (RK2)22ndO(h³)
Classical RK444thO(h⁵)
Dormand–Prince (RK45)64th–5thAdaptive

The Runge–Kutta family: from simple to advanced

As you continue studying differential equations, you'll encounter the classical RK4 method, which uses four slope evaluations per step and is the workhorse of scientific computing. Adaptive methods like Dormand–Prince even adjust the step size automatically to control error. Understanding Heun's method gives you the conceptual foundation for all of these: every Runge–Kutta method is just a more elaborate version of the 'sample slopes and average' strategy you've learned here.

ℹ

Looking Ahead

In college-level courses or AP-level work, you may also encounter multistep methods (like Adams–Bashforth), which reuse slopes from previous steps instead of sampling multiple slopes within one step. These are a different design philosophy but solve the same underlying problem: approximating solutions accurately and efficiently.

SECTION 9

Practice Problems

Test your understanding with these five problems, arranged from conceptual to challenging. Try each one on paper before reading the answer.

Question 1: CONCEPTUAL

In Heun's method, why do we compute the slope at two different points instead of just one? What advantage does this give over Euler's method?
Show answer
Euler's method uses only the slope at the beginning of the step, which assumes the slope stays constant across the entire interval. If the solution curves, this single-slope assumption causes the approximation to drift away from the true solution. Heun's method evaluates the slope at both the beginning and the (predicted) end of the step, then averages them. This average better represents the overall behavior of the curve across the interval, reducing the local truncation error from O(h²) to O(h³) and producing a second-order accurate method.

Question 2: BASIC CALCULATION

Use one step of Heun's method with h = 1 to approximate y(1) for the IVP: dy/dx = 2x, y(0) = 0.
Show answer
Starting at (0, 0): slope₁ = f(0, 0) = 2(0) = 0. The predictor gives ỹ₁ = 0 + 1 × 0 = 0. Then slope₂ = f(1, 0) = 2(1) = 2. The corrector yields y₁ = 0 + (1/2)(0 + 2) = 1. The exact solution is y = x², so y(1) = 1. In this case, Heun's method gives the exact answer because the true solution is a polynomial of degree 2, and a second-order method integrates quadratics exactly. Euler's method would have given y₁ = 0, which is significantly worse.

Question 3: INTERMEDIATE

For the IVP dy/dx = y, y(0) = 1, use Heun's method with h = 0.5 to approximate y(1). Take two steps and compare your result to the exact solution y = eˣ.
Show answer
Step 1 (x = 0 → 0.5): slope₁ = f(0, 1) = 1. Predictor: ỹ₁ = 1 + 0.5 × 1 = 1.5. slope₂ = f(0.5, 1.5) = 1.5. Corrector: y₁ = 1 + (0.25)(1 + 1.5) = 1 + 0.625 = 1.625. Step 2 (x = 0.5 → 1.0): slope₁ = f(0.5, 1.625) = 1.625. Predictor: ỹ₂ = 1.625 + 0.5 × 1.625 = 2.4375. slope₂ = f(1, 2.4375) = 2.4375. Corrector: y₂ = 1.625 + (0.25)(1.625 + 2.4375) = 1.625 + 1.015625 = 2.640625. The exact value is e¹ ≈ 2.71828, so the error is about 0.078 or roughly 2.9%. Basic Euler with h = 0.5 gives y(1) = 2.25, an error of about 17.2%.

Question 4: APPLIED

A cup of coffee cools according to Newton's law of cooling: dT/dt = −0.1(T − 20), where T is the temperature in °C and t is time in minutes. If the coffee starts at 90 °C, use one step of Heun's method with h = 5 minutes to estimate the temperature at t = 5.
Show answer
Starting at (t₀, T₀) = (0, 90). slope₁ = f(0, 90) = −0.1(90 − 20) = −0.1 × 70 = −7. Predictor: T̃₁ = 90 + 5 × (−7) = 90 − 35 = 55. slope₂ = f(5, 55) = −0.1(55 − 20) = −0.1 × 35 = −3.5. Corrector: T₁ = 90 + (5/2)(−7 + (−3.5)) = 90 + 2.5 × (−10.5) = 90 − 26.25 = 63.75 °C. The exact solution is T(t) = 20 + 70e−0.1t70e^{−0.1t}, so T(5) = 20 + 70e−0.570e^{−0.5} ≈ 20 + 42.46 = 62.46 °C. Heun's estimate of 63.75 °C has an error of about 1.29 °C, or roughly 2.1%. This is a practical use of numerical methods in a physics context.

Question 5: CRITICAL THINKING

Suppose you run Heun's method on dy/dx = −10y with y(0) = 1 and h = 0.5. Compute the first step. Then try h = 0.25. What do you notice about the behavior, and what does this tell you about the relationship between step size and the nature of the equation?
Show answer
With h = 0.5: slope₁ = f(0, 1) = −10(1) = −10. Predictor: ỹ₁ = 1 + 0.5(−10) = −4. slope₂ = f(0.5, −4) = −10(−4) = 40. Corrector: y₁ = 1 + 0.25(−10 + 40) = 1 + 7.5 = 8.5. The exact solution y = e−10xe^{−10x} gives y(0.5) ≈ 0.0067, so the answer of 8.5 is wildly wrong and has the wrong sign behavior. With h = 0.25: slope₁ = −10, predictor ỹ₁ = 1 + 0.25(−10) = −1.5, slope₂ = −10(−1.5) = 15, corrector y₁ = 1 + 0.125(−10 + 15) = 1.625. The exact value y(0.25) ≈ 0.082, so even this is quite poor. This equation is 'stiff' — the solution decays extremely rapidly, and Heun's method requires very small h (much less than 1/10 of the decay timescale 1/10 = 0.1) to track it. This demonstrates that step size must be chosen relative to how fast the solution changes, not just how far you want to go.

SUMMARY

Lesson Summary

Summary

The Improved Euler method (also called Heun's method) is a predictor-corrector technique for solving initial value problems of the form dy/dx = f(x, y). It first uses a standard Euler step to predict an endpoint, evaluates the slope at both ends of the interval, and then uses the average of these two slopes to take a more accurate corrected step.

As a second-order Runge–Kutta method, Heun's method has a local truncation error of O(h³) — a significant improvement over Euler's O(h²) — at the cost of just one additional function evaluation per step. It serves as both a practical tool for approximating solutions and a conceptual bridge to more powerful methods like RK4. Remember: choose your step size h carefully — it should be small enough to capture the behavior of the solution, especially for rapidly changing or stiff equations.

Varsity Tutors • Differential Equations • Improved Euler/Heun's Method