In mathematics and computational science, the Euler method (also called the forward Euler method) is a first-order numerical procedure for solving ordinary differential equations (ODEs) with a given initial value. It is the most basic explicit method for numerical integration of ordinary differential equations and is the simplest Runge–Kutta method. The Euler method is named after Leonhard Euler, who first proposed it in his book Institutionum calculi integralis (published 1768–1770).
The Euler method is a first-order method, which means that the local error (error per step) is proportional to the square of the step size, and the global error (error at a given time) is proportional to the step size. The Euler method often serves as the basis to construct more complex methods, e.g., predictor–corrector method.
Consider the problem of calculating the shape of an unknown curve which starts at a given point and satisfies a given differential equation. Here, a differential equation can be thought of as a formula by which the slope of the tangent line to the curve can be computed at any point on the curve, once the position of that point has been calculated.
The idea is that while the curve is initially unknown, its starting point, which we denote by
A0,
A0
Take a small step along that tangent line up to a point
A1.
A1
A1
A0
A0A1A2A3...
When given the values for
t0
y(t0)
y
t
y
y'(t)=fl(t,y(t)r)
y0=y(t0)
h
tn=t0+nh
tn+1=tn+h
yn+1
yn
tn
yn+1=yn+hf(tn,yn).
The value of
yn
tn
yn ≈ y(tn)
yn+1
yi
i\leqn
While the Euler method integrates a first-order ODE, any ODE of order
N
N
y(N+1)(t)=f\left(t,y(t),y'(t),\ldots,y(N)(t)\right),
as well as
h
t0
y0,y'0,...,
(N) | |
y | |
0 |
\vec{y}i+1=\begin{pmatrix}yi+1\ y'
(N-1) | |
\ \vdots\ y | |
i+1 |
(N) | |
\ y | |
i+1 |
\end{pmatrix} =\begin{pmatrix}yi+h ⋅ y'i\ y'i+h ⋅ y''i\
(N-1) | |
\vdots\ y | |
i |
+h ⋅
(N) | |
y | |
i |
(N) | |
\ y | |
i |
+h ⋅ f\left(ti,yi,y'i,\ldots,
(N) | |
y | |
i\right) |
\end{pmatrix}
These first-order systems can be handled by Euler's method or, in fact, by any other scheme for first-order systems.
Given the initial value problem
y'=y, y(0)=1,
we would like to use the Euler method to approximate
y(4)
The Euler method is
yn+1=yn+hf(tn,yn).
so first we must compute
f(t0,y0)
f
f(t,y)=y
f(t0,y0)=f(0,1)=1.
By doing the above step, we have found the slope of the line that is tangent to the solution curve at the point
(0,1)
y
t
The next step is to multiply the above value by the step size
h
h ⋅ f(y0)=1 ⋅ 1=1.
Since the step size is the change in
t
y
y
y0+hf(y0)=y1=1+1 ⋅ 1=2.
y2
y3
y4
\begin{align} y2&=y1+hf(y1)=2+1 ⋅ 2=4,\\ y3&=y2+hf(y2)=4+1 ⋅ 4=8,\\ y4&=y3+hf(y3)=8+1 ⋅ 8=16. \end{align}
Due to the repetitive nature of this algorithm, it can be helpful to organize computations in a chart form, as seen below, to avoid making errors.
n | yn | tn | f(tn,yn) | h | \Deltay | yn+1 | |
---|---|---|---|---|---|---|---|
0 | 1 | 0 | 1 | 1 | 1 | 2 | |
1 | 2 | 1 | 2 | 1 | 2 | 4 | |
2 | 4 | 2 | 4 | 1 | 4 | 8 | |
3 | 8 | 3 | 8 | 1 | 8 | 16 |
The conclusion of this computation is that
y4=16
y(t)=et
y(4)=e4 ≈ 54.598
h
As suggested in the introduction, the Euler method is more accurate if the step size
h
step size | result of Euler's method | error | |
---|---|---|---|
1 | 16.00 | 38.60 | |
0.25 | 35.53 | 19.07 | |
0.1 | 45.26 | 9.34 | |
0.05 | 49.56 | 5.04 | |
0.025 | 51.98 | 2.62 | |
0.0125 | 53.26 | 1.34 |
The error recorded in the last column of the table is the difference between the exact solution at
t=4
Other methods, such as the midpoint method also illustrated in the figures, behave more favourably: the global error of the midpoint method is roughly proportional to the square of the step size. For this reason, the Euler method is said to be a first-order method, while the midpoint method is second order.
We can extrapolate from the above table that the step size needed to get an answer that is correct to three decimal places is approximately 0.00001, meaning that we need 400,000 steps. This large number of steps entails a high computational cost. For this reason, higher-order methods are employed such as Runge–Kutta methods or linear multistep methods, especially if a high accuracy is desired.
For this third-order example, assume that the following information is given:
\begin{align}& y'''+4ty''-t2y'-(\cos{t})y=\sin{t} \ & t0=0 \ & y0=y(t0)=2 \ & y'0=y'(t0)=-1 \ & y''0=y''(t0)=3\ & h=0.5\end{align}
From this we can isolate y''' to get the equation:
f\left(t,y,y',y''\right)=y'''=\sin{t}+(\cos{t})y+t2y'-4ty''
Using that we can get the solution for
\vec{y}1
\vec{y}1
\vec{y}2
\vec{y}i
The Euler method can be derived in a number of ways.
(1) Firstly, there is the geometrical description above.
(2) Another possibility is to consider the Taylor expansion of the function
y
t0
y(t0+h)=y(t0)+hy'(t0)+\tfrac12h2y''(t0)+O\left(h3\right).
The differential equation states that
y'=f(t,y)
The Taylor expansion is used below to analyze the error committed by the Euler method, and it can be extended to produce Runge–Kutta methods.
(3) A closely related derivation is to substitute the forward finite difference formula for the derivative,
y'(t0) ≈
y(t0+h)-y(t0) | |
h |
in the differential equation
y'=f(t,y)
A similar computation leads to the midpoint method and the backward Euler method.
(4) Finally, one can integrate the differential equation from
t0
t0+h
y(t0+h)-y(t0)=
t0+h | |
\int | |
t0 |
fl(t,y(t)r)dt.
Now approximate the integral by the left-hand rectangle method (with only one rectangle):
t0+h | |
\int | |
t0 |
fl(t,y(t)r)dt ≈ hfl(t0,y(t0)r).
Combining both equations, one finds again the Euler method.
This line of thought can be continued to arrive at various linear multistep methods.
The local truncation error of the Euler method is the error made in a single step. It is the difference between the numerical solution after one step,
y1
t1=t0+h
y1=y0+hf(t0,y0).
For the exact solution, we use the Taylor expansion mentioned in the section Derivation above:
y(t0+h)=y(t0)+hy'(t0)+\tfrac12h2y''(t0)+O\left(h3\right).
The local truncation error (LTE) introduced by the Euler method is given by the difference between these equations:
LTE=y(t0+h)-y1=\tfrac12h2y''(t0)+O\left(h3\right).
This result is valid if
y
This shows that for small
h
h2
A slightly different formulation for the local truncation error can be obtained by using the Lagrange form for the remainder term in Taylor's theorem. If
y
\xi\in[t0,t0+h]
LTE=y(t0+h)-y1=\tfrac12h2y''(\xi).
In the above expressions for the error, the second derivative of the unknown exact solution
y
y'=f(t,y)
y''(t0)=
\partialf | |
\partialt |
l(t0,y(t0)r)+
\partialf | |
\partialy |
l(t0,y(t0)r)fl(t0,y(t0)r).
The global truncation error is the error at a fixed time
ti
h2
h
This intuitive reasoning can be made precise. If the solution
y
f
|y(ti)-yi|
|y(ti)-yi|\le
hM | |
2L |
L(ti-t0) | |
\left(e |
-1\right)
where
M
y
L
f
y'(t)=f(t,y)
t
y(t)
t
The precise form of this bound is of little practical importance, as in most cases the bound vastly overestimates the actual error committed by the Euler method. What is important is that it shows that the global truncation error is (approximately) proportional to
h
If we have the differential equation
y'=1+(t-y)2
y=t+
1 | |
t-1 |
M
L
2\let\le3
Notice that t0 is equal to 2 because it is the lower bound for t in
2\let\le3
The Euler method can also be numerically unstable, especially for stiff equations, meaning that the numerical solution grows very large for equations where the exact solution does not. This can be illustrated using the linear equation
y'=-2.3y, y(0)=1.
y(t)=e-2.3t
t\toinfty
h=1
h=0.7
If the Euler method is applied to the linear equation
y'=ky
hk
l\{z\inC||z+1|\le1r\},
k=-2.3
h=1
hk=-2.3
This limitation — along with its slow convergence of error with
h
In step
n
\varepsilonyn
\varepsilon
A simple modification of the Euler method which eliminates the stability problems noted above is the backward Euler method:
yn+1=yn+hf(tn+1,yn+1).
f
yn+1
Other modifications of the Euler method that help with stability yield the exponential Euler method or the semi-implicit Euler method.
More complicated methods can achieve a higher order (and more accuracy). One possibility is to use more function evaluations. This is illustrated by the midpoint method which is already mentioned in this article:
yn+1=yn+hf\left(tn+\tfrac12h,yn+\tfrac12hf(tn,yn)\right)
The other possibility is to use more past values, as illustrated by the two-step Adams–Bashforth method:
yn+1=yn+\tfrac32hf(tn,yn)-\tfrac12hf(tn-1,yn-1).
In the film Hidden Figures, Katherine Goble resorts to the Euler method in calculating the re-entry of astronaut John Glenn from Earth orbit.[3]