Runge Kutta 2 Calculator

Solve an ODE with Heun's second order method.

Math and PercentUpdated 2026-11-202 min read
Runge Kutta 2 Calculator
Final y
...
Final x...
Method used...

What it does

Runge Kutta methods improve on Euler's method by sampling the right hand side of a differential equation several times within each step. The second order version, often called Heun's method, uses an Euler trial step to estimate the slope at the far end and then averages the two slopes.

Florida State University numerical methods notes explain that each Runge Kutta step uses trial evaluations of the right hand side, reducing local truncation error. A method of order two has global error that shrinks like the step size squared.

Middlebury College differential equations notes give the Heun update and list related second order choices such as midpoint and Ralston, which differ in how the two samples are weighted.

This tool offers three simple equations, an initial condition, a step size and a step count. It reports the final x and y values.

Heun's method is a good middle ground between the simplicity of Euler and the cost of fourth order Runge Kutta.

How to use

  1. Choose a built in differential equation.
  2. Enter the initial x and y values.
  3. Enter a positive step size.
  4. Enter the number of steps, up to 1000.
  5. Read the final y value in the main result.
  6. Compare with Euler's method on the same inputs.

Formula

k1 = f(x, y), k2 = f(x + h, y + h k1), y(next) = y + h (k1 + k2)/2.
f(x,y)
Right hand side of dy/dx = f(x,y).
k1
Slope at the start of the step.
k2
Slope estimated at the end using an Euler trial value.
h
Step size.

The engine evaluates the chosen right hand side twice per step. It keeps the step size constant and reports the final values to eight decimal places.

Worked example

Example: dy/dx = y

Initial values x = 0, y = 1, step size 0.1, 10 steps.

  1. At the start, k1 = 1 and the Euler trial gives y trial = 1.1 at x = 0.1.
  2. The second slope is k2 = 1.1.
  3. The average slope is 1.05, giving y = 1 + 0.1 x 1.05 = 1.105 after one step.
  4. Repeating across 10 steps gives y about 2.71408085 at x = 1.
  5. The exact solution is e, about 2.71828, so the error is smaller than Euler's 2.59374.
  6. The tool reports final y 2.71408085.

Reference table

Comparison at x = 1 for dy/dx = y
MethodEstimateError vs e
Euler2.59374246about 0.1245
Heun RK22.71408085about 0.0042
Exact2.718281830

Limits

  • Only three built in equations are available.
  • The method has second order accuracy.
  • Very stiff problems may still need tiny steps.
  • Results are shown to eight decimal places.

Common mistakes

  • Using the Euler slope for the second sample instead of the trial endpoint.
  • Forgetting to average the two slopes.
  • Expecting fourth order accuracy from a two stage method.
  • Using a step size too large for the desired precision.
  • Comparing methods with different step sizes.

Try it yourself

Quick checks. Answers sit tucked under each question.

What is another name for RK2?

Heun's method or the improved Euler method.

What is the Heun update?

y next = y + h(k1 + k2)/2.

How does its accuracy compare with Euler?

It is second order rather than first order.

Questions

What is Runge Kutta 2?

A two stage numerical method for ordinary differential equations.

Why sample twice?

To estimate the slope change across the step and reduce error.

Is it the same as midpoint?

No. Midpoint uses a different weighting of the two samples.

What is its order?

Second order.

Can I use my own equation?

Not on this page. Three built in options are provided.

When is RK4 preferable?

When higher accuracy per step is worth the extra evaluations.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.