7.2 Direction Fields and Euler's Method
Read a differential equation as a map of slopes, find its equilibria and their stability, and follow the slopes step by step with Euler's method.
In Section 7.1 every equation we met could be solved with a formula. Most differential equations cannot. There is no elementary function solving $y^\prime=x^2+y^2$, and the equations used for weather, epidemics or a spacecraft's path are far harder still. Yet a first-order equation $y^\prime=f(x,y)$ always tells us one thing for free: the slope of the solution curve through any point $(x,y)$. That is enough information to draw the solutions, to predict their long-term behaviour, and to compute them numerically.
This section develops three tools built on that single observation: the direction field (a picture of all the slopes at once), equilibrium solutions and their stability (where the slopes are zero, and whether nearby solutions are drawn in or pushed away), and Euler's method (walking along the slopes in small steps) โ the ancestor of every numerical solver used in science and engineering today.
Direction Fields
At each point $(x,y)$ the equation $y^\prime=f(x,y)$ gives a number โ the slope that a solution passing through that point must have there. Draw a short line segment with that slope at each point of a grid and the plane fills with little arrows showing which way solutions flow.
A solution curve is tangent to the field at every one of its points. A curve along which $f(x,y)$ is constant, $f(x,y)=c$, is called an isocline: all the segments on it are parallel.
- Find a few isoclines $f(x,y)=c$, especially $c=0$ (horizontal segments). Draw segments of slope $c$ along each.
- Fill in more slopes at grid points as needed (a table helps).
- To sketch the solution through $(x_0,y_0)$, start at that point and draw a smooth curve that is tangent to the segments everywhere, going both forwards and backwards.
- Look for special curves: lines where the segments point along the line are themselves solutions.
| $(x,y)$ | $(0,0)$ | $(1,0)$ | $(0,1)$ | $(2,1)$ | $(-1,1)$ | $(1,-1)$ |
|---|---|---|---|---|---|---|
| slope | $0$ | $1$ | $-1$ | $1$ | $-2$ | $2$ |
Consequence. Inside such a rectangle, two different solution curves can never cross or touch: if they met at a point, they would be two solutions of the same IVP.
Equilibrium Solutions and Stability
Many models do not involve $x$ (or $t$) explicitly at all: the cooling law $T^\prime=-k(T-22)$ and the growth law $P^\prime=0.4P$ depend only on the current value. For such equations the direction field looks the same along every horizontal line, and the most important features are the heights where the slope is zero.
A constant function $y=c$ is an equilibrium solution of $y^\prime=f(y)$ when $f(c)=0$. (Indeed $y=c$ gives $y^\prime=0=f(c)$.) Its graph is a horizontal line.
- stable (asymptotically stable) if every solution that starts close enough to $c$, on either side, tends to $c$ as $x\to\infty$;
- unstable if solutions starting arbitrarily close to $c$, on both sides, move away from $c$;
- semi-stable if solutions on one side approach $c$ while solutions on the other side move away.
- Solve $f(y)=0$ to find the equilibria; mark them on a vertical $y$-axis (the phase line).
- In each interval between equilibria, find the sign of $f(y)$ (test one value). Draw an arrow up where $f\gt0$ (solutions increase) and down where $f\lt0$ (solutions decrease).
- Arrows pointing towards $c$ from both sides: stable. Both away: unstable. One towards and one away: semi-stable.
- if $f^\prime(c)\lt0$, the equilibrium $y=c$ is stable;
- if $f^\prime(c)\gt0$, it is unstable;
- if $f^\prime(c)=0$, the test is inconclusive โ use the phase line.
Why. If $f^\prime(c)\lt0$, then $f$ is decreasing through $0$ at $c$, so $f\gt0$ just below $c$ (solutions rise towards $c$) and $f\lt0$ just above (solutions fall towards $c$). The case $f^\prime(c)\gt0$ is the mirror image.
| interval | $y\lt-1$ | $-1\lt y\lt2$ | $y\gt2$ |
|---|---|---|---|
| sign of $f$ | $+$ โ | $-$ โ | $+$ โ |
1. Stable equilibria are what we observe. A cup of coffee always ends at room temperature, whatever its starting temperature: $T=22$ is a stable equilibrium of $T^\prime=-k(T-22)$. Unstable equilibria are like a pencil balanced on its tip โ mathematically possible, never seen for long.
2. Semi-stable is fragile. A small disturbance on the โwrongโ side sends the solution away for good, so in a model a semi-stable state usually signals that a parameter is sitting exactly on a tipping point.
3. Equilibria act as barriers. By uniqueness (Theorem 7.2), a solution that starts between two equilibria stays between them for ever.
Euler's Method
A direction field shows the shape of solutions; Euler's method turns it into numbers. Start at the initial point $(x_0,y_0)$. The equation tells us the slope there, $f(x_0,y_0)$. Walk a short horizontal distance $h$ along the tangent line โ the straight line with that slope โ to reach a new point $(x_1,y_1)$. Recompute the slope there and repeat. The result is a polygon (a broken line) that hugs the true solution curve when $h$ is small. It is the tangent line of Calculus I ยง3.1, used again and again: near $x_k$ the curve is close to its tangent line.
| $k$ | $x_k$ | $y_k$ | $f(x_k,y_k)=x_k+y_k$ | $y_{k+1}=y_k+0.1f$ |
|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 1.1 |
| 1 | 0.1 | 1.1 | 1.2 | 1.22 |
| 2 | 0.2 | 1.22 | 1.42 | 1.362 |
| 3 | 0.3 | 1.362 | 1.662 | 1.5282 |
| 4 | 0.4 | 1.5282 | 1.9282 | 1.72102 |
How Accurate Is Euler's Method?
Each Euler step follows a tangent line instead of the curve, so it makes a small error, and the errors of the steps accumulate. Halving $h$ makes each step's error about four times smaller (a tangent-line error is roughly proportional to $h^2$), but doubles the number of steps โ so the total error at a fixed point is roughly halved.
| $h$ | $y_n=(1+h)^{1/h}$ | error $e-y_n$ | error รท $h$ |
|---|---|---|---|
| 0.5 | 2.25 | 0.4683 | 0.937 |
| 0.25 | 2.4414 | 0.2769 | 1.108 |
| 0.1 | 2.5937 | 0.1245 | 1.245 |
| 0.05 | 2.6533 | 0.0650 | 1.300 |
| 0.01 | 2.7048 | 0.0135 | 1.347 |
| $k$ | $t_k$ (min) | $T_k$ (ยฐC) | $f(T_k)$ (ยฐC/min) | $T_{k+1}$ |
|---|---|---|---|---|
| 0 | 0 | 90 | โ5.44 | 84.56 |
| 1 | 1 | 84.56 | โ5.0048 | 79.5552 |
| 2 | 2 | 79.5552 | โ4.604416 | 74.950784 |
- Using the slope at the new point instead of the old one: Euler's method uses $f(x_k,y_k)$, the slope where you are standing.
- Forgetting to update $x$: the slope at step $k$ is $f(x_k,y_k)$ with $x_k=x_0+kh$, not $f(x_0,y_k)$.
- Rounding too early: keep at least five or six significant figures in intermediate values.
- Too large a step can be disastrous. For $y^\prime=-2y$, Euler gives $y_{k+1}=(1-2h)y_k$. With $h=1$ the factor is $-1$ and the approximations flip between $4$ and $-4$ for ever, while the true solution $4e^{-2x}$ decays smoothly to $0$. Try it in Interactive 2 with problem 4 and $n=3$.
Exercises
- 1 For $y^\prime=x-y$, find the slope of the direction field at $(2,1)$, $(0,3)$ and $(-1,-1)$.
- 2 Find and classify the equilibria of $y^\prime=y(2-y)$.
- 3 Find and classify the equilibria of $y^\prime=y^2-4$.
- 4 Find and classify the equilibria of $y^\prime=(y-1)^2$.
- 5 Find and classify the equilibria of $y^\prime=-3(y-5)$.
- 6 Find and classify the equilibria of $y^\prime=y^3-y$.
- 7 Show that $y^\prime=1+y^2$ has no equilibrium solutions. What can you say about every solution?
- 8 For $y^\prime=y(2-y)$ describe the long-term behaviour of the solutions with $y(0)=0.5$, $y(0)=3$ and $y(0)=-0.1$.
- 9 For $y^\prime=x^2+y^2$, on which curve are all the slopes equal to $1$? Where is the direction field horizontal?
- 10 For $y^\prime=(y-1)(y-3)$, what happens as $x\to\infty$ to the solution with $y(0)=2$? With $y(0)=4$?
- 11 Find and classify the equilibria of $y^\prime=\sin y$ in the range $-4\le y\le4$.
- 1 $y^\prime=2x$, $y(0)=0$, $h=0.5$: estimate $y(2)$ and compare with the exact value.
- 2 $y^\prime=y$, $y(0)=1$, $h=0.2$: estimate $y(1)$ and find the error.
- 3 $y^\prime=x-y$, $y(0)=1$, $h=0.25$: estimate $y(1)$. Compare with the exact solution $y=x-1+2e^{-x}$.
- 4 $y^\prime=-2y$, $y(0)=4$, $h=0.1$: estimate $y(0.3)$ and compare with $4e^{-0.6}$.
- 5 $y^\prime=x^2+y^2$, $y(0)=0$, $h=0.1$: estimate $y(0.3)$. (This equation has no elementary solution formula.)
- 6 $y^\prime=xy$, $y(0)=1$, $h=0.5$: estimate $y(1)$; the exact value is $e^{1/2}$.
- 7 Show that Euler's method with $n$ steps for $y^\prime=y$, $y(0)=1$ gives $y(1)\approx\left(1+\tfrac1n\right)^n$. What is the limit as $n\to\infty$?
- 8 Euler's method with $h=0.1$ gives an error of $0.12$ at $x=2$ for a certain IVP. Predict the error with $h=0.05$ and with $h=0.01$.
- 9 Explain why Euler's method underestimates the solution of $y^\prime=y$, $y(0)=1$ for every $h\gt0$.
- 10 Show that Euler's method for $y^\prime=ky$ gives $y_n=y_0(1+kh)^n$. For $k=-3$, for which step sizes $h$ do the approximations oscillate in sign? For which do they grow instead of decay?
- 1 Tea at $85^\circ$C cools in a $20^\circ$C room according to $\dfrac{dT}{dt}=-0.1(T-20)$ ($t$ in minutes). Use Euler's method with $h=2$ to estimate $T(6)$, and compare with the exact solution $T=20+65e^{-0.1t}$.
- 2 For the model in part 1, find the equilibrium temperature and its stability.
- 3 Drug infusion. A drip delivers a drug at $5$ mg/h and the body removes $25\%$ of the amount present per hour: $\dfrac{dA}{dt}=5-0.25A$, $A(0)=0$. Find the equilibrium level and its stability. Use Euler's method with $h=1$ h to estimate $A(3)$ and compare with the exact solution $A=20\left(1-e^{-0.25t}\right)$.
- 4 Harvesting. A fish population (in thousands) obeys $\dfrac{dP}{dt}=0.5P-100$, $t$ in years. Find the equilibrium and its stability, and explain what it means for the fishery.
- 5 Falling with air resistance. A skydiver's velocity satisfies $\dfrac{dv}{dt}=9.8-0.2v$, $v(0)=0$ (m/s). Find the terminal velocity. Use Euler's method with $h=1$ s to estimate $v(2)$; the exact value is $49\left(1-e^{-0.4}\right)$.
- 6 Repeat the estimate in part 5 with $h=0.5$ s. By what factor did the error shrink? Is this consistent with Theorem 7.4?
Research question. If you want a cup of tea to be as cool as possible in $10$ minutes, should you add the cold milk at the start or at the end?
Why it matters. The same reasoning โ a cooling rate proportional to a temperature difference, solved step by step โ is used by engineers to design heat exchangers and electronics cooling, by food-safety agencies to set chilling times for cooked food, and by forensic scientists to estimate time of death.
What to do.
- Model: $200$ mL of tea at $90^\circ$C in a $22^\circ$C room, $\dfrac{dT}{dt}=-0.08(T-22)$ ($t$ in min). Adding $20$ mL of milk at $5^\circ$C instantly mixes to $T_{\text{new}}=\dfrac{200T+20\cdot5}{220}$.
- Option A: add milk at $t=0$, then cool for $10$ min. Option B: cool for $10$ min, then add milk.
- In a spreadsheet, run Euler's method for both options with $h=1$ and with $h=0.5$ min. Then use the exact solution $T=22+(T_0-22)e^{-0.08t}$ and compare.
- If you can, test it with a kitchen thermometer and two identical mugs; estimate $k$ for your own mug from two readings.
Tools: Spreadsheet, calculator; optionally a kitchen thermometer
Hand in: A half-page note: your Euler and exact results for both options, which option wins and by how much, and why (in terms of the direction field or the cooling rate).
Going further. Change the room temperature to that of a summer afternoon where you live, or let the room itself warm up slowly, and see whether the conclusion changes.
๐งช Self-check quiz
Q1. In the direction field of $y^\prime=xy$, the segment at $(2,-1)$ has slope
Q2. For $y^\prime=y(4-y)$, which statement is true?
Q3. One Euler step with $h=0.1$ for $y^\prime=2x+y$, $y(0)=1$ gives $y_1=$
Q4. If the step size in Euler's method is halved, the error at a fixed point is approximately
Q5. The equilibrium $y=2$ of $y^\prime=(y-2)^2$ is