School Launch

Slope Fields and Euler’s Method

A differential equation tells you the slope at every point. Pick an equation, drop a starting point, and watch the true solution follow the little slope marks. Then walk Euler’s method along the same field in steps of size h and see how far it drifts.

Calculus II Lesson 3.2 · Calculus Lessons 7.1 and 7.4 · about 20 minutes

Click or tap the field to choose the starting point, or drag it. With the field focused, arrow keys move the point by 0.5 (hold Shift for 0.1).

Try these

Differential equation

Starting point

Solution through the point:

Euler’s method

4
Euler ends at
Euler estimate
True value
Error (true − Euler)
Each row: yk+1 = yk + h·slope
kxkyk (Euler)slopetrue y

Reading a slope field

A first-order differential equation y′ = f(x, y) does not hand you y. It tells you the slope a solution must have at each point. Draw a short dash with that slope at many points and you get a slope field (also called a direction field). A solution curve is a curve that is tangent to the dashes everywhere it goes.

Every starting point (x0, y0) picks out one solution, the initial value problem. For these five equations the solution through a point is unique, except that y′ = −x/y has no slope at all on the x-axis, so its solutions stop there.

What to look for

  • Equilibrium solutions are horizontal lines where the slope is 0 for every x: y = 0 for y′ = y, and y = 0 and y = 10 for the logistic equation.
  • Isoclines are curves where the slope is the same. For y′ = x − y the slope is 1 all along y = x − 1, so that line is itself a solution, and every other solution gets closer to it.
  • When the slope depends only on x, as in y′ = sin x, the dashes in each column are parallel, and every solution is a vertical shift of every other: y = C − cos x.
  • When the slope depends only on y (an autonomous equation), the dashes in each row are parallel, and solutions are horizontal shifts of each other.

How the true curve is drawn

The blue curve is computed with the fourth-order Runge–Kutta method (RK4) in tiny steps along the curve, which is far more accurate than the drawing can show. The “true value” in the readout comes from the exact solution formula, found by separating variables or with an integrating factor (Lessons 3.3 to 3.5).

Euler’s method

Euler’s idea is to follow the slope field in straight steps. Stand at (xk, yk), read the slope there, and walk along that tangent line for a run of h:

xk+1 = xk + h,   yk+1 = yk + h·f(xk, yk)

Each step is a tangent-line approximation (Calculus I linearization), so where the solution is concave up the tangent line lies below it and Euler underestimates; where it is concave down Euler overestimates. Errors also carry forward: after the first step Euler is reading the slope from a point that is already a little off the true curve.

Smaller steps, smaller error

Use Halve h, double n to reach the same end point with twice as many steps. For small h the error at a fixed end point is roughly proportional to h: halve the step and the error is cut about in half. That is why Euler’s method is called a first-order method. RK4 is fourth order: halving its step cuts the error by about 16.

Check yourself

  1. For y′ = y, y(0) = 1, use Euler with h = 0.5 and 4 steps to estimate y(2). Is the estimate too high or too low, and why?
    Answer

    Each step multiplies by 1 + 0.5 = 1.5, so y(2) ≈ 1.54 = 5.0625. The true value is e2 ≈ 7.3891. The estimate is too low because y = ex is concave up, so every tangent step falls below the curve.

  2. For y′ = x − y, which straight line is a solution? What happens to every other solution as x grows?
    Answer

    Try y = mx + b: then m = x − mx − b for all x, so m = 1 and b = −1. The line y = x − 1 is a solution. Every solution is y = x − 1 + Ce−x, and the last term dies away, so all solutions approach that line.

  3. Why does Euler’s method spiral outward on y′ = −x/y, whose solutions are circles?
    Answer

    Each step runs along a tangent line, and a tangent line to a circle lies outside the circle. Working it out, x2 + y2 grows by h2(1 + x2/y2) at every step, so the radius only ever increases.

A bit of history: Leonhard Euler described this step-by-step method in his Institutiones calculi integralis (1768). Carl Runge and Wilhelm Kutta built the more accurate Runge–Kutta methods around 1900, and RK4 is still a workhorse for engineers today.