Learning Objectives
By the end of this section you will be able to:
- Read a differential equation as a recipe that hands you one slope at every point in the plane.
- Sketch a direction field by hand using isoclines.
- Trace solution curves through any initial condition without solving the equation symbolically.
- Predict long-term behaviour (equilibria, blow-up, oscillation) just from the picture.
- Connect the geometric idea of "follow the field" to Euler's method and to differentiable solvers used in modern machine learning.
The Big Picture: A Slope at Every Point
"You don't need to solve an equation to see what it does." — the moral of this section.
A first-order differential equation written as is doing something almost mechanical: pick any point in the plane, evaluate there, and the equation hands you back one number — the slope of the solution curve that happens to pass through that point. Do this everywhere, sketch each slope as a tiny tangent segment, and you have built a direction field (also called a slope field).
The pay-off is enormous. Before you do any algebra at all you can see what every solution must look like: where curves grow, where they decay, where they curl into closed loops, where two neighbours diverge, and where they all converge. Whole textbooks could be written on solving differential equations and missing this, the first thing you should always do.
The shift in mindset
A differential equation is not a problem to solve — at least, not first. It is a field of slopes, painted across the plane. Solution curves are the threads that, at every point, are tangent to the local slope. Section 20.1 told you what an ODE is. Section 20.2 teaches you how to read one.
One Point at a Time: the Slope Microscope
Before we paint the whole plane, drag a single yellow dot. The equation evaluates at the dot and draws the resulting slope as a tiny tangent. Toggle Show whole field once you have the idea — the picture you have been building one point at a time fills in at once.
Definition of a Direction Field
Three subtleties make this definition richer than it looks:
- The segments are direction-less: a slope of draws the same picture as one of … wait, that is wrong. They have the same magnitude, but different signs. A slope is a rise-over-run, so the segment tilts up to the right when and down to the right when . The arrow tip is conventionally omitted — you should be able to walk the curve in either direction.
- If is unbounded (say near ) we draw vertical hash-marks or simply leave the region blank — the slope is "infinite", meaning solutions cross that horizontal line vertically.
- The direction field exists for every first-order ODE in the form — even ones with no closed-form solution. That is exactly why it is so useful.
Isoclines: How to Draw the Field by Hand
Painting a slope at every grid point one-by-one is tedious. The trick that working mathematicians have used since the nineteenth century is the isocline:
Isocline of slope c
For the equation , the curve is called the isocline of slope . Every point on this curve has the same slope, namely . So a hand sketch reduces to three steps:
- Pick a handful of slope values .
- Draw each isocline (often just a line or a simple curve).
- Along each isocline, draw parallel tick marks at slope . That is the field.
Drag the slider below. Notice that for , the isocline is a 45° line — so the ticks along it are all parallel with the same fixed slope . Click Pin this isocline a few times and the entire field crystallises out of the pinned scaffolding.
Solution Curves: Following the Arrows
A solution curve of through the point is a differentiable function such that
Geometrically: at every point on the curve, the tangent line agrees with the direction-field segment at that point. Mathematically you could say the curve is everywhere tangent to the field. Visually, it is the path a tiny ball would follow if you placed it down and let the arrows push it sideways.
Because the equation only fixes the slope at each point — not the height — through every starting point there is a different solution curve. The initial condition is the choice that pins down which curve.
Interactive Playground
Click anywhere on the canvas to drop an initial condition. The playground integrates forward and backward and draws the solution curve that exactly follows the local slope field. Cycle through the equation presets and notice how each one organises the plane differently: produces a fan of exponentials, produces sigmoid curves saturating between two equilibria, and produces parabolas.
Worked Example: Sketch dy/dx = x − y by Hand
We will sketch over the window and use isoclines to nail it down. Try the steps on paper first; expand the panel below to check.
Show the full hand-worked construction
Pick . Five lines is plenty for a hand sketch.
Each isocline is a 45° line, shifted up by .
| slope c | isocline equation | y-intercept |
|---|---|---|
| −2 | y = x + 2 | (0, 2) |
| −1 | y = x + 1 | (0, 1) |
| 0 | y = x | (0, 0) |
| 1 | y = x − 1 | (0, −1) |
| 2 | y = x − 2 | (0, −2) |
On the line , draw small horizontal ticks (slope 0). On , draw ticks at slope 1 (parallel to itself!). On , draw steeper ticks at slope 2. Mirror across for the negative slopes.
On the slope is , which is exactly the slope of the isocline itself. So is tangent to its own isocline everywhere — it is a solution. Indeed plug in: if then and
- Above the line , slopes are smaller than the line itself, so curves drift down toward it.
- Below the line, slopes are larger, so curves rise toward it.
- In both cases, curves approach asymptotically as . That special solution is an attractor.
The equation is linear and (we will solve in 21.1) has general solution
For any , the term decays to 0 as , leaving . That is exactly the behaviour the sketch predicted — without solving anything!
Now turn back to the Isocline Explorer above, set the equation to , pin , and verify the sketch you just made matches the rendered field.
From Picture to Number: Euler's Method
"Follow the arrows" is a beautiful instruction for the eye but useless for a computer. To turn the field into actual coordinates we discretise time. Stand at , read off the local slope , and step forward by a small amount along that slope:
This is Euler's method, the simplest possible numerical ODE solver. Geometrically you are walking along the field but pretending the slope is constant between samples — a piecewise linear approximation to the smooth true curve.
Drag the step size in the tracer below. With the orange staircase hugs the green "true" curve. Push it up to and the staircase peels away — each step over-shoots a slope it cannot see is curving. This is the single most important picture in numerical analysis.
Reading a Solution Off the Field Without Solving
Once you have a sketch you can answer most qualitative questions immediately. For (logistic), inspecting the field tells you:
| Question | Answer from the field | Why |
|---|---|---|
| Equilibria? | y = 0 and y = 1 | Both make f(x, y) = 0 — horizontal ticks everywhere along these lines. |
| Long-term y if y(0) = 0.1? | y → 1 | All ticks between 0 and 1 point upward; the curve is funnelled into y = 1. |
| Long-term y if y(0) = -0.1? | y → -∞ | Below y = 0 the slope y(1 - y) is negative; the curve runs away downward. |
| Is y = 0 stable? | No (repelling) | Slightly perturb y and ticks push you AWAY from 0. |
| Is y = 1 stable? | Yes (attracting) | Slightly perturb y and ticks push you BACK toward 1. |
Not one of these answers required solving the equation. That is the super-power direction fields give you — qualitative analysis comes free with a sketch.
Python Implementation
Here is the code that produces a publication-grade direction field sketch. It uses so you can cross-check it against the worked example, but the equation is one line — swap it for anything you like.
Three habits to internalise from this code: (1) the equation lives in a single function , (2) the field is plotted before any solutions, and (3) numerical solutions are drawn on top of the field, never instead of it. Always lay down the scaffolding first — the field reveals what to expect; the solver confirms it.
PyTorch: Differentiable ODEs
Once an ODE solver is written in PyTorch tensor ops, the entire trajectory becomes differentiable with respect to anything inside — including the initial condition. This is the key idea behind Neural ODEs: treat a deep network as a continuous-time flow and learn its right-hand side. Here is the smallest non-toy example: a hand-written RK4 integrator that lets autograd propagate gradients through it.
torchdiffeq, which uses the adjoint method to backpropagate in O(1) memory regardless of the number of steps. But the picture is exactly the one above: every slope evaluation is a node in the computational graph, and the gradient flows back along it.Real-World Applications
| Domain | Equation | What the field shows you |
|---|---|---|
| Newton's law of cooling | dT/dt = -k(T - Tₐ) | Horizontal ticks at T = Tₐ — the ambient temperature is the asymptote of every cooling curve, no matter where you start. |
| Logistic population | dP/dt = rP(1 - P/K) | Two equilibria (P = 0 and P = K). The field reveals carrying capacity without any algebra. |
| RC charging circuit | dV/dt = (Vs - V)/(RC) | All curves are funnelled to the source voltage Vs — the charge time is read off the slope at the start. |
| Free-falling object (with drag) | dv/dt = g - kv | Horizontal ticks where v = g/k — that is terminal velocity. Both 0-start and high-speed-start curves approach it. |
| Tumour growth (Gompertz) | dN/dt = αN ln(K/N) | Field saturates as N → K. The inflection point of any solution lies on the isocline of maximum slope. |
Machine Learning Connection
Direction fields are not just classical. Three modern uses keep them relevant:
1. Gradient flow as a direction field
Stochastic gradient descent is a discretised ODE: . Plotting as a direction field on the loss surface lets you see the optimisation trajectory before you ever run a step. Saddle points, basins, and ridges all show up as features of the field.
2. Neural ODEs and continuous normalising flows
A Neural ODE replaces a discrete stack of residual blocks with a continuous-time flow whose right-hand side is a neural net. Training it is exactly the differentiable-integrator picture above — backprop through the entire trajectory.
3. Diffusion models as score fields
A diffusion model learns the score . The sampler then walks a reverse-time SDE whose drift is the score — again a direction field, this time across the data manifold.
Test Your Understanding
1. For dy/dx = y − x, where are the slopes zero?
2. Two solution curves through the same point — when can that happen?
3. Euler's method with h = 0.5 gives y₃ for y' = y, y(0) = 1?
Step by step:
The true value is . Euler with is already 25% low — a vivid demonstration of why step size matters.
4. Why does the picture of dy/dx = y(1 − y) have two distinct horizontal lines?
5. Sketching trick: the equation is dy/dx = x². What do the isoclines look like?
Summary
The whole section in one sentence: a differential equation paints a field of slopes, and solution curves are the threads everywhere tangent to it.
| Idea | What you should be able to do |
|---|---|
| Direction field | Draw a small tangent at each grid point with slope f(x, y). |
| Isocline | Recognise that f(x, y) = c is a curve of constant slope c, and use it to sketch the field by hand. |
| Solution curve | Trace a curve that is tangent to the field at every point — pinned down by an initial condition. |
| Equilibrium | Read off solutions of f(x, y) = 0 directly from the picture. |
| Stability | Use the field around an equilibrium to tell whether it attracts or repels nearby solutions. |
| Euler's method | Turn 'follow the field' into a numerical recipe yₙ₊₁ = yₙ + h·f(xₙ, yₙ). |
| Differentiable solvers | Implement the recipe in PyTorch so gradients flow back through the entire trajectory. |