Numerical Methods · interactive

ODE Solver — Slope Fields & RK4

A first-order ODE y′ = f(x, y) assigns a slope to every point in the plane. Solutions are curves that follow those slopes. Type your own equation, click anywhere to launch a solution, and race Euler against Runge–Kutta to see why step size — and method — matter.

Direction field · click to drop an initial condition

Click anywhere on the plane to start a solution from that point.

slope field Euler Runge–Kutta 4 reference (truth)
Step size h
0.50
Euler error
RK4 error

Your equation

Step size & methods

0.50

Click the plane to launch a solution. Then drag the step size up and watch Euler drift off the true curve while RK4 stays glued to it.

Reading a direction field

For a first-order ODE, f(x, y) is literally the slope dy/dx the solution must have at the point (x, y). Draw a little dash with that slope at every point and you get the direction field — a map of the flow. Any solution is just a curve that stays tangent to the dashes, so you can sketch the qualitative behaviour of every initial condition without solving a thing. Click around and watch solutions fan out, merge, or blow up.

Euler vs. Runge–Kutta

Euler's method is the simplest idea that could work: take the slope where you are and step straight along it — yₙ₊₁ = yₙ + h·f(xₙ, yₙ). But the slope changes during the step, so Euler systematically cuts corners; its error shrinks only linearly with h. RK4 samples the slope four times across each step and blends them, cancelling error to fourth order. The payoff is dramatic: at the same step size RK4 is often thousands of times more accurate. Crank h up and the gap between the red Euler path and the green RK4 path (against the gray truth) tells the whole story.

This is how engineers actually solve ODEs

Most real differential equations — orbital mechanics, circuit transients, chemical kinetics, your spring–mass–damper under a weird forcing — have no closed-form solution. So we march them forward numerically, almost always with an RK-family method and an adaptive step size. What you're driving here is the same engine, just with the step size in your hands. For the analytic side — separable, linear, and exact equations you can solve by hand — see the Learn page.

EngineeringCandy · Numerical Methods · slope field + Euler/RK4 integrated live · click it, break it, learn