Runge-Kutta RK4 Calculator

The fourth-order Runge-Kutta method, known as RK4, is the standard tool for numerically solving a first-order ordinary differential equation. Given the right-hand side f(x, y), an initial point and a target value of x, it advances in steps that each blend four slope estimates into a single high-accuracy update. This calculator lets you type the equation using x and y, set the initial condition, the end point and the number of steps, and returns the solution y at the end point along with the step size used. RK4 is fourth-order accurate, far more precise than Euler's method.

0.00
0.00
0.00
0.00

RK4 step formula

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); x next = x + h

Use x and y as variables in f. Supported: + - * / ^, sin, cos, tan, exp, ln, log, sqrt, abs, pi, e.

RK4 context

  • RK4 is fourth-order accurate; global error scales with the fourth power of the step size.
  • It solves first-order initial value problems y prime equals f(x, y).
  • For y prime equals y with y(0) equal to 1, the solution at x = 1 approaches e.
  • More steps reduce the step size and the error, up to floating-point limits.
  • RK4 is far more accurate than Euler's method for the same step size.

Runge-Kutta RK4: frequently asked questions

What does the RK4 method do?

The classic fourth-order Runge-Kutta method solves an initial value problem y prime equals f(x, y) with y(x0) equal to y0. Starting from the initial point, it advances in steps, combining four slope estimates per step to update y. It is fourth-order accurate, so its error per step falls with the fifth power of the step size.

What are the four slope estimates?

Each step uses k1 at the start, k2 and k3 at the midpoint using k1 and then k2, and k4 at the end using k3. The update is y plus h over six times (k1 plus two k2 plus two k3 plus k4). This weighted average is what gives RK4 its high accuracy.

How do I enter the differential equation?

Enter the right-hand side f(x, y) using x and y as variables. For example, for y prime equals y type y, and for y prime equals x plus y type x + y. Supported operations include plus, minus, times as star, divide, power as caret, parentheses, and the common trig, exponential and logarithmic functions.

How many steps should I use?

More steps mean a smaller step size and higher accuracy, up to floating-point limits. A few hundred steps is usually ample for smooth problems over a modest interval. If the solution changes rapidly, increase the number of steps to keep the error small.

How accurate is RK4 compared to Euler's method?

Euler's method is first-order, with global error proportional to the step size. RK4 is fourth-order, with global error proportional to the step size to the fourth power, so for the same step size it is dramatically more accurate. That is why RK4 is the standard workhorse for non-stiff ODEs.

Official sources

  • NIST Digital Library of Mathematical Functions: Ordinary Differential Equations, numerical solution.
  • U.S. National Institute of Standards and Technology: NIST home, mathematical references.

Reviewed by the CalculatorHub team, edited by James Graham, 17 June 2026. See our methodology.