A starting point and a gradient
A differential equation with a starting value at fixes one solution. Often no formula for it can be found: the variables will not separate, or they separate into a relation that cannot be solved for y.
One thing is always known, though. At the starting point the equation gives the gradient, . So the direction in which the solution leaves that point is known, even when the solution is not.
One step along the tangent
Move a short width h along that tangent. The rise is the gradient times the width, so the new point is , .
At the new point, ask the equation for the gradient again and take another step. In general and . Each step uses the gradient at its own start, so the walk keeps turning to follow the field.
Three steps for
Take with y = 1 at x = 0, and h = 0.5. Its exact solution is , which gives something to check against.
At (0, 1) the gradient is 1, so the first step rises 0.5 × 1 = 0.5 and reaches (0.5, 1.5). There the gradient is 1.5, so the second step rises 0.5 × 1.5 = 0.75 and reaches (1, 2.25). There the gradient is 2.25, so the third step rises 1.125 and reaches (1.5, 3.375).
The exact value at x = 1.5 is , so the estimate 3.375 is low by 1.107. At x = 1 the estimate is 2.25 against .
Three Euler steps of width 0.5 for from (0, 1), drawn as gold arrows on the slope field: to (0.5, 1.5), (1, 2.25) and (1.5, 3.375). The gold curve runs above them and reaches the dot at (1.5, 4.482).
Why it lands low here
The curve bends upward, so it lies above each of its tangents. Each step follows a tangent, and also uses the gradient at the start of the step, which is the smallest gradient anywhere on that step. Every step comes up short, and the shortfalls add.
Smaller steps miss by less. At x = 1.5, h = 0.25 (six steps) gives , low by 0.667; h = 0.125 (twelve steps) gives , low by 0.372; h = 0.0625 gives 4.284, low by 0.197. Each halving of h cuts the error to 0.60, then 0.56, then 0.53 of what it was, closing on one half. The error is roughly proportional to h.
y′ = y bends upward, so each tangent step sits under the curve and the walk lands 2.33 low; halving h roughly halves the miss
Shrink the step to h = 0.1 and read the miss
Euler’s method for from (0, 1) to x = 2 in N = 4 steps of h = 0.5. The walk ends at against , a miss of 2.33. Drag the handle at the end of the first step to shrink h: at N = 20 steps of 0.1 the walk ends at 6.727 and the miss is 0.66.
A downward bend lands high
Take with y = 1 at x = 0, whose exact solution is , a curve bending downward. With h = 0.5: at (0, 1) the gradient is 0, so the first step stays level at (0.5, 1); there the gradient is −0.5, giving (1, 0.75); there it is −1, giving (1.5, 0.25).
The exact value at x = 1.5 is 1 − 1.125 = −0.125, so the estimate 0.25 is too high by 0.375. A curve bending downward lies below its tangents, and each step overshoots.
Euler steps of width 0.5 for from (0, 1): to (0.5, 1), (1, 0.75) and (1.5, 0.25). The gold curve bends down below the arrows and reaches the dot at (1.5, −0.125).
An equation that does not separate
cannot be split into a y side and an x side. Start at y = 1 when x = 0, with h = 0.5. At (0, 1) the gradient is 0 + 1 = 1, giving (0.5, 1.5). There it is 0.5 + 1.5 = 2, giving (1, 2.5).
The integrating factor, a later method, solves this equation exactly: , which is at x = 1. The estimate 2.5 is low by 0.937. With h = 0.25 the estimate is 2.883, and with h = 0.1 it is 3.187, low by 0.249.
The usual mistakes
Leaving out the h. takes a step one unit wide whatever h is. With h = 0.5 from (0, 1) for , the first step reaches 1.5, not 2.
Keeping the first gradient for every step. The gradient is worked out again at each new point; for the second step uses 1.5, not 1.
Dropping . The rise is added to the height already reached, not to 0.
Calling the estimate exact. It is low wherever the solution bends upward and high where it bends downward, and halving h only halves the error.
Ammonia in a tank
In the application below, the equation separates into a relation that cannot be rearranged for the concentration, so it is stepped out instead. Halving the step shows which way Euler’s method errs and by how much.
Worked example: An Aeration Tank Whose Bacteria Saturate: A Concentration Stepped Out Where No Formula Can Be Read Off
Question In an aeration tank the bacteria take up ammonia at a rate that levels off while ammonia is plentiful and falls away as it runs short. With c milligrams of ammonia per liter after n hours, dcdn = −6c4 + c, and the tank starts at c = 8. (a) Use Euler's method with four steps of half an hour to estimate the concentration two hours later. (b) Do it again with eight steps of a quarter of an hour, and say which way Euler's method errs here and why.
1.Separating gives ∫4 + ccdc = −∫ 6 dn, that is 4ln c + c = K − 6n. It is a true relation between c and n, but no rearrangement of it gives c on its own, so a value has to be stepped out instead of read off.
Separating gives 4ln c + c = K − 6n, a true relation that cannot be rearranged to give c. 2.Euler's method steps along the slope field: cnext = c + h × f, where f = −6c4 + c is the slope the equation gives at the point reached so far.
The slope field still shows every solution at once, and Euler's method walks along it: cnext = c + h × f. 3.(a) With h = 0.5: at c = 8, f = −4812 = −4, so c → 8 − 2 = 6; at c = 6, f = −3610 = −3.6, so c → 6 − 1.8 = 4.2; at c = 4.2, f = −3.073, so c → 2.663; at c = 2.663, f = −2.398, so c → 1.464. After two hours the estimate is 1.46 milligrams per liter.
(a) Four steps of h = 0.5: 8 → 6 → 4.2 → 2.663 → 1.464, so about 1.46 milligrams per liter. 4.(b) Eight steps of h = 0.25, worked the same way, give 1.667, so the estimate is 1.67 milligrams per liter.
(b) Eight steps of h = 0.25 give 1.667, about 1.67 milligrams per liter. 5.A step small enough for the answer to settle gives 1.852. Euler's method reads low both times, because it holds the slope of the start of each step for the whole of that step, and the slope eases as the ammonia falls: each step takes off more than it should. Halving the step roughly halves the error, from 0.39 to 0.19, which is what a first-order method does.
Each step holds the slope of its own start, and that slope eases as the ammonia falls, so Euler reads low: 1.852 is the settled value. 6.Check: at n = 0 the relation gives K = 4ln 8 + 8 = 16.318, so at n = 2 it asks for 4ln c + c = 16.318 − 12 = 4.318. Putting c = 1.852 in gives 4ln 1.852 + 1.852 = 4.318, so the settled value is right and it is Euler's two estimates that are short.
Check: at n = 2 the relation asks for 4ln c + c = 4.318, and c = 1.852 gives 4ln 1.852 + 1.852 = 4.318.
Answer: (a) about 1.46 milligrams per liter; (b) about 1.67 milligrams per liter, and Euler's method reads low both times, since a step small enough to settle gives 1.852
Common mistakes
- Using the slope at the start for every step. The slope is −4 only while c is 8; by the last step it is nearer −2.4. Holding −4 throughout gives 8 − 4 × 2 = 0 after two hours, which says the tank is clean when it is not.
- Quoting Euler's answer as though it were exact. It is an estimate from a first-order method: halving the step only halves the error, so 1.46 and 1.67 are both short of 1.852, and neither is worth more than two significant figures at these step sizes.