Skip to content
ENExplore Calculators

Runge-Kutta Calculator

Solve an ODE numerically using the classical 4th-order Runge-Kutta method (RK4).

About Runge-Kutta Calculator

Classical fourth-order Runge-Kutta advances a differential equation by sampling the slope four times per step — once at the start, twice at the midpoint, once at the far end — and averaging them with weights 1:2:2:1. The midpoint samples get double weight because they best represent the average slope across the interval, and that weighting is what buys fourth-order accuracy from only four evaluations. This implementation also integrates a second time with the step count doubled and compares the two answers: for a fourth-order method the difference divided by 15 is a Richardson estimate of the remaining error, so you get not just an answer but a defensible bound on how much to trust it. Halving the step size cuts the error roughly sixteen-fold.

Formulas

Slope samples

k1 = f(x, y); k2 = f(x + h/2, y + h k1/2); k3 = f(x + h/2, y + h k2/2); k4 = f(x + h, y + h k3)

h
Step size (x_end - x_start) / steps

RK4 step

y(next) = y + (h/6)(k1 + 2 k2 + 2 k3 + k4)

Richardson error estimate

error = |y(2n steps) - y(n steps)| / 15

15
2^4 - 1, from the method's fourth-order accuracy

Worked example

With the default values below, Runge-Kutta Calculator returns y at the end point of 5.3054715084. Change any input above and every figure here is recalculated in your browser.

Inputs used

dy/dx = f(x, y)
y - x^2 + 1
Start x
0
Start y
0.5
Integrate to x
2
Number of stepsaccepts 1–20,000
20

Results

y at the end point
5.3054715084
Step size h
0.10000000
Estimated Error
4.3654 × 10⁻⁷
Function Evaluations
80

Step by step

  1. 1Values used
  2. 2Slope samples
  3. 3RK4 step
  4. 4Richardson error estimate
  5. 5y at the end point= 5.3054715084
  6. 6Step size h= 0.10000000
  7. 7Estimated Error= 0.0000
  8. 8Function Evaluations= 80

Assumptions and limits

  • The result is derived only from the 5 inputs listed above. Anything not among them is not part of the calculation.
  • In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
  • Figures are rounded for display to 10 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.

How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.

Frequently Asked Questions

How is the error estimate produced?

The equation is integrated twice, once with your step count and once with double it. For a fourth-order method halving the step reduces the error by a factor of about sixteen, so the gap between the two answers divided by fifteen estimates the error remaining in the finer one. That is Richardson extrapolation, and it needs no knowledge of the exact solution.

How many steps should I use?

Start with 20 and check the error estimate. Doubling the steps should shrink it by roughly sixteen; if it does not, the solution is probably not smooth over the interval, or the problem is stiff. Beyond a few thousand steps floating-point round-off starts to dominate and more steps stop helping.

Why does RK4 fail on some equations?

RK4 is an explicit method with a bounded region of stability. Stiff equations — those mixing very fast and very slow components — force impractically tiny steps to stay stable. Solutions with a singularity inside the interval will also blow up. Implicit methods such as backward Euler or a BDF solver handle those cases.

Runge-Kutta Calculator | Calcrivo