Runge-Kutta RK4 Calculator
The classic fourth-order Runge-Kutta method is the workhorse of numerical ODE solving, blending four slope evaluations per step into one highly accurate update. This calculator applies RK4 to the linear test equation dy/dx = k times y so you can compare its estimate against the exact exponential solution. Enter the rate constant, the starting point, the end point, and the number of steps. It returns the RK4 estimate at the end, the exact value, and the absolute error, showing how a handful of steps already reaches accuracy that Euler needs thousands of steps to match.
RK4 formulas
Step size h = (final x - x0) / number of steps; f(x, y) = k * y
k1 = f(x, y)
k2 = f(x + h/2, y + h/2 * k1)
k3 = f(x + h/2, y + h/2 * k2)
k4 = f(x + h, y + h * k3)
y_next = y + (h/6) * (k1 + 2*k2 + 2*k3 + k4)
Exact solution: y(x) = y0 * e^(k * (x - x0))
The four slope samples give a fourth-order accurate step. The exact value comes from the closed-form solution of dy/dx = k y, so the reported error is the true numerical error.
Worked example and notes
- With k = 1, x0 = 0, y0 = 1, final x = 1, the exact value is e, about 2.7183.
- With just 10 RK4 steps the error is around 0.0000023, far smaller than Euler.
- RK4 global error scales with the fourth power of the step size.
- Halving the step size cuts RK4 error by roughly 16 times.
- A negative k models exponential decay and is handled identically.
Runge-Kutta RK4: frequently asked questions
What is the RK4 method?
The classic fourth-order Runge-Kutta method (RK4) advances a differential equation by combining four slope estimates within each step: one at the start, two at the midpoint, and one at the end. The weighted average of these slopes gives a far more accurate step than the simple Euler method.
Which equation does this calculator solve?
It solves the linear test equation dy/dx = k times y, whose exact solution is y = y0 times e to the power k times (x minus x0). This benchmark lets you compare the RK4 estimate directly against the true value and see how small its error is.
Why is RK4 so much more accurate than Euler?
RK4 has a global error proportional to the step size to the fourth power, compared with the first power for Euler. So halving the step size reduces RK4 error by roughly a factor of 16, while Euler error only halves. For smooth problems RK4 reaches high accuracy with few steps.
What are the four RK4 slope terms?
They are k1 (slope at the start), k2 (slope at the midpoint using k1), k3 (slope at the midpoint using k2), and k4 (slope at the end using k3). The next value is y plus h over 6 times (k1 plus 2 k2 plus 2 k3 plus k4).
What inputs does the calculator take?
Enter the rate constant k, the initial x and y values, the final x value, and the number of steps. The calculator splits the interval into equal steps, runs RK4, and reports the final estimate, the exact value, and the absolute error.
Official sources
- NIST Digital Library of Mathematical Functions: Ordinary differential equations.
- NASA Technical Reports Server: Runge-Kutta integration methods.
Reviewed by the CalculatorHub team, edited by James Graham, 16 June 2026. See our methodology.