Skip to main content

Runge-Kutta RK4 Solver – ODE Integration

Quick answer

RK4 integrates y′=f(x,y) with four slope samples: y′=y from y(0)=1 reaches y(0.1)=1.105170 — 7 correct digits in one step of h=0.1.

Figures are estimates from this calculator’s standard formula — adjust the inputs in the tool below for your exact number.

How the RK4 Solver Works

yₙ₊₁ = yₙ + (h/6)(k₁ + 2k₂ + 2k₃ + k₄), k’s sampled inside the step

RK4 weighs four slope probes across each step — at the left edge, twice at the midpoint, and at the right edge — and combines them with weights 1:2:2:1. For the test equation y′ = y, y(0) = 1, h = 0.1: the four slopes evaluate to k₁ = 1, k₂ = 1.05, k₃ = 1.0525, k₄ = 1.10525, giving y(0.1) = 1 + (0.1/6)(1 + 2.1 + 2.105 + 1.10525) = 1.1051702. The exact solution e⁰·¹ = 1.1051709 differs only in the 7th digit — RK4’s local error is O(h⁵). Euler’s method on the same step returns 1.1, off by 0.005. The calculator prints every k, the weighted update, a step table, and the global error against known solutions (exponential growth, decay, logistics). Halving h divides global error by 16, the signature of a 4th-order method.

  1. 1

    Enter f(x, y) and initial values

    The ODE right-hand side plus x₀, y₀

  2. 2

    Set step h and target

    e.g. h = 0.1 out to x = 1

  3. 3

    Compute the four slopes

    k₁…k₄ are listed per step

  4. 4

    Advance and report error

    The weighted update and exact-solution comparison appear

Use Cases

Physics Simulation

Integrate pendulum and orbit equations without closed forms

Engineering Models

RC-circuit and mixing-tank transients to 6 digits

Coursework

Compare RK4 vs Euler on y′ = y at h = 0.1

Tips

  • 1

    Local error O(h⁵), global O(h⁴) — halve h, cut error 16×

  • 2

    Weights 1:2:2:1 on the four slope samples

  • 3

    One RK4 step often beats ten Euler steps

Common Mistakes

  • Evaluating all four slopes at the left endpoint instead of staggering them

  • Using weights 1:1:1:1 — that collapses to a crude average

  • Believing RK4 handles stiff equations well; implicit methods are needed there

  • Skipping the error check against a known solution during development

FAQs

How accurate is one RK4 step of h=0.1 on y′=y?

y(0.1) ≈ 1.1051702 vs e⁰·¹ = 1.1051709 — 7 significant digits.

What are the k slopes for that step?

k₁ = 1, k₂ = 1.05, k₃ = 1.0525, k₄ = 1.10525 for y(0)=1, h=0.1.

Why choose RK4 over Euler?

Euler gives 1.1 (0.5% error) on the same step; RK4 costs twice the evaluations for vastly more accuracy.

What happens when h halves?

Global error divides by 16 — the fourth-order signature.

Does RK4 work for systems?

Yes — apply the k-formulas componentwise to each dependent variable.