Unit 7 · Topic 7.5 · BC

Euler approximation

Builds on the tangent line approximation, concavity and slope fields. 12 minutes.

  1. Example 1Take one Euler step
  2. Example 2Update both coordinates after every step
  3. Example 3Reach the requested input
  4. Example 4Interpret the approximation's error

An initial value problem (topic 7.2) has the form

\[\frac{dy}{dx}=F(x,y),\qquad y(x_0)=y_0\]

where \(F(x,y)\) is an expression in \(x\) and \(y\). Often no formula for its solution can be found. Euler's method, which some books call the tangent line method, approximates that solution with short straight steps. This topic builds the method, runs it to a requested input, and finds the size and sign of its error.

A step along the tangent line

The slope field of dy/dx = x minus y, with the chalk solution curve through the orange start (0, 2). The curve falls, levels off near x = 1.1 and rises again. An orange path of Euler steps of size 0.5 runs from (0, 2) to (0.5, 1), (1, 0.75), (1.5, 0.875) and (2, 1.1875), below the curve, and a dashed orange segment at each corner shows the slope that the next step follows. Under the picture, a table lists x, y, the slope dy/dx and the change in y at each corner.

Figure 1Over the faint slope field of \(\frac{dy}{dx}=x-y\), the chalk curve is the solution through the orange start \((0,2)\). Each orange step follows the dashed orange segment where it starts. The newest step shows its faint dashed run and its rise. The rise and the changes in the table are green where \(y\) increases and red where it decreases.

In Figure 1, the chalk curve is the solution of \(\frac{dy}{dx}=x-y\) with \(y(0)=2\). By topics 7.2 and 7.4, it is \(y=x-1+3e^{-x}\), but suppose that no formula is known. Here \(F(x,y)=x-y\), so at the orange start \((0,2)\) the equation still gives the slope \(\cy{F(0,2)}=0-2=-2\).

In general, the solution passes through \((x_0,y_0)\) and satisfies the equation there, so its slope at \(x_0\) is \(\cy{F(x_0,y_0)}\). Its tangent line there is \(y=y_0+\cy{F(x_0,y_0)}\,(x-x_0)\) (topic 4.6). A step of size \(h\) ends at \(x_1=x_0+h\). Near \(x_0\) the tangent line stays close to the curve, so its height at \(x_1\) approximates \(y(x_1)\):

\[y(x_1)\approx y_1=y_0+h\,\cy{F(x_0,y_0)}\]

This is one Euler step. As along any line, the change in \(y\) is the run \(h\) times the slope. In Figure 1, \(h=0.5\), so the first step changes \(y\) by \(0.5(-2)=-1\), the red rise, and ends at \((0.5,1)\).

The step ends near the curve but usually not on it, because the curve bends. The slope of the curve at \(x_1\) is \(F\big(x_1,y(x_1)\big)\), which needs the unknown value \(y(x_1)\). The second step therefore uses the slope \(\cy{F(x_1,y_1)}\) of the solution through \((x_1,y_1)\), the point where the first step ends.

The steps join into the orange path, whose corners are the start and the end of each step. Step \(k+1\) uses the slope \(\cy{F(x_k,y_k)}\) at the corner \((x_k,y_k)\), with both of its coordinates. It ends at \(x_{k+1}=x_k+h\) and \(y_{k+1}=y_k+h\,\cy{F(x_k,y_k)}\).

Move the slider under Figure 1 to draw the steps one at a time. The table lists each corner, the slope \(\cy{\frac{dy}{dx}}\) there and the change \(\Delta y\) of the next step. Each row comes from the row above it.

Reaching the requested input

A problem asks for the solution at one input \(b\), the requested input, so the last corner must be at \(b\). With \(n\) equal steps, the last corner is at \(x_0+nh\), so \(h=\frac{b-x_0}{n}\). If a problem gives \(h\) instead, the number of steps \(\frac{b-x_0}{h}\) must be a whole number. In Figure 1, four steps of 0.5 reach \(b=2\).

If \(b\) is to the left of \(x_0\), then \(h\) is negative, and the steps run to the left. The same formula applies, because a tangent line approximates its curve on both sides of its point (topic 4.6). Each change \(h\,\cy{F(x_k,y_k)}\) then has the sign opposite to the slope.

A problem may instead list steps of different sizes. Each step then uses its own size, and the sizes must add up to \(b-x_0\).

The size and the sign of the error

Let \(y_n\) be the Euler approximation of \(y(b)\). Its error is \(\cr{E}=y(b)-y_n\), as for a tangent line (topic 4.6). A positive error means an underestimate, and a negative error means an overestimate.

The slope field of dy/dx = x minus y, with a dashed vertical line at x = 2 and a faint straight line y = x − 1 that rises from (0, −1) on the y-axis. An orange path of equal Euler steps runs from an orange start on the y-axis to the dashed line, and a chalk curve is the solution through the same start. A red segment on the dashed line joins the end of the path to a chalk dot on the curve. At first the start is (0, 2), the steps have size 0.5, the path and the curve lie above the faint line, and the curve bends upward and ends above the path. Buttons use steps of 0.25 or 0.125, which brings the end of the path closer to the curve. A slider moves the start: below (0, −1) the path and the curve lie below the faint line, and the curve bends downward and ends below the path. At (0, −1) the curve is the faint line, and the path lies on it.

Figure 2Over the faint slope field, the orange path runs from the orange start to the dashed line at \(x=2\). The chalk curve is the solution through the same start, and the faint line is \(y=x-1\). The red segment on the dashed line is the error.

In Figure 2, with \(h=0.5\), the path ends at 1.1875 (rounded to 1.188 under the figure), below \(y(2)=1+3e^{-2}\approx1.406\), so the error is about 0.219. Use the buttons under Figure 2 to shorten the steps to 0.25 and 0.125. The error falls to about 0.106 and then 0.052, about half each time.

The sign of the error comes from concavity. To find \(y''\), differentiate the equation with respect to \(x\), with the chain rule for \(y\) (topic 7.4). Then replace \(\frac{dy}{dx}\) by \(F(x,y)\). For the equation of the figures, the solution through \((x,y)\) has

\[y''=1-\frac{dy}{dx}=1-x+y\]

which is positive above the line \(y=x-1\) and negative below it.

Each step, in either direction, follows the tangent line of the solution through its start. If that solution is concave up over the step, it lies above the line there, so the step ends below it (topic 4.6). If the solution is concave down, the step ends above it.

For several steps, suppose that \(F\) is a polynomial in \(x\) and \(y\) or a quotient of such polynomials. Then, by the Existence and Uniqueness Theorem (topic 7.4), two different solutions never meet. Suppose also that \(y''>0\) throughout a region that contains the corners and, between \(x_0\) and \(b\), the solutions through them. The first step ends below the solution \(y\). The second step ends below the solution through \((x_1,y_1)\), which starts below \(y\) and therefore stays below it. Step by step, in either direction, every corner lies below \(y\), so the approximation is an underestimate. If \(y''<0\) in such a region, it is an overestimate.

In Figure 2, the start \((0,2)\) lies above the faint line \(y=x-1\), the solution through \((0,-1)\). A step changes \(y\) by \(h(x-y)\), and the line rises by \(h\), so the height \(y-(x-1)\) above the line changes by \(h(x-y)-h=-h\big(y-(x-1)\big)\). Each step multiplies the height by \(1-h\), which is positive for the step sizes of the figure, so every corner stays above the line. No other solution meets the line, so the solutions through the corners stay above it too, where \(y''>0\). The error is therefore positive. Move the start below \(-1\). The corners then lie below the line, where \(y''<0\), and the error is negative. At \(y(0)=-1\), the path follows the solution \(y=x-1\) exactly. If \(y''\) changes sign between \(x_0\) and \(b\), the rule gives no conclusion.

Example 1

Take one Euler step

A snowball melts so that its volume \(V\), in cubic centimeters, satisfies \(\dfrac{dV}{dt}=-0.6\,V^{2/3}\), where \(t\) is measured in minutes. At \(t=0\), the volume is 125 cubic centimeters. Use Euler's method with one step of size 2 to approximate the volume at \(t=2\).

Solution

The rate has a value for every \(V\ge0\). At \(t=0\), the volume is 125, and \(125^{2/3}=5^2=25\), so the rate is

\[\frac{dV}{dt}=-0.6(25)=-15\]

cubic centimeters per minute. The step follows the tangent line for 2 minutes, so it changes \(V\) by 2 times this rate:

\[V(2)\approx125+2(-15)=95\]

After 2 minutes, the volume of the snowball is about 95 cubic centimeters.

Example 2

Update both coordinates after every step

Let \(y=f(x)\) be the particular solution to the differential equation \(\dfrac{dy}{dx}=\dfrac{x}{y}\) with the initial condition \(f(3)=1.5\). Use Euler's method, starting at \(x=3\) with two steps of size 0.5, to approximate \(f(4)\).

Solution

The slope \(\frac{x}{y}\) has a value wherever \(y\neq0\). Each row of the table is a corner, and its slope uses both of its coordinates. Its change \(\Delta y=0.5\cdot\frac{x}{y}\) gives the \(y\) of the next row:

\[\begin{array}{c|c|c|c} x & y & \frac{x}{y} & \Delta y\\ \hline 3 & 1.5 & 2 & 1\\ 3.5 & 2.5 & 1.4 & 0.7\\ 4 & 3.2 & & \end{array}\]

Both steps start where \(y>0\), so their slopes have values. The last corner gives \(f(4)\approx3.2\).

Example 3

Reach the requested input

Let \(y=f(x)\) be the particular solution to the differential equation \(\dfrac{dy}{dx}=xy-2\) with the initial condition \(f(5)=-1\). Use Euler's method, starting at \(x=5\) with two steps of equal size, to approximate \(f(4)\).

Solution

The slope \(xy-2\) has a value at every point. The requested input 4 is to the left of the start 5, so the two equal steps have the negative size

\[h=\frac{4-5}{2}=-0.5\]

At the start \((5,-1)\), the slope is \(5(-1)-2=-7\). The first step therefore ends at \(x=4.5\), with

\[y_1=-1+(-0.5)(-7)=2.5\]

At the corner \((4.5,\,2.5)\), the slope is \(4.5(2.5)-2=9.25\). The second step ends at the requested input \(x=4\), with

\[y_2=2.5+(-0.5)(9.25)=-2.125\]

The approximation is \(f(4)\approx-2.125\).

Example 4

Interpret the approximation's error

The temperature \(T\) of a pie, in degrees Celsius, \(t\) minutes after it leaves the oven satisfies \(\dfrac{dT}{dt}=-0.05\,(T-22)\) with \(T(0)=182\), and the solution is \(T(t)=22+160e^{-0.05t}\). Use Euler's method with two steps of equal size to approximate \(T(10)\), and find the error. Is the approximation an underestimate or an overestimate? Use \(\dfrac{d^2T}{dt^2}\) to give a reason for your answer.

Solution

Two equal steps from \(t=0\) to \(t=10\) have size 5, and the rate has a value at every \(T\). The rate is \(-0.05(182-22)=-8\) at the start, so the first step ends at \(T_1=182+5(-8)=142\). At the corner \((5,142)\), the rate is \(-0.05(142-22)=-6\), so

\[T_2=142+5(-6)=112\]

and \(T(10)\approx112\) degrees Celsius. The exact value is \(T(10)=22+160e^{-0.5}\), so the error, in degrees Celsius, is

\[\begin{aligned}\cr{E}&=22+160e^{-0.5}-112\\&=160e^{-0.5}-90\approx7.04\end{aligned}\]

To find the concavity, differentiate the equation with respect to \(t\). Then replace \(\frac{dT}{dt}\) by the right side:

\[\frac{d^2T}{dt^2}=-0.05\,\frac{dT}{dt}=0.0025\,(T-22)\]

This is positive wherever \(T>22\). The constant \(T=22\) solves the equation, and the rate is a polynomial in \(T\), so no other solution meets it (topic 7.4). The solutions through the corners, where \(T\) is 182, 142 and 112, therefore stay above 22 and are concave up. The approximation is an underestimate, as the positive error shows.

Each example is one of the four skills of topic 7.5 in Which & Why: AP Calculus.