Menu
Sign up Sign in

AI HL · AHL 9

Differential Equations

AHL 9.5

Euler's method for dy/dx = f(x, y)

AHL 9.5

Euler's method for dy/dx = f(x, y)

Target: I can write the Euler formulas x(n+1) = x(n) + h and y(n+1) = y(n) + h f(x(n), y(n)). (+3 more)

By the end of this section

Key points

The method

  • Start from a known point (x₀, y₀). The equation dy/dx = f(x, y) gives the gradient there.
  • Euler's method: x(n+1) = x(n) + h and y(n+1) = y(n) + h × f(x(n), y(n)).
  • Use the gradient at the point you are leaving. The change in y is about h times that gradient.
  • Both formulas use the old x(n) and y(n). The gradient is never found at the new point.

Setting it out

  • Write the two formulas first, with the numbers for h and f put in.
  • Make a table of n, x(n) and y(n). Row 0 is the start point.
  • If there are many steps, show the first row, the last row and a few between.
  • Keep the full calculator value in the table. Round only the final answer, to 3 significant figures.

Checks

  • Count the steps: from x = 0 to x = 1 with h = 0.2 is 5 steps, so 5 rows after the start.
  • Check row 1 by hand. A wrong formula in row 1 is wrong in every row.
  • In a spreadsheet the y formula must refer to the y cell of the row above.

On the calculator

Euler's method with sequences

  • Enter two sequences: one for x(n) that adds h each time, one for y(n) that adds h times the gradient.
  • Give the start values for x and y.
  • Open the table and read the row where x reaches the value you need.

Screenshot and video to come

Euler's method in a spreadsheet

  • Put n in column A, x in column B and y in column C. Row 1 holds the start values.
  • In row 2 the x cell adds h to the x above. The y cell adds h times the gradient, using the old x and y cells.
  • Fill down to the row you need. Check that the formula refers to the y cell, not the x cell.

Screenshot and video to come

Explore: Euler's method, one step at a time

Choose an equation and a step length h. Drag the orange start point if you like. Press Next: the gradient at the point you are leaving gives one straight piece. Tick the box to compare with the true curve.

Step length h


nxydy/dxnew y
Step length h
Steps taken
Euler's y
True value of y
Error
Percentage error

The table shows 4 decimal places; the calculation keeps more. Dots and ink line: Euler's method. Orange: the start point and the latest piece. Teal: the true curve, with its error at the last point.

Press Next to take the first step.

  1. Press Next once with h = 0.5. Which point's gradient made the first piece: the one you left or the one you reached? How does the working show it?
  2. Tick the true curve. Run to x = 2 with h = 1, then 0.5, 0.2 and 0.1. What happens to the error each time? Why does a shorter step follow the curve more closely?
  3. Choose 0.5y and look at the true curve. Is Euler's estimate above or below it? What does the bend of the curve have to do with that?
  4. Choose 3x − y. Where is the Euler path closest to the true curve, and where is it furthest away? Why?

Worked examples

Problems like the ones in class. Pick one, try it, then open the working.
A linear equation

Use Euler's method with step length \(h=0.2\) to estimate \(y(1)\), given \(\dfrac{dy}{dx}=3x-y\) and \(y(0)=2\).

Working
  1. Write the formulas

    \(x_{n+1}=x_n+0.2\), \(y_{n+1}=y_n+0.2(3x_n-y_n)\)

    h = 0.2. Each new y adds h times the gradient at the point you are leaving.

  2. The first step

    \(y_1=2+0.2(3\times 0-2)=1.6\)

    Start at (0, 2). The gradient there is 3 × 0 − 2 = −2, so y falls by 0.2 × 2.

  3. Run the table

    From the calculator: (0.2, 1.6), (0.4, 1.4), (0.6, 1.36), (0.8, 1.448), (1, 1.6384)

    Use a sequence or a spreadsheet. The last row is x = 1.

  4. 0.20.40.60.811.21.622.42.83.2xy
    The picture

    \(y(1)\approx 1.638\)

    Each step is a straight piece along the gradient you left. The exact curve is the other line.

Video walkthrough coming
A nonlinear equation

Use Euler's method with \(h=0.2\) to estimate \(y(1)\), given \(\dfrac{dy}{dx}=y^2-x\) and \(y(0)=0.5\).

Working
  1. Write the formulas

    \(x_{n+1}=x_n+0.2\), \(y_{n+1}=y_n+0.2(y_n^2-x_n)\)

    The same method. Only the gradient changes: it now has y squared.

  2. The first step

    \(y_1=0.5+0.2(0.5^2-0)=0.55\)

    Use y_n squared, not y_{n+1}. Both x and y are the old values.

  3. Run the table

    From the calculator: (0.2, 0.55), (0.4, 0.5705), (0.6, 0.5556), (0.8, 0.4973), (1, 0.3868)

    Keep full calculator values in the table. Round only the final answer.

  4. The answer

    \(y(1)\approx 0.387\)

    Five steps of 0.2 take x from 0 to 1.

Video walkthrough coming
In a spreadsheet

Set up a spreadsheet to use Euler's method with \(h=0.2\) for \(\dfrac{dy}{dx}=xe^{-y}\) with \(y(0)=1\). Find \(y(1)\).

Working
  1. Label the columns

    A: n. B: x_n. C: y_n. Row 1: 0, 0, 1

    Row 1 is the start (0, 1). Each later row is the next step.

  2. The x column

    B2: =b1+0.2

    x goes up by h each row.

  3. The y column

    C2: =c1+0.2*(b1*e^(-c1))

    The formula uses the y cell (c1) from the row above, not the x cell. Copying the wrong column is the usual slip.

  4. Fill down to x = 1

    From the calculator: (0.2, 1), (0.4, 1.0147), (0.6, 1.0437), (0.8, 1.086), (1, 1.14)

    Fill down five rows. Read y in the row where x = 1.

  5. The answer

    \(y(1)\approx 1.14\)

    Check the first row by hand: y_1 = 1 + 0.2 × (0 × e^(−1)) = 1.

Video walkthrough coming