Open the editor

differential equations · calculus · university · explainer

Euler's Method and Direction Fields, Visually

The Tracé team · · 2 min read

A first-order differential equation dy/dx = f(x, y) gives a slope at every point of the plane. Draw those slopes and the solutions become visible before any algebra: they are the curves that follow the arrows.

Start with the direction field

At each point of a grid, draw a short segment with slope f(x, y). For dy/dx = x − y, the segments are flat along the line y = x and every solution bends towards y = x − 1, which is itself a solution. Ask the class to sketch a curve through a starting point before you reveal it: they usually get it right, and that is the point.

Euler's method, one step at a time

Euler's method turns the picture into arithmetic. From (x₀, y₀), move a step h along the slope:

y₁ = y₀ + h · f(x₀, y₀)        x₁ = x₀ + h

For dy/dx = y with y(0) = 1 and h = 0.5, the steps give 1, 1.5, 2.25, 3.375, 5.06… while the exact solution eˣ gives 1, 1.65, 2.72, 4.48, 7.39. The method always lags here, because the slope keeps growing during each step and Euler uses the slope at its start.

Euler steps of size 0.5 below the exact solution of y′ = y
Four Euler steps (solid) against the exact solution (dashed). Halve h and the gap roughly halves: Euler's method is first order.

Systems and the phase plane

A pendulum needs two equations: angle x and angular velocity y, with x′ = y and y′ = −sin x − c·y when there is friction. Plotting y against x gives the phase plane: the swings spiral into the resting position, and with enough energy the pendulum goes over the top instead.

Phase plane of a damped pendulum with trajectories spiralling to rest
A damped pendulum: four starting points, four trajectories, one equilibrium.

Build it in Tracé

  1. Open Plot → Differential equation.
  2. Type x - y after dy/dx =, and a few starting points, one x, y per line.
  3. Animate Solutions drawn so far from 0 to 1 on a click: the curves trace themselves along the field.
  4. For Euler, choose Euler’s method, step by step, set Euler step h and press Reveal one Euler step per click. Keep Show the exact solution, dashed on for the comparison.
  5. For a phase plane, switch Equation to the system form.

Questions

Which solver draws the curves?

A fourth-order Runge–Kutta method with a small step, accurate enough that the curves are what you would get exactly.

Can I show a second-order equation like y″ = −y?

Write it as a system: x′ = y, y′ = −x. The phase plane then shows circles, the trajectories of a harmonic oscillator.

Make this slide yourselfFree to start, in your browser, no code. Present it, share a link or export a video.
Open the editor

More: Animated math slides for teachers · How to create math slides, step by step

New free slides by emailWhen new free slides and lessons come out. No spam, and one click to unsubscribe.