Runge-Kutta Calculator (RK4)

Numerically solve any first-order ODE dy/dx = f(x,y) using the classical 4th-order Runge-Kutta method. Enter f(x,y), initial conditions, step size, and number of steps to get a table of solution values.

Presets:

ODE: dy/dx = f(x, y)

Use x and y as variables. Supports sin, cos, exp, log, sqrt, ^, etc.

Solution Table

Step x y
Press "Solve with RK4" to see results.

Solution Curve y(x)

RK4 Formula Reference

k1 = h · f(xn, yn)
k2 = h · f(xn + h/2, yn + k1/2)
k3 = h · f(xn + h/2, yn + k2/2)
k4 = h · f(xn + h, yn + k3)
yn+1 = yn + (k1 + 2k2 + 2k3 + k4) / 6

Summary

Numerically solve any first-order ODE dy/dx = f(x,y) using the classical 4th-order Runge-Kutta method. Enter f(x,y), initial conditions, step size, and number of steps to get a table of solution values.

How it works

  1. Enter the right-hand side f(x, y) of the ODE dy/dx = f(x, y) using standard math syntax (math.js parses sin, cos, exp, log, sqrt, ^, etc.).
  2. Set the initial point (x0, y0), step size h, and number of steps n.
  3. For each step the tool computes four slope estimates k1 = h·f(xn, yn), k2 = h·f(xn + h/2, yn + k1/2), k3 = h·f(xn + h/2, yn + k2/2), k4 = h·f(xn + h, yn + k3).
  4. It advances the solution with yn+1 = yn + (k1 + 2k2 + 2k3 + k4) / 6 — a weighted average that gives 4th-order global accuracy O(h^4).
  5. Results are listed in a step-by-step table and plotted as a solution curve y(x); divergence ( |y| > 1e9 ) stops the run and warns you.

Use cases

  • Solve motion equations such as dy/dx = -y + sin(x) numerically.
  • Verify analytical solutions of first-order ODEs against numerical approximations.
  • Explore how initial conditions affect the shape of solution curves.
  • Compute population growth models dy/dx = r·y·(1 - y/K) step by step.
  • Approximate solutions for ODEs with no closed-form antiderivative.

Frequently Asked Questions

Last updated: 2026-06-13 · Reviewed by Nham Vu