Calculus · Slope field

Slope field

A slope field draws, at each point of the plane, a short segment with the slope y′ = f(x, y) that a differential equation prescribes there; every solution is a curve that follows those segments. Drag the starting point and watch the whole solution move, then let Euler’s method step along the slopes.

01

Slope fields in this visualization

A first-order differential equation y′=f(x,y)y' = f(x, y) prescribes a slope at every point of the plane. Its slope field (also called a direction field) draws that slope as a short segment at each point of a lattice. A solution is a differentiable function y(x)y(x) whose graph is tangent to the segments everywhere; an initial-value problem asks for the one through a given point P=(x0,y0)P = (x_0, y_0). When f is continuous and locally Lipschitz in y, exactly one solution passes through each point, on some interval of x — so the slopes alone determine every solution.

Drag P and the whole curve through it moves continuously (on any closed interval where the solution exists). For the eight preset equations the curves are closed-form solutions; for an equation you type they are computed numerically with an adaptive Runge–Kutta method (Dormand–Prince 5(4), relative tolerance 10−810^{-8}). If y′ depends on x only, solutions differ by a constant: +C+C is a vertical shift. If it depends on y only, the zeros of f are horizontal equilibrium solutions, and the solutions lying between two neighbouring equilibria are horizontal shifts of each other.

Euler’s method, step h
yk+1=yk+h f(xk,yk),xk+1=xk+hy_{k+1} = y_k + h\, f(x_k, y_k), \qquad x_{k+1} = x_k + h

Euler’s method follows the slope read at the current point for one step of length h, then reads again. Here it runs from P to the end X (its last step shortened to land on X). For a smooth solution its error at X is roughly proportional to h: the red key halves h level by level, and each halving roughly halves the error, so the ratio of successive errors tends to 2.

02

Things to notice

  • The segments have equal length and no arrowheads: only their slope means something. A slope field is the vector field (1,f)(1, f) with every arrow’s length thrown away.
  • A solution need not exist for every x. For y′=y2y' = y^2 the solution through (0, 1) is 1/(1−x)1/(1-x), which grows without bound as x approaches 1; the page stops it at the dashed line and never joins it to the other branch. For y′=−x/yy' = -x/y the solution through (0, 2) is a half circle that ends where its slope turns vertical. Euler still returns a number past such a point; the solution’s value is then marked as not existing.
  • Without the Lipschitz condition a solution need not be unique: y=0y = 0 and y=x3y = x^3 both solve y′=3y2/3y' = 3y^{2/3} through (0, 0), and so does any curve that rests on y = 0 for a while and then leaves. Euler’s method from (0, 0) stays at 0 at every step size.
  • Isoclines are the curves where the slope is constant, f(x,y)=cf(x, y) = c; along each one the segments are parallel, which is how slope fields are sketched by hand. With h = π/n, Euler on y′=cos⁡xy' = \cos x from (0, 0) to π returns exactly h.
03

Controls

  • Click empty space to add another solution (up to six); the one you touched last is P, the one Euler starts from. With Pan on, dragging moves the picture instead.
  • Drag the ▲ on the x axis, or turn its wheel, to move Euler’s end X. The red key starts from the current h; at the end it starts again from h = 1. The Approach record window collects each level’s value, error and ratio, even while it is closed.
04

Related

Euler’s method on y′=yy' = y from (0, 1) to 1 gives (1+h)1/h(1 + h)^{1/h}, the compound-interest factor. A system of two equations is drawn as a phase portrait.

Further reading: Wikipedia: Slope field; OpenStax, Calculus Volume 2, 4.2 Direction Fields and Numerical Methods.