Improved Euler (Heun) Method Calculator

Published on: November 30, 2025

This Improved Euler (Heun) Method Calculator helps you approximate the solution of a first-order differential equation and shows each step clearly. It works by using an initial slope prediction and then correcting it with an average slope over the step, which usually gives a better approximation than the basic Euler method. This makes it useful for checking answers, understanding how the Improved Euler (Heun) method works, and practising differential equations step by step.

Step-by-step method

  1. Rewrite the ODE as y' = f(x,y).
  2. Read the IVP: y(x0) = y0, choose step size h and steps n.
  3. Compute k1 = f(x_k, y_k).
  4. Predict: y* = y_k + h k1 at x_{k+1} = x_k + h.
  5. Compute k2 = f(x_{k+1}, y*).
  6. Correct: y_{k+1} = y_k + (h/2)(k1 + k2).

Formula bank:

Heun (Improved Euler): y' = f(x,y)
k1 = f(xk, yk)
y* = yk + h·k1
k2 = f(xk+1, y*)
yk+1 = yk + (h/2)·(k1 + k2)

Example 1: dy/dx = x + y, x, y, y(0)=1, h=0.2, n=4

Step 1 - Write y' = f(x,y).

In this problem: Use the ODE in explicit slope form.

y′ = x + y

Step 2 - Read parameters.

In this problem: Use the initial condition and Heun settings.

y(0) = 1
h = 0.2, n = 4

Step 3 - Heun update (k=0).

In this problem: Compute k1, predict y*, compute k2, then correct.

x0 = 0, y0 = 1
k1 = f(x0, y0) = 1
x1 = 0 + 0.2 = 0.2
y* = 1 + 0.2·1 = 1.2
k2 = f(x1, y*) = 1.4
y1 = 1 + (0.2/2)·(1 + 1.4) = 1.24

Step 4 - Heun update (k=1).

In this problem: Compute k1, predict y*, compute k2, then correct.

x1 = 0.2, y1 = 1.24
k1 = f(x1, y1) = 1.44
x2 = 0.2 + 0.2 = 0.4
y* = 1.24 + 0.2·1.44 = 1.528
k2 = f(x2, y*) = 1.928
y2 = 1.24 + (0.2/2)·(1.44 + 1.928) = 1.5768

Step 5 - Heun update (k=2).

In this problem: Compute k1, predict y*, compute k2, then correct.

x2 = 0.4, y2 = 1.5768
k1 = f(x2, y2) = 1.9768
x3 = 0.4 + 0.2 = 0.6
y* = 1.5768 + 0.2·1.9768 = 1.97216
k2 = f(x3, y*) = 2.57216
y3 = 1.5768 + (0.2/2)·(1.9768 + 2.57216) = 2.031696

Step 6 - Heun update (k=3).

In this problem: Compute k1, predict y*, compute k2, then correct.

x3 = 0.6, y3 = 2.031696
k1 = f(x3, y3) = 2.631696
x4 = 0.6 + 0.2 = 0.8
y* = 2.031696 + 0.2·2.631696 = 2.5580352
k2 = f(x4, y*) = 3.3580352
y4 = 2.031696 + (0.2/2)·(2.631696 + 3.3580352) = 2.63066912

Step 7 - Summary table.

In this problem: All Heun iterations in one table.

kxkykk1y*k2yk+1
00111.21.41.24
10.21.241.441.5281.9281.5768
20.41.57681.97681.972162.572162.031696
30.62.0316962.6316962.55803523.35803522.63066912

Step 8 - Final answer.

In this problem: Heun approximation at x_n.

y(xn) yn = 2.63066912(xn = 0.8)

Final answer: Approximation

Example 2: dy/dx = y - x^2 + 1, x, y, y(0)=0.5, h=0.2, n=5

Step 1 - Write y' = f(x,y).

In this problem: Use the ODE in explicit slope form.

y′ = 1 + y − x2

Step 2 - Read parameters.

In this problem: Use the initial condition and Heun settings.

y(0) = 0.5
h = 0.2, n = 5

Step 3 - Heun update (k=0).

In this problem: Compute k1, predict y*, compute k2, then correct.

x0 = 0, y0 = 0.5
k1 = f(x0, y0) = 1.5
x1 = 0 + 0.2 = 0.2
y* = 0.5 + 0.2·1.5 = 0.8
k2 = f(x1, y*) = 1.76
y1 = 0.5 + (0.2/2)·(1.5 + 1.76) = 0.826

Step 4 - Heun update (k=1).

In this problem: Compute k1, predict y*, compute k2, then correct.

x1 = 0.2, y1 = 0.826
k1 = f(x1, y1) = 1.786
x2 = 0.2 + 0.2 = 0.4
y* = 0.826 + 0.2·1.786 = 1.1832
k2 = f(x2, y*) = 2.0232
y2 = 0.826 + (0.2/2)·(1.786 + 2.0232) = 1.20692

Step 5 - Heun update (k=2).

In this problem: Compute k1, predict y*, compute k2, then correct.

x2 = 0.4, y2 = 1.20692
k1 = f(x2, y2) = 2.04692
x3 = 0.4 + 0.2 = 0.6
y* = 1.20692 + 0.2·2.04692 = 1.616304
k2 = f(x3, y*) = 2.256304
y3 = 1.20692 + (0.2/2)·(2.04692 + 2.256304) = 1.6372424

Step 6 - Heun update (k=3).

In this problem: Compute k1, predict y*, compute k2, then correct.

x3 = 0.6, y3 = 1.6372424
k1 = f(x3, y3) = 2.2772424
x4 = 0.6 + 0.2 = 0.8
y* = 1.6372424 + 0.2·2.2772424 = 2.09269088
k2 = f(x4, y*) = 2.45269088
y4 = 1.6372424 + (0.2/2)·(2.2772424 + 2.45269088) = 2.110235728

Step 7 - Heun update (k=4).

In this problem: Compute k1, predict y*, compute k2, then correct.

x4 = 0.8, y4 = 2.110235728
k1 = f(x4, y4) = 2.470235728
x5 = 0.8 + 0.2 = 1
y* = 2.110235728 + 0.2·2.470235728 = 2.6042828736
k2 = f(x5, y*) = 2.6042828736
y5 = 2.110235728 + (0.2/2)·(2.470235728 + 2.6042828736) = 2.6176875882

Step 8 - Summary table.

In this problem: All Heun iterations in one table.

kxkykk1y*k2yk+1
000.51.50.81.760.826
10.20.8261.7861.18322.02321.20692
20.41.206922.046921.6163042.2563041.6372424
30.61.63724242.27724242.092690882.452690882.110235728
40.82.1102357282.4702357282.60428287362.60428287362.6176875882

Step 9 - Final answer.

In this problem: Heun approximation at x_n.

y(xn) yn = 2.6176875882(xn = 1)

Final answer: Approximation