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 is known (see the picture on top right). Then, from the differential equation, the slope to the curve at
can be computed, and so, the tangent line.
Take a small step along that tangent line up to a point Along this small step, the slope does not change too much, so
will be close to the curve. If we pretend that
is still on the curve, the same reasoning as for the point
above can be used. After several steps, a polygonal curve
is computed. In general, this curve does not diverge too far from the original unknown curve, and the error between the two curves can be made small if the step size is small enough and the interval of computation is finite:
Choose a value for the size of every step and set
. Now, one step of the Euler method from
to
The value of is an approximation of the solution to the ODE at time
. The Euler method is explicit i.e. the solution
is an explicit function of
for
.
While the Euler method integrates a first-order ODE, any ODE of order N can be represented as a first-order ODE: to treat the equation
-
,
we introduce auxiliary variables and obtain the equivalent equation
This is a first-order system in the variable and can be handled by Euler’s method or, in fact, by any other scheme for first-order systems
Example
Given the initial value problem
we would like to use the Euler method to approximate
Using step size equal to 1 (h = 1)
The Euler method is
so first we must compute . In this simple differential equation, the function
is defined by
. We have
By doing the above step, we have found the slope of the line that is tangent to the solution curve at the point . Recall that the slope is defined as the change in
divided by the change in
, or
.
The next step is to multiply the above value by the step size , which we take equal to one here:
Since the step size is the change in , when we multiply the step size and the slope of the tangent, we get a change in
value. This value is then added to the initial
value to obtain the next value to be used for computations.
The above steps should be repeated to find ,
and
.
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.
-
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 . The exact solution of the differential equation is
, so
. Thus, the approximation of the Euler method is not very good in this case. However, as the figure shows, its behaviour is qualitatively right.
Using other step sizes
As suggested in the introduction, the Euler method is more accurate if the step size is smaller. The table below shows the result with different step sizes. The top row corresponds to the example in the previous section, and the second row is illustrated in the figure.
-
step size result of Euler’s method error 1 16 38.598 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 and the Euler approximation. In the bottom of the table, the step size is half the step size in the previous row, and the error is also approximately half the error in the previous row.
Other methods, such as the mid point method also illustrated in the figures, behave more favourably : the 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, people usually employ alternative, higher-order methods such as runge kutta method or linear multi step methods , especially if a high accuracy is desired
Derivation
The Euler method can be derived in a number of ways. Firstly, there is the geometrical description mentioned above.
Another possibility is to consider the taylor expansion of the function around
:
The differential equation states that . If this is substituted in the Taylor expansion and the quadratic and higher-order terms are ignored, the Euler method arises The Taylor expansion is used below to analyze the error committed by the Euler method, and it can be extended to produce runge-kutta method
A closely related derivation is to substitute the forward finite differences formula for the derivative,
in the differential equation . Again, this yields the Euler method. A similar computation leads to the midpoint rule and the backward euler method
Finally, one can integrate the differential equation from to
and apply the fundamental theorem of calcus to get:
Now approximate the integral by the left-hand rectangle method (with only one rectangle):