You have written Euler’s method, three variants of it, RK4 and RK45. This lesson meets you on that ground, and it adds two things your code never told you. The first is a picture: the right-hand side of draws an arrow at every point of the plane, and every solution is a curve that follows those arrows. The second is the theory of the error: why Euler is first order, and the two situations where it fails outright. Last lesson (3.1 What Is a Differential Equation?) ended with Euler on from producing finite numbers long after the true solution blew up at . We now explain that, and we keep the module’s habit of setting the exact solution next to the numerical one.
Transcript
- Last lesson, Euler sailed past a blow-up. To see why, start with a picture of the equation itself.
- Take y prime equals t minus y. At every point the right-hand side gives a slope, so draw a short tick with that slope. At zero, one it is minus one. At two, zero, plus two. At one, one, flat. Fill a grid and you have a direction field, with nothing solved.
- To draw it fast, use isoclines: curves where the slope is constant. Here slope m lives on the line y equals t minus m, so every tick along one line is parallel. On the line y equals t the slope is zero, and every tick is flat.
- A solution is a curve tangent to every tick it passes. Drop a seed at zero, one and follow the ticks. It heads down, flattens as it meets the line y equals t, turns, and climbs. Other seeds give other curves, and none cross, since a crossing needs two slopes at one point.
- Now Euler, as geometry. Follow the arrow for a time h, then stop and re-aim. With h a half, we land at a half, a half, then follow a flat arrow to one, a half. The true curve has bent away: at t equals one, we are off by 0.236.
- Shrink h. A quarter, an eighth, a sixteenth. The polygon hugs the true curve, and the miss at t equals one falls: 0.103, 0.049, 0.024.
- Keep halving h, and each error is about half the last. The ratios are 2.29, 2.12, 2.06, 2.03, heading for two. Halve the step, halve the error. That is a first order method.
- Why? A step follows the tangent, and the curve bends, so each step misses by about h squared. Reaching t equals one takes one over h steps. One over h misses of size h squared add up to size h: one power is lost to counting.
- Now the first failure. The true solution of y prime equals minus ten y decays smoothly. Euler multiplies by one minus ten h each step. At h of 0.05 the factor is a half, and it decays as it should. At 0.15 it is minus a half: still decaying, but flipping sign.
- At h of 0.25 the factor is minus one and a half. We get one, minus one point five, two point two five, minus three point three seven five, five point oh six. The exact answer dies away to zero. Euler flips sign and grows.
- The reason is overshoot. The arrow points at zero, but a step along it has length ten h times the size of y, while zero is only the size of y away. Once ten h passes two, the step is more than twice the distance, so every landing is farther out. Euler is stable only below h of 0.2.
- The second failure. y prime equals y squared from one half has an exact solution that blows up at t equals two. Euler with h of a half sails past: at t equals two it reports 1.83. Nothing in the algorithm can notice. Each step just adds a finite amount.
- It does explode, but late: 3.5, 9.6, 56, 1600. Shrink h, and the numerical blow-up creeps toward the truth. Euler first passes a million at t equals 4.5, 2.7, 2.09, 2.011. Finite output is not proof that a solution exists.
- The fluids link: a particle in a steady velocity field obeys x dot equals u of x. The field is the arrow, the path is the solution, and an Euler step follows the arrow for time h. Here arrow length is speed, and the step lands just outside the true circle.
- So: a direction field is the equation drawn as arrows, solutions are curves tangent to them, and Euler walks them in steps. Its error is first order, and it fails by overshooting, and by sailing past blow-ups. Next, we start solving exactly, with separable equations.
From a rule to a picture of every solution
The equation says: if you are at the point , your slope is . Evaluate on a grid and draw a short tick with that slope at each grid point. The result is the direction field (or slope field). It is built without solving anything, only by evaluating .
Take . At the slope is ; at it is ; at it is . A solution is a curve that is tangent to the tick at every point it passes through. Through every point of the plane there is a tick, so a curve starts at every point: the field is the whole family of solutions drawn at once, which is the family picture of the last lesson without any formula. For a well-behaved two curves cannot cross, because at a crossing the tick would need two slopes.
The exact solutions of are (check: ). Open the sim below and compare the curves you seed with the ticks they follow.
A direction field records only the direction at each point, not a speed. For a pure slope field that is enough, because is the independent variable and moves at unit speed to the right. Keep this in mind for the fluids connection at the end of the lesson, where the length of the arrow matters.
Isoclines, and sketching a solution by eye
An isocline is a curve along which the slope is constant: . Every tick on it is parallel, so isoclines make the field quick to draw. For the isocline of slope is the line . For it is the pair of horizontal lines .
The isocline for is special: along it the solutions have horizontal tangents, so any solution crossing it is at a local maximum or minimum. For that is the line . Above it and below it , so a solution coming from above descends, meets the line, and then climbs: a minimum. The isocline , the line , has slope itself, which matches the ticks along it, so it is also a solution (it is above).
Here is the by-eye recipe, and you should try it on the sim with the field and isoclines switched on:
- Start at the initial point and move along the tick there.
- At each isocline you cross, your slope must be that isocline’s .
- Cross the isocline horizontally. Where the sign of changes from minus to plus you have a minimum, and from plus to minus a maximum.
- Never cross another solution, and bend gradually: your slope changes continuously from one isocline to the next.
Worked sketch. Start at in . The slope there is , so the curve heads down and to the right, flattening as it nears the line . It meets that line horizontally, at its minimum, and then turns upward. The exact solution confirms this: requires , so the minimum is at with . After that, the term fades and the curve settles onto the straight-line solution from above and never crosses it.
Euler’s method: follow the arrow for time h
At the field gives the slope . Move along that tick for a horizontal distance :
That is the whole algorithm, and you coded it. The geometric reading is the tangent line: the first-order Taylor polynomial of the true solution at . The numerical solution is a polygon, a chain of straight segments. Each segment follows the arrow at its start, but a real solution bends, so the arrow at the end of the segment has changed and the polygon drifts off the true curve. In the sim, raise and watch the polygon corners miss the exact curve. Where solutions curve upward, Euler lands below the curve (its tangent lies under a convex function); where they curve downward it lands above.
Worked example. Solve , , on with . The exact solution is , so .
- Step 1: slope at is , so at .
- Step 2: slope at is , so at .
Euler gives against the exact , an error of . With the same hand computation gives , error . Halving cut the error by a factor ; we will see why it tends to .
Why the global error is first order
Taylor’s theorem for the exact solution gives, with ,
Euler keeps the first two terms, so a single step started on the exact curve misses by the third: the local truncation error is about , which is . In the worked example, at , so the estimate is ; the true one-step miss at is . The estimate is slightly high because shrinks across the step.
To reach you need steps. If every step added an error of size and nothing amplified or removed it, the total would be . That is the whole argument for global error : one power of is lost when you add up steps. The equation also reshapes each step’s error as it is carried forward (damped when solutions converge, amplified when they spread), which changes the constant in front of but not the power.
For you can see the constant exactly. Euler gives . With ,
so the relative error is about . It is proportional to , as claimed. Check it: for , , , Euler gives against , a relative error of , and the formula says .
Read the output: the ratio column heads toward (, , , as halves) and the error / h column settles near . That constant is the price of first order.
Where Euler goes wrong
The error analysis above assumed two things: that the true solution exists and is well behaved on the whole interval, and that is small enough for the error to behave as a small perturbation. Each of those fails in an instructive example.
Too large a step: y’ = −10y
The exact solution of , is : positive and decaying monotonically. Euler gives
The factor decides everything:
| factor | what Euler does | |
|---|---|---|
| decays smoothly | ||
| jumps to in one step | ||
| decays, but alternates in sign | ||
| oscillates forever at constant size | ||
| alternates and grows: |
The mechanism is overshoot. The arrow at is steep and points at zero. For it stops short of zero. At it lands exactly on zero. Beyond that Euler walks past the equilibrium, to the other side, where the arrow now points back. A step has length and the equilibrium is away, so once the step is more than twice the distance, and each landing is farther from zero than the last. So Euler is stable for and sign-faithful only for . For general the limit is .
This is a failure of stability, not of accuracy: it is not a matter of the error constant being large. The limit is set by the fastest decay rate in the problem, even when you only care about slow behaviour. This is the first appearance of stiffness, treated in 4.5 Stability Regions & Stiffness.
The solution itself ends: y’ = y²
The exact solution of from is , which tends to infinity at . Euler with gives
| 0 | 0.5 | 1.0 | 1.5 | 2.0 | 2.5 | 3.0 | 3.5 | 4.0 | |
|---|---|---|---|---|---|---|---|---|---|
| Euler | 0.5 | 0.625 | 0.820 | 1.157 | 1.826 | 3.493 | 9.592 | 55.59 | 1601 |
At the exact solution does not exist and Euler reports . Nothing in the algorithm can notice: each step evaluates at one finite point and adds a finite amount. Euler does not solve “the ODE on an interval”; it iterates a map, and the map is perfectly defined for every finite . It does not stay finite forever: the next values explode, passing at and at . But that is a blow-up at to , not at .
Refining moves the numerical blow-up toward the truth. The step at which first exceeds occurs at for , for , for and for . This does not contradict the first-order theory: convergence is a statement about intervals with , where the exact solution is bounded. The error constant (the size of and the growth of errors) grows without limit as .
Exercise: measure the order of convergence
Implement Euler for a scalar ODE and measure the error at for on the IVP , , whose exact value is . If your implementation is first order, the error ratio between consecutive step sizes will be close to , and the slope of against will be close to .
For : (a) find the isocline of slope ; (b) show that the isocline is itself a solution; (c) find where solutions have horizontal tangents, and decide whether each is a minimum or a maximum.
Show worked solution
(a) gives the line .
(b) For the line is , with slope . The slope of the field along it is . The two agree at every point, so it is a solution. (Equivalently, is the general solution, and .)
(c) Horizontal tangents occur on : the line . Differentiating gives , which equals where . So every such point is a minimum.
Apply Euler to , , to estimate . Use and then . Compute both errors and their ratio, and say why the ratio is not exactly .
Show worked solution
With : , , error .
With : each step multiplies by , so , error .
The ratio is . The error is , and the term is still noticeable at . The ratio tends to as , as in the table above.
Euler is applied to , . (a) Find the range of for which Euler is stable. (b) Find the range for which the numerical solution has the same sign at every step, as the exact one does. (c) For , find the size of . (d) Explain, in terms of the arrow, why the solution grows.
Show worked solution
Euler gives .
(a) Stability needs , which gives .
(b) Same sign needs , so . At the factor is and already.
(c) , so . The exact value at is .
(d) The arrow at points at zero with slope . Following it for moves a distance of , which is more than twice the distance to the equilibrium, so Euler lands on the other side at times the distance it started from. Each step repeats this.
Where this goes next
Euler’s method is the geometry of the direction field turned into an algorithm, and its first-order error is the accumulation of steps that each miss by . In 3.3 Separable Equations we stop sketching and start solving: for many equations the curves in the field can be written down exactly. 3.7 Existence & Uniqueness returns to the one thing the field makes visible and we have only assumed, that exactly one curve passes through each point and exists up to a stated time (the case shows why that needs care). The question of how step size, order and stability interact is taken up fully in 4.1 Local Error, Global Error & Order and 4.5 Stability Regions & Stiffness.
Key Takeaways
- A direction field draws the slope at every grid point; solutions are exactly the curves tangent to it, and distinct solutions never cross.
- Isoclines organize the drawing. The isocline marks the horizontal tangents, where solutions have maxima and minima.
- Euler’s method follows the arrow at the start of a step for time : . The numerical solution is a polygon of tangent segments.
- The local error is , ; summing steps gives a global error . Halving halves the error (for at , the error was about ).
- For Euler multiplies by each step. It is stable only for and sign-faithful only for : a stability limit, set by the fastest rate in the problem, and independent of accuracy.
- For Euler produces finite numbers past the true blow-up at , because it iterates a map and never checks that a solution exists. Convergence only holds on intervals where the exact solution is bounded.
- Advecting a particle through a velocity field is the same computation: field, path and Euler step.