Slope Fields and Euler's Method
Read a slope field to sketch solutions without formulas, then approximate solutions numerically with Euler's method and see how step size controls error.
Welcome back!
Step 1 of 12Learn
Seeing solutions without solving
Most differential equations, especially nonlinear ones, can't be solved with a formula. But a first-order equation dy/dt = f(t, y) tells you something useful at every point: the slope a solution must have if it passes through that point.
Draw a short line segment with that slope at each point of a grid, and you get a slope field (or direction field). Solution curves must be tangent to the segments everywhere, so you can sketch them by following the flow, like tracing the path of a leaf on a stream.
Take dy/dt = t − y.
- Along the line y = t, the slope is 0, so segments are flat there.
- Above that line (y > t), slopes are negative: solutions fall.
- Below it, slopes are positive: solutions rise.
- Along y = t − 1, the slope is t − (t − 1) = 1, which matches the slope of the line itself. So y = t − 1 is an exact solution.
Every other solution approaches y = t − 1 as t grows. Indeed, the general solution is y = t − 1 + Ce^(−t), and the exponential term dies away.
Slope fields let you answer qualitative questions quickly: Do solutions grow, decay or level off? Do they approach a particular curve? Can two solutions cross? (For well-behaved f, no: at a crossing point there would be two different futures from the same state.)
Step 2 of 12Practice · Choose one
In the slope field of dy/dt = y − t, what is the slope of the segment at the point (t, y) = (2, 5)?
Step 3 of 12Learn
Euler's method
If you can follow a slope field by eye, a computer can follow it by arithmetic. Euler's method is the simplest way, and the idea behind almost every numerical solver.
Start at the initial point (t₀, y₀). Compute the slope there, f(t₀, y₀). Walk a short step h along that straight line:
y_(n+1) = y_n + h·f(t_n, y_n), t_(n+1) = t_n + h
Repeat from the new point.
Example. Approximate y(1) for y′ = y, y(0) = 1, using h = 0.5.
| n | t | y | slope f = y | next y |
|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 1 + 0.5(1) = 1.5 |
| 1 | 0.5 | 1.5 | 1.5 | 1.5 + 0.5(1.5) = 2.25 |
| 2 | 1.0 | 2.25 |
The exact answer is e ≈ 2.718, so the estimate 2.25 is off by about 0.47. With h = 0.1 (ten steps), Euler gives 1.110 ≈ 2.594, off by about 0.12.
Why the error? Each step follows the tangent line, but the true solution curves away. Here the solution is concave up, so tangent lines lie below it and Euler underestimates at every step.
Step 4 of 12Try the calculator
Euler versus exact for y′ = y
For y′ = y, y(0) = 1, Euler's method with n equal steps on [0, 1] gives exactly (1 + 1/n)n. Increase n and watch the error shrink.
- Step size h
- 0.5
- Euler estimate of y(1)
- 2.25
- Exact value e
- 2.718282
- Error
- 0.468282
- Error × n (roughly constant)
- 0.9366
Step 5 of 12Practice · Work it out
Use Euler's method with h = 0.1 for y′ = t + y, y(0) = 1. What is the approximation of y(0.2)? Give your answer to three decimal places.
Step 6 of 12Practice · Chart
Euler (h = 0.25) vs the exact solution of y′ = y
Euler follows the slope at the start of each step. Because et curves upward, each step falls a little short and the errors pile up.
Tap the point where Euler's error is largest.
Tap the point that answers the question, then press Check.
| Item | Exact e^t | Euler, h = 0.25 |
|---|---|---|
| t = 0 | 1 | 1 |
| 0.25 | 1.28 | 1.25 |
| 0.5 | 1.65 | 1.56 |
| 0.75 | 2.12 | 1.95 |
| 1 | 2.72 | 2.44 |
Step 7 of 12Learn
Step size, error and better methods
The calculator shows a key fact: for Euler's method, halving the step size roughly halves the error. The error is proportional to h, so Euler is called a first-order method. That's slow. To get one more correct digit you need ten times as many steps.
Two kinds of error combine:
- Local truncation error is the mistake made in a single step by following the tangent instead of the curve. For Euler it's proportional to h2.
- Global error is what accumulates over all the steps to a fixed endpoint. With about 1/h steps, each contributing about h2, the total is about h.
Better methods sample the slope at several points within each step and average them cleverly.
- Improved Euler (Heun's method) takes a trial Euler step, computes the slope at the end, and uses the average of the two slopes. Its error is proportional to h2.
- Classical Runge-Kutta (RK4) combines four slope samples per step. Its error is proportional to h4: halving h cuts the error by a factor of 16. It's the workhorse of scientific computing.
Modern solvers also adapt the step size, taking big steps where the solution is smooth and small steps where it changes quickly.
Common mistake: trusting a numerical solution without checking it. Run it again with half the step size. If the answer barely changes, it's probably reliable. If it changes a lot, the step was too large.
Step 8 of 12Note
Step 9 of 12Practice · Put in order
Order these numerical methods from least accurate to most accurate for the same small step size h.
Drag the items, or use the arrow buttons, to put them in order.
- Improved Euler (error proportional to h2)
- Classical Runge-Kutta, RK4 (error proportional to h4)
- Euler's method (error proportional to h)
Step 10 of 12Diagram
Error at t = 1 for y′ = y with h = 0.1
Same equation, same step size, three methods. The scale is logarithmic: each tick is ten times smaller.
Tap a shape with to see more.
- Euler: 0.12
10 steps of y_(n+1) = 1.1·y_n give 2.5937 instead of e ≈ 2.7183.
- Improved Euler: 0.004
Averaging two slopes per step cuts the error about 30-fold.
- RK4: 0.000002
Four slope samples per step: the error is about 60,000 times smaller than Euler's.
Step 11 of 12Note
Step 12 of 12Practice · Select all that apply
Euler's method is applied to y′ = y on [0, 1] with step size h = 0.2. Which statements are true?
Select all that apply.
Lesson complete!