Interactive visualiser

Slope fields and Euler's method

See the slope field of a first-order differential equation and follow it with Euler's method from a point you choose. Change the step size and the number of steps, and compare the result with the exact solution.

Loading the visualiser…

Works on a phone, tablet or computer — nothing to install, no account.

What you are looking at

A differential equation dydx=f(x,y)\dfrac{dy}{dx} = f(x, y) gives the gradient of the solution curve at every point without giving the curve itself. The slope field draws a short segment with that gradient at each point of a grid spaced 0.50.5 apart. Every solution curve runs along the segments, so the field shows the shape of the whole family of solutions at once; the green starting point (x0,y0)(x_0, y_0) picks out one of them.

Euler's method replaces the curve with straight steps. From (xn,yn)(x_n, y_n) it moves a distance hh to the right along the gradient at that point: xn+1=xn+hx_{n+1} = x_n + h and yn+1=yn+h f(xn,yn)y_{n+1} = y_n + h\,f(x_n, y_n). Because the gradient is only updated at the start of each step, the yellow Euler path drifts away from the exact solution, drawn in blue. The working shows the first step, the point reached after nn steps and the error there.

Try this

  1. 1With the default dydx=x+y\dfrac{dy}{dx} = x + y, y(0)=0y(0) = 0, h=0.5h = 0.5 and n=4n = 4, Euler's method reaches y4=2.0625y_4 = 2.0625 at x=2x = 2, while the exact solution y=ex−x−1y = e^x - x - 1 gives e2−3≈4.39e^2 - 3 \approx 4.39.
  2. 2Halve the step to h=0.25h = 0.25 and double nn to 88 so that you still finish at x=2x = 2. The error falls from about 2.332.33 to about 1.431.43: smaller steps follow the curve more closely, but the error does not vanish.
  3. 3Press Play: nn goes back to 00 and one step is added at a time until the path reaches the right-hand edge. Watch whether each new point lands above or below the blue curve.
  4. 4Choose dydx=x−y\dfrac{dy}{dx} = x - y and drag the green point to different starting heights. Every exact solution, y=x−1+Ce−xy = x - 1 + Ce^{-x}, approaches the line y=x−1y = x - 1, and the Euler path is drawn towards it too.

Mistakes students make

  • Using the wrong gradient in a step. Euler's method uses f(xn,yn)f(x_n, y_n), the gradient at the point you are leaving, not at the new point and not at the new xx with the old yy.
  • Expecting Euler's method to be exact. Each step follows a tangent, so it tends to fall below a solution that curves upwards (as for dydx=x+y\dfrac{dy}{dx} = x + y from (0,0)(0, 0)) and to overshoot one that curves downwards.
  • Swapping xx and yy when working out a segment. For dydx=x−y\dfrac{dy}{dx} = x - y at the point (2,1)(2, 1) the gradient is 2−1=12 - 1 = 1, not −1-1.

Where it is taught

  • IB Maths AA HL 5.18 · Slope fields and Euler's method
  • AP Calculus AB/BC Unit 7 · Sketching and reasoning with slope fields (7.3, 7.4)
  • AP Calculus BC Unit 7 · Approximating solutions with Euler's method (7.5)

Teaching this?

Put this visualiser on your lesson board with one tap. Your student sees every drag, live, on their own screen — and Owlileo marks the homework, runs the tests and keeps the parents informed.

Start free →