Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 39 ยท Introduction to Differential Equations

Euler's Method

Approximate solutions of differential equations step by step with Euler's method, compare with exact answers, and see how the step size controls error.

Most differential equations have no neat formula for their solution. Yet we can still draw the solution curve to any accuracy we want by following the slope field step by step. The simplest way to do this is Euler's method, named after the Swiss mathematician Leonhard Euler (1707-1783). It is the idea behind many simulations in physics, biology and engineering.

The idea

Suppose dy/dx = F(x, y) and we know the starting point y(xโ‚€) = yโ‚€. At that point the slope is F(xโ‚€, yโ‚€). If we walk a small distance h along the tangent line, y changes by about slope ร— h. So:

Text
xโ‚ = xโ‚€ + h
yโ‚ = yโ‚€ + h ยท F(xโ‚€, yโ‚€)

Now we have a new point (xโ‚, yโ‚). Repeat from there:

Text
yโ‚™โ‚Šโ‚ = yโ‚™ + h ยท F(xโ‚™, yโ‚™)
xโ‚™โ‚Šโ‚ = xโ‚™ + h

Each step replaces the true curve with a short straight segment. Errors accumulate, but smaller steps make the approximation closer.

flowchart LR
    A["Start (x0, y0)"] --> B["Compute slope F(x0, y0)"]
    B --> C["Step: y1 = y0 + h * slope"]
    C --> D["New point (x1, y1)"]
    D --> B

Euler's method follows the tangent line for one step, then recomputes the slope.

A hand example

Approximate y(0.4) for dy/dx = y, y(0) = 1, using h = 0.2. The exact solution is y = eหฃ, so the true value is e^0.4 โ‰ˆ 1.4918.

  • Step 1: yโ‚ = 1 + 0.2 ยท 1 = 1.2 (at x = 0.2).
  • Step 2: yโ‚‚ = 1.2 + 0.2 ยท 1.2 = 1.44 (at x = 0.4).

The estimate is 1.44, a bit low. The curve is concave up, so the tangent line always falls below it.

Euler's method in code

Python Euler's method from scratch

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

When h is cut by a factor of 10, the error at x = 1 falls by about a factor of 10 as well. Euler's method is first order: the error is roughly proportional to h. To get a thousand times more accuracy, you need a thousand times more steps.

Seeing the steps

The plot below compares Euler's polygon with the exact curve for dy/dx = y using two step sizes.

Python Euler's polygon versus the exact curve

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

An equation with no easy solution

Euler's method does not care whether the equation can be solved. Try dy/dx = xยฒ + yยฒ, y(0) = 0.5. There is no elementary closed form, but we can still compute an approximation. Here we compare with SciPy's accurate solver.

Python Euler versus a professional solver

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Limits and improvements

  • Accuracy. The error shrinks slowly with h. For long ranges or rapidly changing slopes, Euler can drift badly.
  • Stability. With a large step, Euler's method can oscillate or blow up even when the true solution is stable.
  • Better methods. Improved Euler (Heun's method) averages two slopes per step; the classic Runge-Kutta method (RK4) uses four slopes and its error shrinks like hโด. Professional software uses such methods with automatic step control.

Use Euler's method to understand how simulations work. Use a library solver when you need reliable numbers.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. The Euler update for dy/dx = F(x, y) is

    Move along the tangent line for a step h: the change in y is slope times h.
  2. 2. dy/dx = y, y(0) = 1, h = 0.5. What is yโ‚ by Euler's method?

    yโ‚ = 1 + 0.5 ยท 1 = 1.5.
  3. 3. If you divide h by 10, the global error of Euler's method falls by roughly

    Euler's method is first order, so the error is roughly proportional to h.
  4. 4. For a concave-up solution, Euler's estimates are typically

    The tangent line lies below a concave-up curve, so each step underestimates.

Summary

  • Euler's method steps along tangent lines: yโ‚™โ‚Šโ‚ = yโ‚™ + h F(xโ‚™, yโ‚™).
  • It works even for equations with no closed-form solution.
  • The error is roughly proportional to h; smaller steps are more accurate but need more work.
  • Methods such as RK4 give much better accuracy for the same effort.

Next: Growth, Decay and Logistic Models