Skip to main content
Examonaut

Topic 6 · Lesson 1 of 4

First order differential equations

Notation

Start at (x0,y0)(x_0, y_0) and take steps of length hh: x1=x0+hx_1 = x_0 + h, x2=x0+2hx_2 = x_0 + 2h, and so on. Write yry_r for the approximate value of yy at xrx_r, and (dydx)r\left(\frac{dy}{dx}\right)_r for the gradient found by putting xrx_r and yry_r into the differential equation.

Euler's method

Near xrx_r the curve is close to its tangent. Following the tangent for a distance hh:

yr+1≈yr+h(dydx)ry_{r+1} \approx y_r + h\left(\frac{dy}{dx}\right)_r

This comes from the approximation (dydx)r≈yr+1−yrh\left(\frac{dy}{dx}\right)_r \approx \frac{y_{r+1} - y_r}{h}, the gradient of the chord from xrx_r to xr+1x_{r+1}.

Worked example

Euler's method

Given dydx=x2−y\frac{dy}{dx} = x^2 - y with y=1y = 1 at x=0x = 0, use h=0.1h = 0.1 to estimate yy at x=0.2x = 0.2.

Show solution
  1. (dydx)0=0−1=−1\left(\frac{dy}{dx}\right)_0 = 0 - 1 = -1, so y1=1+0.1×(−1)=0.9y_1 = 1 + 0.1 \times (-1) = 0.9.
  2. (dydx)1=0.01−0.9=−0.89\left(\frac{dy}{dx}\right)_1 = 0.01 - 0.9 = -0.89, so y2=0.9+0.1×(−0.89)=0.811y_2 = 0.9 + 0.1 \times (-0.89) = 0.811.
  3. y(0.2)≈0.811y(0.2) \approx 0.811.

A table with columns xrx_r, yry_r, (dydx)r\left(\frac{dy}{dx}\right)_r and yr+1y_{r+1} keeps the working clear.

The midpoint formula

A better approximation to the gradient at xrx_r uses the points on either side, the gradient of the chord from xr−1x_{r-1} to xr+1x_{r+1}:

(dydx)r≈yr+1−yr−12h,soyr+1≈yr−1+2h(dydx)r\left(\frac{dy}{dx}\right)_r \approx \frac{y_{r+1} - y_{r-1}}{2h}, \quad \text{so} \quad y_{r+1} \approx y_{r-1} + 2h\left(\frac{dy}{dx}\right)_r

Each new value needs the two before it, so the formula cannot start on its own. Find y1y_1 another way (often one step of Euler's method, or a value given in the question), then continue with the midpoint formula.

Worked example

The midpoint formula

For the same equation, dydx=x2−y\frac{dy}{dx} = x^2 - y, y0=1y_0 = 1, use Euler's method for y1y_1 and then the midpoint formula to estimate yy at x=0.2x = 0.2 and x=0.3x = 0.3, with h=0.1h = 0.1.

Show solution
  1. As before, y1=0.9y_1 = 0.9.
  2. (dydx)1=0.01−0.9=−0.89\left(\frac{dy}{dx}\right)_1 = 0.01 - 0.9 = -0.89, so y2=y0+0.2×(−0.89)=0.822y_2 = y_0 + 0.2 \times (-0.89) = 0.822.
  3. (dydx)2=0.04−0.822=−0.782\left(\frac{dy}{dx}\right)_2 = 0.04 - 0.822 = -0.782, so y3=y1+0.2×(−0.782)=0.7436y_3 = y_1 + 0.2 \times (-0.782) = 0.7436.

The exact solution is y=x2−2x+2−e−xy = x^2 - 2x + 2 - e^{-x}, which gives y(0.2)=0.8213y(0.2) = 0.8213 and y(0.3)=0.7492y(0.3) = 0.7492. The midpoint value at x=0.2x = 0.2 is much closer than Euler's 0.811.

Accuracy

  • Errors build up with each step, so estimates get worse the further you go.
  • Halving hh roughly halves the error of Euler's method, at the cost of twice as many steps.
  • Euler's method is poor where the gradient changes quickly, because the tangent soon leaves the curve.
  • Percentage error =∣estimate−exact∣∣exact∣×100%= \frac{|\text{estimate} - \text{exact}|}{|\text{exact}|} \times 100\%.

Practise this topic

Both are part of Premium.