Search

Search papers and lessons

Euler Method

Level 2 · 9 min read

Euler's method solves an ODE numerically by repeatedly following the tangent line for a small step, trading accuracy for simplicity.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Sign in to see your progress

TL;DR

Many differential equations cannot be solved with a formula. Euler's method gets an approximate answer anyway. Start at the known point, measure the slope there, move a short step along that slope, and repeat. Each step is a straight line, so the path is a chain of short segments that bends the way the true solution bends.

The method is crude. Its error shrinks in proportion to the step size, so you need small steps for a good answer. It is still the foundation for almost every numerical ODE solver.

Where you'll see it: in simulating falling objects and circuits in code, in cooling and population models with no closed-form answer, and in the residual-network view of deep learning, where one layer is exactly one Euler step.

Intuition

Walking with a map that only shows slopes

Suppose you know where you are and which way you are heading, but not the whole road. A reasonable plan is to look at the slope under your feet, walk a short distance in that direction, look again, and repeat. You never see the full curve. You only ever know the local direction, and you assume it stays put for the length of one step.

That is the whole idea. An ODE tells you the slope y′y' at every point (t,y)(t, y). You know the starting value y0y_0, so you know the slope there. The tangent line at that point is a good guess for where the solution goes over a short interval of length hh.

Why does this matter? Writing a law of nature as an ODE is usually the clearest description of it, but solving the ODE by hand is often impossible. A computer, however, can follow slopes all day. Euler's method turns the rule "how things change" into a loop a computer can run.

0246810020406080100time (min)temperature (C)
  • exact solution
  • Euler, step 5
  • Euler, step 2.5
A cooling cup of tea. The exact curve is smooth. Euler's method draws straight segments; halving the step makes the segments hug the curve more closely.

The math

The setup

Take an initial value problem: an unknown function y(t)y(t) that obeys

y′(t)=f(t,y),y(t0)=y0.y'(t) = f(t, y), \qquad y(t_0) = y_0.

Here tt is time, yy is the quantity we track, and ff is the rule giving its slope. We want approximate values yn≈y(tn)y_n \approx y(t_n) at times tn=t0+nht_n = t_0 + n h, where hh is a fixed step size.

The update rule

Euler's method is

yn+1=yn+h f(tn,yn),n=0,1,2,…y_{n+1} = y_n + h\,f(t_n, y_n), \qquad n = 0, 1, 2, \ldots

Read it as: new value equals old value plus step size times slope. The slope f(tn,yn)f(t_n, y_n) is evaluated only at the start of the step and then held fixed for the whole step. That is the source of both the simplicity and the error.

Where the formula comes from

Taylor's theorem (see Taylor series) expands the true solution around tnt_n:

y(tn+h)=y(tn)+h y′(tn)+h22 y′′(ξ)y(t_n + h) = y(t_n) + h\,y'(t_n) + \frac{h^2}{2}\,y''(\xi)

for some ξ\xi between tnt_n and tn+ht_n + h. Since y′(tn)=f(tn,y(tn))y'(t_n) = f(t_n, y(t_n)), dropping the last term gives exactly the Euler update. The dropped term is the local error, and it is of size h2h^2.

Order of accuracy

One step makes an error of order h2h^2. Taking N=(T−t0)/hN = (T - t_0)/h steps to reach a fixed time TT accumulates about NN local errors, and N∝1/hN \propto 1/h. So the global error is of order hh. Euler's method is called first-order for this reason. Halving hh roughly halves the error, and reducing the error by a factor of 100 costs about 100 times more steps.

Systems

An ODE system Y′=F(t,Y)\mathbf{Y}' = F(t, \mathbf{Y}) uses the same rule with vectors:

Yn+1=Yn+h F(tn,Yn).\mathbf{Y}_{n+1} = \mathbf{Y}_n + h\,F(t_n, \mathbf{Y}_n).

A second-order equation such as y′′=−yy'' = -y becomes a system by setting v=y′v = y'. Then Y=(y,v)\mathbf{Y} = (y, v) and F(Y)=(v,−y)F(\mathbf{Y}) = (v, -y), and each step updates position and velocity together.

Worked examples

Example
One small problem by hand

Solve y′=yy' = y with y(0)=1y(0) = 1, from t=0t = 0 to t=1t = 1, using step h=0.5h = 0.5. The exact answer is y(1)=e≈2.71828y(1) = e \approx 2.71828.

  1. Here f(t,y)=yf(t, y) = y, so each step is yn+1=yn+0.5 yn=1.5 yny_{n+1} = y_n + 0.5\,y_n = 1.5\,y_n.
  2. Step 1: y1=1.5⋅1=1.5y_1 = 1.5 \cdot 1 = 1.5 at t=0.5t = 0.5.
  3. Step 2: y2=1.5⋅1.5=2.25y_2 = 1.5 \cdot 1.5 = 2.25 at t=1t = 1.
  4. Error: 2.71828−2.25=0.468282.71828 - 2.25 = 0.46828, about 17 percent of the true value.

Now halve the step to h=0.25h = 0.25. The multiplier per step is 1.251.25, and after four steps y4=1.254=2.44141y_4 = 1.25^4 = 2.44141. The error is 0.276880.27688, about 10 percent. Halving hh cut the error by a factor of about 1.7, close to the expected 2. Interpretation: Euler's answer is always too low here, because the true curve bends upward and the tangent lines lie underneath it.

Example
Cooling a cup of tea

A cup of tea starts at 90 ∘C90\,^\circ\text{C} in a room at 20 ∘C20\,^\circ\text{C}. Newton's law of cooling gives T′=−0.1 (T−20)T' = -0.1\,(T - 20) with T(0)=90T(0) = 90, in minutes. Its exact solution is T(t)=20+70 e−0.1tT(t) = 20 + 70\,e^{-0.1t}, so T(10)=20+70 e−1≈45.75T(10) = 20 + 70\,e^{-1} \approx 45.75.

Step h=5h = 5 minutes:

  1. At t=0t = 0: slope =−0.1⋅(90−20)=−7= -0.1 \cdot (90 - 20) = -7. So T1=90+5⋅(−7)=55T_1 = 90 + 5 \cdot (-7) = 55.
  2. At t=5t = 5: slope =−0.1⋅(55−20)=−3.5= -0.1 \cdot (55 - 20) = -3.5. So T2=55+5⋅(−3.5)=37.5T_2 = 55 + 5 \cdot (-3.5) = 37.5.
  3. Euler says 37.537.5 at t=10t = 10. The true value is 45.7545.75, so the error is 8.258.25.

Step h=2.5h = 2.5 takes four steps and ends at 42.1542.15, an error of about 3.63.6. Halving the step cut the error by a factor of about 2.32.3. Interpretation: with a coarse step, Euler predicts the tea cools faster than it really does. For a rough estimate that may be fine; for a precise one, shrink the step or use a better method.

Tradeoffs and failure modes

Euler's method is the right choice when the problem is simple, the step count is cheap, and you want code that fits on one screen. It is the wrong choice when accuracy matters and the step has to be large, or when the system is stiff.

SituationWhat goes wrongBetter choice
Smooth problem, need many digitsError is only order hh; you need tiny stepsRunge-Kutta methods (order 4 is standard)
Stiff system, fast decay plus slow changeEuler becomes unstable unless hh is tinyImplicit methods such as backward Euler
Long simulation of an oscillatorEnergy drifts, amplitude grows slowlySymplectic or higher-order integrators
Quick educational or prototype codeUsually nothingEuler is fine

The stiff case is worth seeing once. Take y′=−50 yy' = -50\,y with y(0)=1y(0) = 1. The true solution decays quickly to zero. With h=0.1h = 0.1, each Euler step multiplies yy by 1−50⋅0.1=−41 - 50 \cdot 0.1 = -4. After one step y=−4y = -4, after two steps y=16y = 16. The numerical solution explodes while the true one vanishes. The fix is to use a step small enough that ∣1−50h∣<1|1 - 50h| \lt 1, which means h<0.04h \lt 0.04, or to switch to an implicit method.

History

Euler's method appears in Leonhard Euler's multi-volume work on integral calculus, published in the late 1760s and early 1770s, where he was systematising the theory of differential equations. Euler needed a way to approximate solutions where no closed form was known, and stepping along tangent lines was the most direct approach available with pencil and paper.

The method was largely a computational tool for a long time. Carl Runge and Martin Kutta, around the 1890s and early 1900s, developed the higher-order schemes that now carry their names by evaluating the slope at several points inside each step. Modern solvers in scientific computing still use that family, and the forward Euler step remains the simplest member of it.

Check yourself

QuestionWrite the Euler update for y′=f(t,y)y' = f(t, y). Which quantity is held constant over one step?Show answer

The update is yn+1=yn+h f(tn,yn)y_{n+1} = y_n + h\,f(t_n, y_n). The slope f(tn,yn)f(t_n, y_n), computed at the start of the step, is held constant for the whole step of length hh. Euler's method never looks at the slope at any point inside the step, which is why its error is only of order hh per step.

QuestionUse Euler's method with h=0.2h = 0.2 to estimate y(0.4)y(0.4) for y′=2yy' = 2y, y(0)=1y(0) = 1. The exact value is e0.8≈2.2255e^{0.8} \approx 2.2255. What is the error?Show answer

Each step multiplies yy by 1+0.2⋅2=1.41 + 0.2 \cdot 2 = 1.4. After two steps, y(0.4)≈1.42=1.96y(0.4) \approx 1.4^2 = 1.96. The error is 2.2255−1.96=0.26552.2255 - 1.96 = 0.2655, roughly 12 percent. Interpretation: the approximation is low, because for a growing function the tangent line always sits below the curve.

QuestionIf you halve the step size, roughly how much does the global error of Euler's method shrink, and why?Show answer

It roughly halves. The global error is of order hh, because each local error is of order h2h^2 and there are about 1/h1/h steps. Halving hh halves the global error and doubles the number of steps, so the cost of each factor of two in accuracy is also a factor of two in work.

QuestionWhy can Euler's method blow up on y′=−50 yy' = -50\,y even though the true solution decays to zero?Show answer

Each step multiplies yy by 1−50h1 - 50h. Unless ∣1−50h∣<1|1 - 50h| \lt 1, the multiplier is larger than 1 in size, and with h=0.1h = 0.1 it equals −4-4, so the iterates grow. The true solution is stable for any step, but the numerical method is only stable for small steps when the system decays fast. This is the stiffness problem.

QuestionA deep residual network computes xk+1=xk+g(xk)x_{k+1} = x_k + g(x_k) for each block kk. Which ODE step does this match, and what does a network with many thin blocks become in the limit?Show answer

It matches one Euler step with h=1h = 1 applied to the ODE x′(t)=g(x(t))\mathbf{x}'(t) = g(\mathbf{x}(t)). Each residual block is one step of the solver. Taking more blocks with a smaller effective step hh approaches the continuous ODE, which is the idea behind residual networks viewed as discretised flows and behind neural ODEs. The continuous limit is what makes the depth of the model a time variable rather than a fixed count.

Sources