Calculus3Differential Equations3 of 7
Differential Equations · 3

Tangent Lines and Euler's Method

1

Estimating with a tangent line

We want to estimate y(0.5)y(0.5) for the solution to dydx=y−x\frac{dy}{dx} = y - x with y(0)=2y(0) = 2. But we don't have a formula for yy, so we can't just plug in 0.50.5.

What we do have is the slope. The differential equation gives the slope y−xy - x at any point, and our solution passes through (0,2)(0, 2). A point and a slope are all a tangent line needs.

Tangent line at x=ax = a
y≈f(a)+f′(a)(x−a)\displaystyle y \approx f(a) + \slp{f'(a)}(x - a)

So the slope-field segment at (0,2)(0, 2) is a piece of the tangent line to our solution, and we can follow that line out to x=0.5x = 0.5.

−0.5-0.5
00
0.50.5
11
00
11
22
33
44
55
xx
yy
(0,2)(0, 2)
(0.5,3)(0.5, 3)
y=2+2x\htmlClass{lc-pink}{y = 2 + 2x}
dydx∣(0, 2)\displaystyle \slp{\frac{dy}{dx}\Big|_{(0,\,2)}} =2−0\displaystyle = 2 - 0 =2\displaystyle = \slp{2}
Use the tangent line at (0,2)(0, 2) to estimate y(0.5)y(0.5) for dydx=y−x\frac{dy}{dx} = y - x with y(0)=2y(0) = 2
−0.5-0.5
00
0.50.5
11
00
11
22
33
44
55
xx
yy
(0,2)(0, 2)
y(0.5)≈  ?y(0.5) \approx \;?
Text solution
Tangent line, then plug in 0.50.5We get the slope straight from the equation, 2−0=22 - 0 = \slp{2}, so the line through (0,2)(0, 2) is
y≈2+2(x−0)\displaystyle y \approx 2 + \slp{2}(x - 0) =2+2x\displaystyle = \slp{2 + 2x}
y(0.5)≈2+2(0.5)\displaystyle y(0.5) \approx 2 + \slp{2}(0.5) =3\displaystyle = 3
Compare with the exact solutionThis equation happens to have the solution y=x+1+ex\sol{y = x + 1 + e^x}: its derivative 1+ex1 + e^x equals y−xy - x, and y(0)=2y(0) = 2. So 33 is a little low.
y(0.5)\displaystyle y(0.5) =1.5+e0.5≈3.15\displaystyle = \sol{1.5 + e^{0.5} \approx 3.15}
2

Deciding whether an estimate is too big or too small

The tangent line gave y(0.5)≈3y(0.5) \approx 3, and the actual solution gave 3.15\sol{3.15}, so our estimate was too small. But if we don't have the formula for the solution, how can we tell whether an estimate is too big or too small?

If a curve is concave up, it lies above its tangent lines, so the tangent-line estimate is too small. If it's concave down, it lies below its tangent lines, and the estimate is too big.

concave up\htmlClass{lc-orange}{\text{concave up}}
concave down\htmlClass{lc-violet}{\text{concave down}}

Concavity comes from the sign of the second derivative, d2ydx2\frac{d^2y}{dx^2}, so we need to get it from the differential equation alone. Let's find it at (0,2)(0, 2), and then at a second starting point, (0,0)(0, 0).

Decide whether the tangent-line estimate is too big or too small for dydx=y−x\frac{dy}{dx} = y - x
−0.5-0.5
00
0.50.5
11
00
11
22
33
44
55
xx
yy
(0,2)(0, 2)
(0.5,3)(0.5, 3)
y=2+2x\htmlClass{lc-pink}{y = 2 + 2x}
d2ydx2=  ?\dfrac{d^2y}{dx^2} = \;?
Text solution
Differentiate both sidesyy is a function of xx, so its derivative is dydx\slp{\frac{dy}{dx}}, not 00. Treating yy as a constant would give −1-1 and the wrong answer. In the same way, y2y^2 would give 2y dydx2y\,\slp{\frac{dy}{dx}}.
d2ydx2\displaystyle \frac{d^2y}{dx^2} =ddx(y−x)\displaystyle = \frac{d}{dx}(y - x) =dydx−1\displaystyle = \slp{\frac{dy}{dx}} - 1
At (0,2)(0, 2): too smallThe slope there is 2\slp{2}, so the curve is concave up and lies above its tangent line. The estimate 33 is too small.
d2ydx2\displaystyle \frac{d^2y}{dx^2} =2−1\displaystyle = \slp{2} - 1 =1>0\displaystyle = \cvup{1 > 0}
At (0,0)(0, 0): too bigThe slope there is 0−0=00 - 0 = \slp{0}, so the tangent line is y=0\slp{y = 0} and the estimate of y(0.5)y(0.5) is 00. The curve is concave down, so 00 is too big.
d2ydx2\displaystyle \frac{d^2y}{dx^2} =0−1\displaystyle = \slp{0} - 1 =−1<0\displaystyle = \cvdn{-1 < 0}

Is the tangent-line estimate always too big or always too small for the same equation?

3

Stepping with Euler's method

What if we use the same tangent line to estimate y(1)y(1)? It gives 44, but the exact solution gives 2+e\sol{2 + e}, about 4.72\sol{4.72}. So 44 is quite a bit too small.

tangent line at (0,2) ⁣:y(1)≈2+2(1)=4y(1)=2+e≈4.72\displaystyle \begin{aligned}\text{tangent line at } (0, 2)\colon\quad y(1) &\approx 2 + \slp{2}(1) = 4\\ y(1) &= \sol{2 + e \approx 4.72}\end{aligned}
tangent line at (0,2) ⁣:y(1)≈2+2(1)=4y(1)=2+e≈4.72\displaystyle \begin{aligned}&\text{tangent line at } (0, 2)\colon\\ &y(1) \approx 2 + \slp{2}(1) = 4\\[4pt] &y(1) = \sol{2 + e \approx 4.72}\end{aligned}
−0.5-0.5
00
0.50.5
11
00
11
22
33
44
55
xx
yy
(0,2)(0, 2)
(1,4)(1, 4)
(1,4.72)\htmlClass{lc-blue}{(1, 4.72)}
y=2+2x\htmlClass{lc-pink}{y = 2 + 2x}
y=x+1+ex\htmlClass{lc-blue}{y = x + 1 + e^x}

The tangent line keeps a slope of 2\slp{2} the whole way, while the slope y−xy - x on the actual solution keeps increasing. So instead, we follow the line only to x=0.5x = 0.5, find a fresh slope at the new point, and follow a new line from there. Going from 00 to 11 in two equal steps, each step has size 0.50.5.

Estimate y(1)y(1) for dydx=y−x\frac{dy}{dx} = y - x with y(0)=2y(0) = 2 using two steps of 0.50.5
−0.5-0.5
00
0.50.5
11
00
11
22
33
44
55
xx
yy
(0,2)(0, 2)
y(1)≈  ?y(1) \approx \;?
step=0.5\text{step} = 0.5
Text solution
First step, from (0,2)(0, 2)The change in yy is the slope times the step.
slope\displaystyle \text{slope} =2−0\displaystyle = 2 - 0 =2\displaystyle = \slp{2}
2×0.5\displaystyle \slp{2} \times 0.5 =1\displaystyle = \chg{1}
→  (0.5, 3)\displaystyle \to\; (0.5,\ 3)
Fresh slope at (0.5,3)(0.5, 3)This point is a little below our curve, since y(0.5)≈3.15y(0.5) \approx \sol{3.15}. So 2.5\slp{2.5} is the slope of a nearby solution, a much better direction than 2\slp{2}.
slope\displaystyle \text{slope} =3−0.5\displaystyle = 3 - 0.5 =2.5\displaystyle = \slp{2.5}
2.5×0.5\displaystyle \slp{2.5} \times 0.5 =1.25\displaystyle = \chg{1.25}
→  (1, 4.25)\displaystyle \to\; (1,\ 4.25)
Stepping to the leftTo estimate y(−0.5)y(-0.5), use a step of −0.5-0.5. The true value is 0.5+e−0.5≈1.11\sol{0.5 + e^{-0.5} \approx 1.11}.
y(−0.5)≈2+2(−0.5)\displaystyle y(-0.5) \approx 2 + \slp{2}(-0.5) =1\displaystyle = 1

Taking a step along a tangent line and then recalculating the slope at the new point is called Euler's method. The step can be negative, to go left.

new x=x+stepnew y=y+(slope at (x,y))×step\displaystyle \begin{aligned}\text{new } x &= x + \text{step}\\ \text{new } y &= y + (\slp{\text{slope at } (x, y)}) \times \text{step}\end{aligned}

We can keep track of the steps in a table, with one row per point.

xxyyslope\slp{\text{slope}}=y−x= y - xchange in y\chg{\text{change in } y}=slope= \slp{\text{slope}} ×0.5{}\times 0.5
00222\slp{2}1\chg{1}
0.50.5332.5\slp{2.5}1.25\chg{1.25}
114.254.25
4

Smaller steps and concavity

With two steps of 0.50.5, we got y(1)≈4.25y(1) \approx 4.25. That's closer than the 44 from a single tangent line, but both are still less than 2+e≈4.72\sol{2 + e \approx 4.72}. So let's see how much closer four smaller steps of 0.250.25 get us, and why every estimate stays too small.

Estimate y(1)y(1) with four steps of 0.250.25 for dydx=y−x\frac{dy}{dx} = y - x with y(0)=2y(0) = 2, and check whether the estimate is too small
−0.5-0.5
00
0.50.5
11
00
11
22
33
44
55
xx
yy
(0,2)(0, 2)
y=x+1+ex\htmlClass{lc-blue}{y = x + 1 + e^x}
44
4.254.25
4.72\htmlClass{lc-blue}{4.72}
y(1)≈  ?y(1) \approx \;?
step=0.25\text{step} = 0.25
Text solution
Four steps of 0.250.25At each point, the slope is y−xy - x, and yy changes by the slope times 0.250.25.
(0,2)→(0.25, 2.5)\displaystyle (0, 2) \to (0.25,\ 2.5)
→(0.5, 3.0625)\displaystyle \to (0.5,\ 3.0625)
→(0.75, 3.703125)\displaystyle \to (0.75,\ 3.703125)
→(1, 4.44)\displaystyle \to (1,\ 4.44)
Concave up above y=x+1y = x + 1The line y=x+1\sol{y = x + 1} is itself a solution, since its slope and y−xy - x are both 11. Above it, d2ydx2=y−x−1\frac{d^2y}{dx^2} = y - x - 1 is positive, and every point of our path lies above it. So every solution curve through our path is concave up.
Each step lands on a lower curveEach step follows the tangent line of a concave-up solution curve, so it ends below that curve. Solution curves can't cross, so the path keeps landing on lower curves and stays below y=x+1+ex\sol{y = x + 1 + e^x}. Every estimate is too small.

Halving the step size gets us closer to 4.72\sol{4.72}, but it takes twice as many steps, and here every estimate stays below it.

1 step: 4\displaystyle 1 \text{ step: } 4
2 steps: 4.25\displaystyle 2 \text{ steps: } 4.25
4 steps: 4.44\displaystyle 4 \text{ steps: } 4.44
y(1)=2+e≈4.72\displaystyle {y(1) = \sol{2 + e \approx 4.72}}

To see why without the exact solution, we check the sign of the second derivative along the whole path, not just at (0,2)(0, 2). Every corner sits above y=x+1\sol{y = x + 1}, where every solution curve is concave up.

00
0.50.5
11
00
11
22
33
44
55
xx
yy
(0,2)(0, 2)
(0.25,2.5)(0.25, 2.5)
(0.5,3.0625)(0.5, 3.0625)
(0.75,3.703125)(0.75, 3.703125)
(1,4.44)(1, 4.44)
y=x+1\htmlClass{lc-blue}{y = x + 1}
y=x+1+ex\htmlClass{lc-blue}{y = x + 1 + e^x}
d2ydx2=dydx−1=(y−x)−1=y−x−1\displaystyle \begin{aligned}\frac{d^2y}{dx^2} &= \slp{\frac{dy}{dx}} - 1\\ &= \slp{(y - x)} - 1\\ &= y - x - 1\end{aligned}
y−x−1>0for y>x+1\displaystyle \begin{gathered}\cvup{y - x - 1 > 0}\\ \text{for } \cvup{y > x + 1}\end{gathered}

How does taking smaller steps change Euler’s estimate?

Summary

Tangent line from a differential equation
dydx=y−x at (0,2) ⁣:2−0=2→  y≈2+2x\displaystyle \begin{gathered}\frac{dy}{dx} = y - x \text{ at } (0, 2)\colon\quad 2 - 0 = \slp{2}\\[6pt] \to\; y \approx \slp{2 + 2x}\end{gathered}
dydx=y−x at (0,2) ⁣:2−0=2→  y≈2+2x\displaystyle \begin{gathered}\frac{dy}{dx} = y - x \text{ at } (0, 2)\colon\\ 2 - 0 = \slp{2}\\[6pt] \to\; y \approx \slp{2 + 2x}\end{gathered}

Plug both coordinates of the given point directly into the differential equation to find the slope. The tangent line gives an estimate of the solution without needing a formula for yy.

Overestimate or underestimate from concavity
concave up\htmlClass{lc-orange}{\text{concave up}}
concave down\htmlClass{lc-violet}{\text{concave down}}
d2ydx2=ddx(y−x)=dydx−1=2−1=1>0\displaystyle \begin{aligned}\frac{d^2y}{dx^2} &= \frac{d}{dx}(y - x)\\ &= \slp{\frac{dy}{dx}} - 1\\ &= \slp{2} - 1 = \cvup{1 > 0}\end{aligned}
ddx(y2)=2y dydx\displaystyle {\frac{d}{dx}\left(y^2\right) = 2y\,\slp{\frac{dy}{dx}}}

To find d2ydx2\frac{d^2y}{dx^2}, differentiate the differential equation with respect to xx. Remember that yy is a function of xx, so the derivative of yy is dydx\slp{\frac{dy}{dx}}, and the derivative of y2y^2 is 2y dydx2y\,\slp{\frac{dy}{dx}}. If d2ydx2>0\cvup{\frac{d^2y}{dx^2} > 0} at the point, the solution curve is concave up and lies above its tangent line, so the tangent-line estimate is too small. If d2ydx2<0\cvdn{\frac{d^2y}{dx^2} < 0}, the curve is concave down and lies below its tangent line, so the estimate is too big.

Updating the slope with Euler's method
new x=x+stepnew y=y+(slope at (x,y))×step\displaystyle \begin{aligned}\text{new } x &= x + \text{step}\\ \text{new } y &= y + (\slp{\text{slope at } (x, y)}) \times \text{step}\end{aligned}
new x=x+stepnew y=y+(slope at (x,y))×step\displaystyle \begin{aligned}\text{new } x &= x + \text{step}\\ \text{new } y &= y + (\slp{\text{slope at } (x, y)})\\ &\qquad \times \text{step}\end{aligned}
xxyyslope\slp{\text{slope}}=y−x= y - xchange in y\chg{\text{change in } y}=slope= \slp{\text{slope}} ×0.5{}\times 0.5
00222\slp{2}1\chg{1}
0.50.5332.5\slp{2.5}1.25\chg{1.25}
114.254.25

Instead of keeping one slope the whole way, take a short step along the tangent line. At each new point, calculate the new slope from its coordinates and multiply by the step size to get the next change in yy. For nn equal steps, the step size is the target xx minus the starting xx, divided by nn. So going from x=0x = 0 to x=1x = 1 in 22 steps gives a step size of 0.50.5. To step to the left, use a negative step size.

Step size and concavity in Euler's method
1 step: 4\displaystyle 1 \text{ step: } 4
2 steps: 4.25\displaystyle 2 \text{ steps: } 4.25
4 steps: 4.44\displaystyle 4 \text{ steps: } 4.44
y(1)≈4.72\displaystyle {y(1) \approx \sol{4.72}}

When we take smaller steps, we recalculate the slope more often and get a closer estimate of the true value. If d2ydx2>0\cvup{\frac{d^2y}{dx^2} > 0} along the path, the solution curves are concave up, so each step ends below the curve through its start and Euler's method underestimates. If d2ydx2<0\cvdn{\frac{d^2y}{dx^2} < 0} along the path, it overestimates.

5

Practice

Enter decimals exactly as your steps give them, without rounding.

1
The function y=f(x)y = f(x) is the solution of the differential equation dydx=x2−y\dfrac{dy}{dx} = x^2 - y with f(2)=3f(2) = 3. (a) Write an equation of the tangent line to the graph of ff at x=2x = 2, and use it to approximate f(2.1)f(2.1). (b) Is your approximation an overestimate or an underestimate? Explain.

To find the slope at (2,3)(2, 3), plug both coordinates into dydx=x2−y\frac{dy}{dx} = x^2 - y.

If you got 3.43.4 Check the slope of the tangent line. dydx\frac{dy}{dx} depends on both xx and yy, so plug in y=3y = 3 as well as x=2x = 2.

(b)\text{(b)}
The tangent lineThe differential equation has both xx and yy, so plug in x=2x = 2 and y=3y = 3 to find the slope.
dydx∣(2, 3)\displaystyle \slp{\frac{dy}{dx}\Big|_{(2,\,3)}} =22−3\displaystyle = 2^2 - 3 =1\displaystyle = \slp{1}
Write the tangent line using the point (2,3)(2, 3) and slope 1\slp{1}, then plug in x=2.1x = 2.1.
y\displaystyle y =3+1(x−2),f(2.1)≈3+1(0.1)\displaystyle = 3 + \slp{1}(x - 2), \qquad f(2.1) \approx 3 + \slp{1}(0.1) =3.1\displaystyle = 3.1
ConcavityDifferentiating x2−yx^2 - y gives 2x−dydx2x - \slp{\frac{dy}{dx}}. At (2,3)(2, 3), the second derivative is positive, so the curve is concave up and the tangent line lies below it. So 3.13.1 is an underestimate.
d2ydx2\displaystyle \frac{d^2y}{dx^2} =2x−dydx\displaystyle = 2x - \slp{\frac{dy}{dx}} =2(2)−1\displaystyle = 2(2) - \slp{1} =3>0\displaystyle = \cvup{3 > 0}
2
Let yy be the solution of dydx=x−y2\dfrac{dy}{dx} = x - y^2 with y(0)=1y(0) = 1. (a) Use the tangent line at x=0x = 0 to approximate y(0.2)y(0.2). (b) Is your approximation an overestimate or an underestimate? Explain.
(b)\text{(b)}

When you differentiate y2y^2 with respect to xx, remember that yy is a function of xx. What does the chain rule give?

The tangent line estimatePlug (0,1)(0, 1) into the differential equation to get the slope, write the tangent line, and plug in x=0.2x = 0.2.
dydx∣(0, 1)\displaystyle \slp{\frac{dy}{dx}\Big|_{(0,\,1)}} =0−12\displaystyle = 0 - 1^2 =−1,y≈1−x,y(0.2)≈0.8\displaystyle = \slp{-1}, \qquad y \approx 1 - x, \qquad y(0.2) \approx 0.8
The second derivativeBecause yy is a function of xx, the chain rule gives an extra factor of dydx\slp{\frac{dy}{dx}} when we differentiate y2y^2.
d2ydx2\displaystyle \frac{d^2y}{dx^2} =1−2y dydx\displaystyle = 1 - 2y\,\slp{\frac{dy}{dx}}
Plugging in (0,1)(0, 1) and dydx=−1\slp{\frac{dy}{dx} = -1} gives 33. Because the second derivative is positive, the curve is concave up and the estimate is an underestimate.
at (0,1) ⁣:d2ydx2\displaystyle \text{at } (0, 1)\colon \quad \frac{d^2y}{dx^2} =1−2(1)(−1)\displaystyle = 1 - 2(1)(\slp{-1}) =3>0\displaystyle = \cvup{3 > 0}
3
Let yy be the solution of dydx=y−x2\dfrac{dy}{dx} = y - x^2 with y(1)=2y(1) = 2. Use Euler's method with two steps of equal size, starting at x=1x = 1, to approximate y(0)y(0).

We're moving backwards from x=1x = 1 to x=0x = 0 in two steps. What is the step size?

The step sizeWe're moving left from x=1x = 1 to x=0x = 0, so the step size is negative.
step\displaystyle \text{step} =0−12\displaystyle = \frac{0 - 1}{2} =−0.5\displaystyle = -0.5
Start at (1,2)(1, 2), compute the slope, and multiply by −0.5-0.5 to find the change in yy.
from (1,2) ⁣:slope=2−12=1change in y=1×(−0.5)=−0.5  →  (0.5, 1.5)\displaystyle \begin{aligned}\text{from } (1, 2)\colon\quad \text{slope} &= 2 - 1^2 = \slp{1}\\ \text{change in } y &= \slp{1} \times (-0.5) = \chg{-0.5} \;\to\; (0.5,\ 1.5)\end{aligned}
Recompute the slope at (0.5,1.5)(0.5, 1.5) and take the second step of −0.5-0.5 to reach x=0x = 0.
from (0.5,1.5) ⁣:slope=1.5−0.52=1.25change in y=1.25×(−0.5)=−0.625  →  (0, 0.875)\displaystyle \begin{aligned}\text{from } (0.5, 1.5)\colon\quad \text{slope} &= 1.5 - 0.5^2 = \slp{1.25}\\ \text{change in } y &= \slp{1.25} \times (-0.5) = \chg{-0.625} \;\to\; (0,\ 0.875)\end{aligned}
4
Let y=g(x)y = g(x) be the solution of dydx=2x−3y\dfrac{dy}{dx} = 2x - 3y with g(0)=kg(0) = k. Euler's method with step size 1, starting at x=0x = 0, gives g(2)≈10g(2) \approx 10. Find kk.

At (1,−2k)(1, -2k), plug x=1x = 1 and y=−2ky = -2k into 2x−3y2x - 3y. What is the new slope?

At (0,k)(0, k), the slope is −3k\slp{-3k}, so over a step of 11 the change in yy is −3k\chg{-3k}.
from (0,k) ⁣:slope=2(0)−3k=−3kg(1)≈k+(−3k)(1)=−2k\displaystyle \begin{aligned}\text{from } (0, k)\colon\quad \text{slope} &= 2(0) - 3k = \slp{-3k}\\ g(1) &\approx k + (\slp{-3k})(1) = -2k\end{aligned}
At (1,−2k)(1, -2k), compute the new slope and add the change in yy over the second step.
from (1,−2k) ⁣:slope=2(1)−3(−2k)=2+6kg(2)≈−2k+(2+6k)(1)=2+4k\displaystyle \begin{aligned}\text{from } (1, -2k)\colon\quad \text{slope} &= 2(1) - 3(-2k) = \slp{2 + 6k}\\ g(2) &\approx -2k + (\slp{2 + 6k})(1) = 2 + 4k\end{aligned}
Set this estimate equal to 1010 and solve for kk.
2+4k\displaystyle 2 + 4k =10  →  k\displaystyle = 10 \;\to\; k =2\displaystyle = 2
5
(Challenge) Let yy be the solution of dydx=y\dfrac{dy}{dx} = y with y(0)=1y(0) = 1. (a) Show that Euler's method with nn equal steps from x=0x = 0 to x=1x = 1 gives y(1)≈(1+1n)ny(1) \approx \left(1 + \dfrac1n\right)^n. (b) What does this estimate approach as nn grows?

With nn equal steps from 00 to 11, each step is 1n\frac1n. If the slope is yy, what do you multiply yy by to get the new y-value?

One stepBecause the slope is y\slp{y}, each step of size 1n\frac1n adds y⋅1n\chg{\slp{y} \cdot \frac1n}, and that multiplies the current value by 1+1n1 + \frac1n.
step\displaystyle \text{step} =1n,new y\displaystyle = \frac1n, \qquad \text{new } y =y+y⋅1n\displaystyle = y + \chg{\slp{y} \cdot \frac1n} =y(1+1n)\displaystyle = y\left(1 + \frac1n\right)
Starting at y=1y = 1, each of the nn steps multiplies by another factor of 1+1n1 + \frac1n.
1  →  1+1n  →  (1+1n)2  →  ⋯  →  (1+1n)n\displaystyle 1 \;\to\; 1 + \frac1n \;\to\; \left(1 + \frac1n\right)^2 \;\to\; \cdots \;\to\; \left(1 + \frac1n\right)^n
The limit as nn increasesAs nn goes to infinity, the estimate approaches ee, which is the exact value of the solution y=ex\sol{y = e^x} at x=1x = 1.
lim⁡n→∞(1+1n)n\displaystyle \lim_{n\to\infty}\left(1 + \frac1n\right)^n =e\displaystyle = e =y(1)\displaystyle = y(1)