5.16 Euler's method

5.16 Euler's method

IB Maths: Applications and Interpretation HL: Revision notes

Studying this course? Keep your progress in one place.

Key facts

  • Euler's method approximates the solution of dydx=f(x,y)\frac{dy}{dx}=f(x,y) by following tangents in steps of length hh.
  • xn+1=xn+hx_{n+1}=x_n+h and yn+1=yn+h f(xn,yn)y_{n+1}=y_n+h\,f(x_n,y_n): always use the values at the start of the step.
  • A smaller step length is more accurate but needs more steps; it is never exact.
  • Where the solution is concave up, Euler underestimates; concave down, it overestimates.
  • For a coupled system, update tt, xx and yy together using the old values.

What Euler does

It builds an approximate solution by following the tangent for a short step, then recalculating the gradient.

Many differential equations have no neat formula for the solution. Euler's method builds a numerical approximation instead. Given dydx=f(x,y)\frac{dy}{dx}=f(x,y) and an initial condition (x0,y0)(x_0,y_0), the equation gives the gradient at any point.

Follow the tangent for a short horizontal distance hh, the step length, then recalculate the gradient and repeat. The result is a list of points (x0,y0),(x1,y1),…(x_0,y_0),(x_1,y_1),\dots joined by short straight segments.

  1. 1

    Find the gradient

    Substitute (xn,yn)(x_n,y_n) into f(x,y)f(x,y)

  2. 2

    Follow the tangent

    Move hh along xx and h fh\,f along yy

  3. 3

    Record the new point

    This is (xn+1,yn+1)(x_{n+1},y_{n+1})

Then back to step 1

One Euler step, repeated

Which gradient does a step use?

Formulae and an example

Each step adds hh to xx and adds h×h\times gradient to yy.

For dydx=f(x,y)\frac{dy}{dx}=f(x,y) with y(x0)=y0y(x_0)=y_0 and step length hh, use the recurrence below. Example: dydx=x+y\frac{dy}{dx}=x+y, y(0)=1y(0)=1, h=0.1h=0.1.

  • y1=1+0.1(0+1)=1.1y_1=1+0.1(0+1)=1.1 at x=0.1x=0.1
  • y2=1.1+0.1(0.1+1.1)=1.22y_2=1.1+0.1(0.1+1.1)=1.22 at x=0.2x=0.2
  • y3=1.22+0.1(0.2+1.22)=1.362y_3=1.22+0.1(0.2+1.22)=1.362 at x=0.3x=0.3

So y(0.3)≈1.36y(0.3)\approx1.36. The true value is 1.401.40 (3 s.f.): close, not exact.

00.20.40.60.811.21.400.10.20.3xy
  • Euler (h = 0.1)
  • True solution
Euler estimates against the true solution y = 2eˣ − x − 1. Euler stays below the curve.
  • xn+1x_{n+1}xn+hx_n+h
  • yn+1y_{n+1}yn+h f(xn,yn)y_n+h\,f(x_n,y_n)

dydx=2y\frac{dy}{dx}=2y, y(0)=3y(0)=3, h=0.5h=0.5. What is y1y_1?

Spreadsheet or GDC

Enter the recurrence in a spreadsheet or GDC, fill down, and round only the final answer.

Repeated steps are slow by hand, so examinations use permissible technology. In a spreadsheet, put x0x_0 and y0y_0 in the first row. In the next row type the recurrences, for example =A2+0.1 for xx and =B2+0.1*(A2+B2) for yy, then fill down. Most GDCs can do this with a recursive sequence or table mode.

Keep full precision and round only the final answer to 3 significant figures. A spreadsheet is also the quickest way to answer "when does yy first exceed...?": read down the column.

  1. 1

    Enter the start

    x0x_0 and y0y_0 in row 1

  2. 2

    Type the recurrences

    one formula for xx, one for yy

  3. 3

    Fill down

    one row per step

  4. 4

    Read the answer

    round at the end to 3 s.f.

Euler on a spreadsheet

When should you round?

Accuracy and step length

A smaller step length is more accurate; the sign of the error follows the curvature.

Each step replaces a curve by a tangent, so a small error is made, and errors build up. A smaller step length hh gives a more accurate estimate but needs more steps. Halving hh roughly halves the final error.

If the true solution is concave up, the tangent lies below the curve and Euler underestimates. If concave down, it overestimates. In the example the gradient x+yx+y increases, so 1.362<1.401.362<1.40.

00.20.40.60.811.21.40.30.150.10.050.025Step length hEstimate of y(0.3)
Euler estimates of y(0.3) for dy/dx = x + y: smaller steps approach the true value 1.3997.

The true solution is concave down. Euler gives...

Coupled systems

Step tt, xx and yy together, always using the old values on the right.

Two quantities that depend on each other give a coupled system: dxdt=f1(x,y,t)\frac{dx}{dt}=f_1(x,y,t) and dydt=f2(x,y,t)\frac{dy}{dt}=f_2(x,y,t). Euler's method steps tt, xx and yy together, and both new values use the OLD xnx_n and yny_n.

Example: dxdt=−y\frac{dx}{dt}=-y, dydt=x\frac{dy}{dt}=x, x0=1x_0=1, y0=0y_0=0, h=0.1h=0.1. Then x1=1+0.1(0)=1x_1=1+0.1(0)=1 and y1=0+0.1(1)=0.1y_1=0+0.1(1)=0.1. Next x2=1+0.1(−0.1)=0.99x_2=1+0.1(-0.1)=0.99 and y2=0.1+0.1(1)=0.2y_2=0.1+0.1(1)=0.2.

−1.5−1−0.50.511.5−1.5−1−0.50.511.5xy(x₀, y₀) = (1, 0)(1, 0.1)(0.99, 0.2)True path
For dx/dt = −y, dy/dt = x the true path is a circle. The first Euler steps (h = 0.1) move along it, slightly outside.
  • xn+1x_{n+1}xn+h f1(xn,yn,tn)x_n+h\,f_1(x_n,y_n,t_n)
  • yn+1y_{n+1}yn+h f2(xn,yn,tn)y_n+h\,f_2(x_n,y_n,t_n)
  • tn+1t_{n+1}tn+ht_n+h

In the example, what is y1y_1?

Predator-prey models

Each term is either growth or loss, and the interaction terms xyxy need both species to meet.

With prey xx and predators yy a common model is dxdt=ax−bxy\frac{dx}{dt}=ax-bxy and dydt=cxy−dy\frac{dy}{dt}=cxy-dy.

Populations are constant when both rates are zero: y=aby=\frac{a}{b} and x=dcx=\frac{d}{c}, the non-zero equilibrium.

Example: dxdt=0.6x−0.03xy\frac{dx}{dt}=0.6x-0.03xy, dydt=0.02xy−0.5y\frac{dy}{dt}=0.02xy-0.5y with x=50x=50, y=10y=10 gives rates 1515 and 55, so with h=0.2h=0.2: x1=53x_1=53, y1=11y_1=11. A spreadsheet then shows cycles, with predators peaking after the prey.

02040608001234567891011121314Time tPopulation
  • Prey x
  • Predators y
Euler's method with h = 0.2 for dx/dt = 0.6x − 0.03xy, dy/dt = 0.02xy − 0.5y from x = 50, y = 10 (values every 1 unit of time). Predators peak after the prey.

Prey xx

Increases:
axax: growth with plenty of food
Decreases:
−bxy-bxy: eaten by predators

Predators yy

Increases:
cxycxy: growth from eating prey
Decreases:
−dy-dy: deaths

In dxdt=ax−bxy\frac{dx}{dt}=ax-bxy, what does −bxy-bxy represent?

Try an exam question

Euler's method with step length h=0.1h=0.1 is used to solve dydx=x+y\frac{dy}{dx}=x+y with y(0)=1y(0)=1. Find an estimate of y(0.2)y(0.2), and state with a reason whether it is an overestimate or an underestimate.

[4 marks]

That's the notes covered.

Carry on to the next subtopic.

Try a question

Find the approximation to yy when x=0.5x=0.5.

1 mark, marked against the mark scheme

Revision notes