Differential Equations

Euler’s Method: Formula and Step-by-Step Example

Euler’s Method: Formula and Step-by-Step Example — CalculusCalc cover image

Euler’s method approximates the solution of a first-order differential equation

$$y' = F(x, y), \qquad y(x_0) = y_0$$

by taking small straight-line steps along the slope field. With step size \( h \):

$$x_{n+1} = x_n + h, \qquad y_{n+1} = y_n + h\,F(x_n, y_n)$$

In words: new value equals old value plus step size times slope. This guide explains why that works, walks through six worked examples, shows how big the error is and how to shrink it, and covers the traps that catch students on exams.

The idea

At each point you know the slope, \( F(x_n, y_n) \). Follow the tangent line for a short distance \( h \): that’s a linear approximation of the solution curve. Then recompute the slope at the new point and repeat.

Think of walking across a slope field in the dark with a compass that shows the local direction. You read the arrow, take one stride in that direction, read the arrow again, and take another stride. Short strides keep you close to the true path; long strides let you drift off it, because the direction keeps changing while you walk straight.

Where the formula comes from

There are two quick ways to derive it, and both tell you something about the error.

From the tangent line. Near \( x_n \), the solution satisfies \( y(x_n + h) \approx y(x_n) + h\,y'(x_n) \). The differential equation says \( y'(x_n) = F(x_n, y(x_n)) \). Replace the unknown exact value \( y(x_n) \) with your current estimate \( y_n \), and you get the Euler formula. The first term dropped from the Taylor series is \( \frac{h^2}{2}y''(x_n) \), so each step makes an error roughly proportional to \( h^2 \).

From an integral. Integrating \( y' = F \) from \( x_n \) to \( x_{n+1} \) gives

$$y(x_{n+1}) = y(x_n) + \int_{x_n}^{x_{n+1}}F(x, y(x))\,dx$$

Euler’s method approximates that integral by one left-endpoint rectangle, height \( F(x_n, y_n) \) times width \( h \). So Euler’s method is a left Riemann sum in disguise. When \( F \) depends only on \( x \), it is exactly a left Riemann sum.

How to do it by hand

  1. Write down \( x_0 \), \( y_0 \), \( h \), and the number of steps \( N = \frac{x_{\text{end}} - x_0}{h} \).
  2. Compute the slope \( F(x_n, y_n) \) at the current point.
  3. Update: \( y_{n+1} = y_n + h\cdot\text{slope} \) and \( x_{n+1} = x_n + h \).
  4. Repeat until \( x_n \) reaches the target. A table keeps the work organized.

Example 1: a full table

Solve \( y' = x + y \), \( y(0) = 1 \), and estimate \( y(1) \) with \( h = 0.1 \). That’s \( N = \frac{1 - 0}{0.1} = 10 \) steps.

\( n \) \( x_n \) \( y_n \) slope \( x_n + y_n \) \( y_{n+1} = y_n + 0.1\cdot\text{slope} \)
0 0.0 1.0000 1.0000 1.1000
1 0.1 1.1000 1.2000 1.2200
2 0.2 1.2200 1.4200 1.3620
3 0.3 1.3620 1.6620 1.5282
4 0.4 1.5282 1.9282 1.7210

Continuing to \( x = 1 \) (10 steps in total) gives \( y(1) \approx 3.1875 \).

How good is it?

This equation has an exact solution: \( y = 2e^x - x - 1 \), so \( y(1) = 2e - 2 \approx 3.4366 \). Euler’s estimate is about 7% low. The error shrinks roughly in proportion to \( h \):

Step size \( h \) Euler estimate of \( y(1) \) Error
0.1 3.1875 0.249
0.05 3.3066 0.130
0.01 3.4096 0.027

Halving \( h \) roughly halves the error: Euler’s method is first-order accurate. It underestimates here because the solution is concave up, so each tangent line runs below the curve.

Why first order when each step’s error is about \( h^2 \)? Because reaching a fixed endpoint takes \( \frac1h \) steps, and \( \frac1h \) errors of size \( h^2 \) add up to something of size \( h \). This is the practical cost of Euler’s method: ten times the accuracy needs ten times the steps.

The concavity rule is worth remembering. If the solution is concave up, Euler’s method underestimates; if it’s concave down, it overestimates.

Example 2: exponential growth

Estimate \( y(1) \) for \( y' = y \), \( y(0) = 1 \), with \( h = 0.25 \).

Each step multiplies by \( 1 + h \), because \( y_{n+1} = y_n + 0.25y_n = 1.25y_n \). After four steps, \( y(1) \approx 1.25^4 \approx 2.4414 \). The exact value is \( e \approx 2.7183 \).

This example shows exactly what Euler’s method does to growth problems: it replaces continuous growth with compounding at discrete steps. As \( h \to 0 \), \( (1 + h)^{1/h} \to e \), the same limit that defines continuous compounding. You can explore the exact curve with the exponential growth calculator.

Example 3: Newton’s law of cooling

A cup of coffee at 90°C sits in a 20°C room, and its temperature obeys \( T' = -0.1(T - 20) \) with time in minutes. Estimate the temperature after 3 minutes with \( h = 1 \).

  • \( T_1 = 90 - 0.1(70) = 83 \)
  • \( T_2 = 83 - 0.1(63) = 76.7 \)
  • \( T_3 = 76.7 - 0.1(56.7) = 71.03 \)

The exact solution is \( T = 20 + 70e^{-0.1t} \), which gives about 71.86°C at \( t = 3 \). Here the solution is concave up (the cooling slows down), so Euler again comes out low, by less than 1 degree.

Example 4: an equation you can’t solve by hand

The equation \( y' = x^2 + y^2 \), \( y(0) = 0 \), has no solution in terms of elementary functions. Euler’s method doesn’t care. With \( h = 0.1 \):

  • \( y_1 = 0 + 0.1(0^2 + 0^2) = 0 \)
  • \( y_2 = 0 + 0.1(0.1^2 + 0^2) = 0.001 \)
  • \( y_3 = 0.001 + 0.1(0.2^2 + 0.001^2) = 0.0050001 \)

So \( y(0.3) \approx 0.005 \). This is the real reason numerical methods exist: most differential equations that come from science can’t be solved with a formula.

Example 5: logistic population growth

A population follows \( P' = 0.5P\left(1 - \frac{P}{100}\right) \) with \( P(0) = 10 \), time in years. With \( h = 1 \):

  • \( P_1 = 10 + 0.5\cdot10\cdot0.9 = 14.5 \)
  • \( P_2 = 14.5 + 0.5\cdot14.5\cdot0.855 \approx 20.70 \)

Notice the slope depends on \( P \) itself. Early on, growth is nearly exponential; as \( P \) approaches the carrying capacity 100, the factor \( 1 - \frac{P}{100} \) shrinks and the steps get smaller.

Example 6: when the step is too big

Try \( y' = -10y \), \( y(0) = 1 \), with \( h = 0.25 \). Each step multiplies by \( 1 - 10(0.25) = -1.5 \), so the estimates are \( 1, -1.5, 2.25, -3.375, \dots \)

The true solution \( e^{-10x} \) decays smoothly to zero, but the Euler values flip sign and grow. For \( y' = -ky \), Euler’s method stays stable only when \( |1 - kh| < 1 \), which means \( h < \frac2k \). Here that’s \( h < 0.2 \). Equations with fast-decaying parts like this are called stiff, and they need either tiny steps or implicit methods.

Better methods

  • Improved Euler (Heun’s method): average the slopes at the start and end of each step. Error shrinks like \( h^2 \). For Example 1’s first step, the start slope is 1, a trial Euler step gives \( y = 1.1 \), the end slope is \( 0.1 + 1.1 = 1.2 \), and the average gives \( y_1 = 1 + 0.1\cdot1.1 = 1.11 \). The exact value is 1.11034, far closer than Euler’s 1.1.
  • Runge–Kutta (RK4): four slope samples per step. Error shrinks like \( h^4 \). With \( h = 0.1 \) it gets \( y(1) \) right to about 5 decimal places (error ≈ 0.000004), and it’s the standard choice in practice.

Euler’s method is still worth learning well: every better method is built from the same “step along a slope” idea, just with smarter slopes.

Common mistakes

  • Using the wrong point for the slope. The slope comes from the start of the step, \( F(x_n, y_n) \), not \( F(x_{n+1}, y_n) \).
  • Forgetting to multiply by \( h \). The update is \( y_n + h\cdot\text{slope} \), not \( y_n + \text{slope} \).
  • Miscounting steps. Reaching \( x = 1 \) from \( x = 0 \) with \( h = 0.1 \) takes 10 steps. Stopping at \( x_9 \) is a common off-by-one error; track \( x_n \) in your table.
  • Rounding too early. Carry at least four decimals in intermediate values. Rounding each step compounds the error.
  • Ignoring \( y \) in the slope. When \( F \) depends on \( y \), each slope uses your latest estimate, so you can’t compute all the slopes first.

Where Euler’s method is used

  • Differential equations with no closed-form solution.
  • Physics simulations and games (position updated from velocity each frame).
  • Population models like logistic growth \( P' = kP\left(1 - \frac PM\right) \).
  • Teaching: it shows exactly what a slope field means.

It shares its core idea with Newton’s method: replace a curve by its tangent line, take a step, and repeat.

Euler’s method calculator (with RK4 comparison)

Enter \( F(x, y) \), the initial condition, the step size and the endpoint:

Physics & Applied#24

Euler's Method ODE Solver

Approximates \(y' = F(x, y)\) step by step, compared with RK4.

The full Euler’s method calculator page shows the complete step table and more examples.

Practice problems

Try these before checking the answers.

  1. \( y' = y,\ y(0) = 1,\ h = 0.5:\ y(1) \)
  2. \( y' = 2x,\ y(0) = 0,\ h = 0.5:\ y(1) \)
  3. \( y' = -y,\ y(0) = 1,\ h = 0.1:\ y(0.2) \)
  4. \( y' = xy,\ y(0) = 1,\ h = 0.5:\ y(1) \)
  5. \( y' = y - x,\ y(0) = 2,\ h = 0.5:\ y(1) \)
  6. For \( y' = -10y \), what is the largest step size that keeps Euler’s method stable?

Answers: (1) \( 2.25 \); (2) \( 0.5 \); (3) \( 0.81 \); (4) \( 1.25 \); (5) \( 4.25 \); (6) \( h < 0.2 \).

For problem 5, the steps are \( 2 + 0.5(2 - 0) = 3 \), then \( 3 + 0.5(3 - 0.5) = 4.25 \). The exact solution is \( y = e^x + x + 1 \), so \( y(1) = e + 2 \approx 4.718 \): with only two big steps, Euler is well off.

FAQ

What step size should I use?

Smaller is more accurate but needs more steps. Halve \( h \) until the answer stops changing at the precision you need.

Can Euler’s method be unstable?

Yes. For equations like \( y' = -50y \), a step that is too large makes the numbers oscillate and blow up even though the true solution decays.

Does Euler’s method overestimate or underestimate?

It depends on concavity. If the solution curve is concave up, the tangent lines lie below it and Euler underestimates. If it’s concave down, Euler overestimates.

What is the error of Euler’s method?

Each step has a local error of order \( h^2 \), and the total (global) error at a fixed endpoint is of order \( h \). Halving the step size roughly halves the final error.

Can Euler’s method solve second-order equations?

Yes, after rewriting. Set \( v = y' \), so \( y'' = G(x, y, v) \) becomes the pair \( y' = v \) and \( v' = G \). Then update both \( y \) and \( v \) with an Euler step each time.

Further reading

Calculators for this topic

Leave a comment

Your email address will not be published. Required fields are marked *