Most differential equations are solved numerically. Euler's method follows the direction field in straight steps: from (xₙ, yₙ) go a step h along the line element of slope Aₙ = f(xₙ, yₙ), so xₙ₊₁ = xₙ + h and yₙ₊₁ = yₙ + hAₙ. Done by hand, keep a table. Where the solution curve is convex Euler's answer is too low, where concave too high, and y″ can be found from the equation itself without solving it. The error is roughly proportional to h: Euler is a first-order method, so halving the step halves the error. Heun's method (improved Euler, RK2) averages the slope at the start and at the Euler endpoint; its error goes as h². The standard Runge–Kutta method RK4 uses four slopes and has error ∝ h⁴. A pitfall: solutions can blow up at places the equation does not reveal, as y′ = y² shows.
In real life most differential equations are solved numerically: even the solution curves a computer draws are computed point by point (transcript, p. 1). This lecture introduces the basic method, Euler's, of which the others are refinements.
At (x0,y0) the only information is the line element of the direction field there, so start off in that direction, go a horizontal steph, recompute the slope, and repeat. The result is a broken-line approximation to the solution (pp. 1–2). (Euler himself used the idea to prove that solutions exist, not to compute them, p. 1.)
From (xn,yn), the line element has slope An=f(xn,yn); over a run of h it rises by hAn (pp. 2–3):
Euler's method
xn+1=xn+h,yn+1=yn+hAn,An=f(xn,yn)
In words
x sub n plus 1 equals x sub n plus h, y sub n plus 1 equals y sub n plus h A sub n, A sub n equals f( x sub n, y sub n )
Example.y′=x2−y2, y(0)=1, which cannot be solved with elementary functions, with h=0.1 (pp. 4–6). Be systematic and keep a table with columns n, xn, yn, An, hAn (p. 5):
If the solution were a straight line, Euler would be exact. A convex solution curve bends up away from the tangent line Euler follows, so Euler falls too low, and keeps losing ground; a concave curve makes Euler too high (transcript, pp. 7–8). Convex means y′′>0, concavey′′<0, and y′′ can be found from the differential equation itself, without solving it (pp. 8–9). For the example, differentiating with the chain rule (p. 9):
Second derivative from the equation
y′′=2x−2yy′,y′′(0)=2(0)−2(1)(−1)=2
In words
y double prime equals 2 x minus 2 y y prime, y double prime (0) equals 2(0) minus 2(1)(-1) equals 2
So the solution is convex at the start, and the Euler value 0.82 is too low (pp. 9–10). If the curve changes from convex to concave along the way, no prediction can be made (p. 10).
The errore is the difference between the true value and Euler's. Smaller steps follow the curve better, bigger ones worse (transcript, pp. 10–11). Roughly, for small h (pp. 11–12):
for some constant c: Euler's method is a first-order method. Halve the step size and you halve the error (p. 12). ("First order" refers to the power of h, not the order of the equation.) Halving again and again until the answer stops changing works, but slowly (p. 13).
Euler's slope An is systematically wrong when the curve bends. Improve it (transcript, pp. 13–15): take the Euler step to a temporary point y~n+1, find the slope Bn there, and use the average of An and Bn for the real step:
y sub n plus 1 tilde equals y sub n plus h A sub n, B sub n equals f( x sub n plus 1, y sub n plus 1 tilde ), y sub n plus 1 equals y sub n plus h the quantity A sub n plus B sub n, all over 2
This is Heun's method, also called improved Euler, modified Euler, or RK2 (Runge–Kutta second order) (p. 16). It is a second-order method: e≈ch2, so halving the step quarters the error (p. 16).
What costs time is evaluating f, which in practice can be a long formula: Euler evaluates it once per step, Heun twice (p. 16). The standard method, RK4 (Runge–Kutta fourth order), evaluates four slopes and combines them in a weighted average, divided by 6, the sum of the weights; its error goes as h4, and it is what draws the solution curves in the course's computer visuals (pp. 17–18). Mattuck adds that higher order is not free, since more slopes per step means more work (p. 17). (He then says it hardly matters which method is used, comparing RK4 with halving Euler's step four times; but four halvings multiply Euler's work by 16, not 4, so for the same accuracyRK4 is far cheaper.)
Loading graph…
y′=y, y(0)=1, computed with two steps of h=0.5: Euler's broken line (slopes 1 and 1.5) falls well below the exact solution ex, which is convex; Heun's averaged slopes land much closer (2.64 against e≈2.72 at x=1).
y′=y2 looks harmless, and separation of variables gives the solutions y=1/(c−x) (transcript, p. 18). Starting from y(0)=1, the solution 1/(1−x) shoots off to infinity at x=1. Asked for y(2), a numerical method follows the curve up towards infinity and never finds the other branch (pp. 18–19). Each solution has its own singularity, at x=c, and nothing in the equation predicts where: one of the things that makes numerical work hard (p. 19). (Separation of variables also misses the solution y=0. A first pitfall was left for the problem set, p. 18.)
Worked example
Euler and Heun on y′ = y
For y′=y, y(0)=1, estimate y(1) (exactly e≈2.718): (a) by Euler with h=0.5 and h=0.25; (b) by Heun with h=0.5. Compare the errors.
(a) Euler
With h=0.5 each step multiplies y by 1+h=1.5: y(1)≈1.52=2.25, error 0.47. With h=0.25: 1.254≈2.441, error 0.28. Halving h cut the errorby a factor of about 1.7; for smaller h the factor approaches 2. Both are too low, as expected for a convex solution.
(b) Heun
An=yn, y~n+1=yn(1+h), Bn=yn(1+h), so each step multiplies y by 1+h+h2/2=1.625. Two steps: 1.6252≈2.641, error 0.08, already better than Euler with twice as many steps.
An average in which some values count more: each is multiplied by its weight, and the total divided by the sum of the weights. Explained in Centre of mass and its motion.
A way to solve a differential equation by putting everything with one variable on one side, the rest on the other, and integrating both sides. Explained in The rocket equation.
In maths, to grow without limit; to become infinite.
Tap or click a word, here or in the text, for its meaning in this lesson. All words: the glossary. How many words are marked in the text: Reading options (the “Aa” button).