Math Core

Lesson 3.2 · Differential Equations

Euler's method

Most differential equations can't be solved by separating variables. Equations like dydx=x−y2\dfrac{dy}{dx} = x - y^2 have no neat formula for yy, yet you can still estimate the solution. Euler's method does this by following tangent lines in small steps, and it is a BC-only topic that shows up regularly on the AP exam.

The idea: tangent lines in small steps

You already know the local linear approximation: near a point (x0,y0)(x_0, y_0), a differentiable function is close to its tangent line,

y≈y0+dydx∣(x0, y0)⋅(x−x0).y \approx y_0 + \frac{dy}{dx}\bigg|_{(x_0,\,y_0)} \cdot (x - x_0).

A differential equation dydx=f(x,y)\dfrac{dy}{dx} = f(x, y) gives you that slope at any point, not just at the starting point. So instead of riding a single tangent line a long way (which drifts far from the curve), you take a short step, recompute the slope at the new point, take another short step, and so on.

Euler's method

To approximate the solution of dydx=f(x,y)\dfrac{dy}{dx} = f(x, y) with y(x0)=y0y(x_0) = y_0, choose a step size hh (often written Δx\Delta x). Then repeat:

xn+1=xn+hyn+1=yn+h⋅f(xn,yn)\begin{aligned} x_{n+1} &= x_n + h \\ y_{n+1} &= y_n + h \cdot f(x_n, y_n) \end{aligned}

Each new yy equals the old yy plus (step size) ×\times (slope at the old point). After nn steps, yny_n approximates y(x0+nh)y(x_0 + nh).

The number of steps is the distance you travel divided by the step size. Going from x=0x = 0 to x=1x = 1 with h=0.25h = 0.25 takes 10.25=4\dfrac{1}{0.25} = 4 steps.

Organizing the work in a table

Keep the calculation tidy by recording xx, yy, the slope f(x,y)f(x, y), and the change h⋅f(x,y)h \cdot f(x, y) for each step. AP free-response graders need to see the setup, so write every step, not just the final number.

Worked example: Two steps

Let y=f(x)y = f(x) be the solution of dydx=x+y\dfrac{dy}{dx} = x + y with f(0)=1f(0) = 1. Use Euler's method with two steps of equal size to approximate f(1)f(1).

Solution. Two equal steps from 00 to 11 means h=0.5h = 0.5.

xxyyslope x+yx + yΔy=0.5⋅slope\Delta y = 0.5 \cdot \text{slope}
0011110.50.5
0.50.51.51.52211
112.52.5

So f(1)≈2.5f(1) \approx 2.5.

This equation happens to have the exact solution f(x)=2ex−x−1f(x) = 2e^x - x - 1, so f(1)=2e−2≈3.437f(1) = 2e - 2 \approx 3.437. The estimate is well below the true value. You will see why shortly.

Worked example: Three steps with a smaller step size

Let y=g(x)y = g(x) be the solution of dydx=x−y2\dfrac{dy}{dx} = x - y^2 with g(0)=1g(0) = 1. Use Euler's method with step size 0.10.1 to approximate g(0.3)g(0.3).

Solution. Three steps are needed.

y1=1+0.1 (0−12)=1−0.1=0.9y2=0.9+0.1 (0.1−0.92)=0.9+0.1(−0.71)=0.829y3=0.829+0.1 (0.2−0.8292)=0.829+0.1(−0.487241)≈0.7803\begin{aligned} y_1 &= 1 + 0.1\,(0 - 1^2) = 1 - 0.1 = 0.9 \\ y_2 &= 0.9 + 0.1\,(0.1 - 0.9^2) = 0.9 + 0.1(-0.71) = 0.829 \\ y_3 &= 0.829 + 0.1\,(0.2 - 0.829^2) = 0.829 + 0.1(-0.487241) \approx 0.7803 \end{aligned}

So g(0.3)≈0.780g(0.3) \approx 0.780. This equation is not separable, so a numerical estimate like this is the practical way to get a value.

Common mistake

Evaluate the slope at the start of each step, using the xx and yy values you just computed. The two most common errors are reusing the original slope for every step, and updating xx but forgetting to use the new estimated yy in the slope formula.

Overestimate or underestimate?

Each Euler step follows a tangent line. Whether a tangent line lies above or below the curve depends on concavity:

  • If the solution is concave up, tangent lines lie below the curve, so Euler's method underestimates.
  • If the solution is concave down, tangent lines lie above the curve, so Euler's method overestimates.

To find concavity, compute d2ydx2\dfrac{d^2y}{dx^2} by differentiating the differential equation implicitly, remembering that yy is a function of xx. Then substitute dydx\dfrac{dy}{dx} from the original equation.

In the first example, dydx=x+y\dfrac{dy}{dx} = x + y gives d2ydx2=1+dydx=1+x+y\dfrac{d^2y}{dx^2} = 1 + \dfrac{dy}{dx} = 1 + x + y. Along the solution from (0,1)(0, 1) to x=1x = 1, both xx and yy are positive, so d2ydx2>0\dfrac{d^2y}{dx^2} \gt 0. The curve is concave up, and that explains why 2.52.5 underestimates 3.4373.437.

Worked example: Justifying an overestimate

Let y=h(x)y = h(x) solve dydx=2−y\dfrac{dy}{dx} = 2 - y with h(0)=0h(0) = 0. Use Euler's method with two steps of size 0.50.5 to approximate h(1)h(1), and decide whether the estimate is too large or too small. The exact solution is h(x)=2−2e−xh(x) = 2 - 2e^{-x}.

Solution. First step: slope 2−0=22 - 0 = 2, so y1=0+0.5(2)=1y_1 = 0 + 0.5(2) = 1. Second step: slope 2−1=12 - 1 = 1, so y2=1+0.5(1)=1.5y_2 = 1 + 0.5(1) = 1.5. So h(1)≈1.5h(1) \approx 1.5.

For concavity, d2ydx2=−dydx=−(2−y)=y−2\dfrac{d^2y}{dx^2} = -\dfrac{dy}{dx} = -(2 - y) = y - 2. The solution starts at y=0y = 0 and stays below the equilibrium y=2y = 2, so d2ydx2<0\dfrac{d^2y}{dx^2} \lt 0: the curve is concave down, and Euler's method overestimates. Indeed, h(1)=2−2e−1≈1.264<1.5h(1) = 2 - 2e^{-1} \approx 1.264 \lt 1.5.

The picture shows the two Euler steps as a broken line riding above the concave-down solution curve.

Euler's method with h = 0.5 for dy/dx = 2 − y, y(0) = 0. The broken line lies above the concave-down solution y = 2 − 2e^(−x).Open in grapher →

Accuracy and step size

Smaller steps mean each tangent segment is shorter, so it has less room to drift away from the curve. Halving the step size roughly halves the error of Euler's method, but it doubles the number of steps. On the AP exam you will usually take two or three steps by hand; a calculator program or spreadsheet can take hundreds.

Tip

Before computing, check the step count: (final xx −- initial xx) ÷\div hh. If it isn't a whole number, reread the problem. Also keep full precision between steps and round only at the end, to three decimal places unless told otherwise.

Practice

Practice 1

Let y=f(x)y = f(x) solve dydx=x−2y\dfrac{dy}{dx} = x - 2y with f(0)=1f(0) = 1. Use Euler's method with two steps of equal size to approximate f(1)f(1).

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 2

A pot of soup cools according to dTdt=−0.1(T−20)\dfrac{dT}{dt} = -0.1(T - 20), where TT is the temperature in degrees Celsius and tt is in minutes. At t=0t = 0 the soup is at 9090 degrees. Use Euler's method with two steps of size 22 minutes to approximate the temperature at t=4t = 4.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 3

Let y=f(x)y = f(x) be the solution of dydx=1+xy\dfrac{dy}{dx} = 1 + xy with f(1)=2f(1) = 2. What is the approximation for f(1.4)f(1.4) obtained by using Euler's method with two steps of equal size?

Practice 4

Let y=f(x)y = f(x) solve dydx=x2+y\dfrac{dy}{dx} = x^2 + y with f(1)=0f(1) = 0. Use Euler's method with step size 0.20.2 to approximate f(1.4)f(1.4).

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 5

Let y=f(x)y = f(x) solve dydx=x+y\dfrac{dy}{dx} = \sqrt{x + y} with f(0)=4f(0) = 4. Use Euler's method with two steps of equal size to approximate f(1)f(1). Round to three decimal places.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 6

Let y=f(x)y = f(x) solve dydx=xy\dfrac{dy}{dx} = xy with f(0)=2f(0) = 2. Use Euler's method with step size 0.250.25 to approximate f(1)f(1). Round to three decimal places.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 7

Let y=f(x)y = f(x) solve dydx=x+2y\dfrac{dy}{dx} = x + 2y with f(0)=1f(0) = 1. An Euler's method approximation of f(0.5)f(0.5) uses a positive step size. Which statement is true?