The following sections are concerned with the theory underlying the numerical solution of ODEs such as numerical differentiation and Euler’s method.
Recall from the previous unit ‘Basic calculus in MATLAB’ that the derivative of a function
with respect to the variable
can be approximated by
the backward difference formula; or
the forward difference formula.
where
is small.
The smaller
is, the better the approximation.
The notation here is slightly different from unit 3, since we are using
.
We wish to solve the first order ODE
subject to the initial condition
on the domain
We will do this using Euler’s method and proceed as follows:
The first step is to divide the domain up into
equally sized intervals of size
.
Then we define
,
and
, and let
.
We now want to find a sequence of numbers
such that
.
Using the approximations for the derivative from above we can approximate the first order initial value problem by
.
If we know
, then rearranging this gives a formula for calculating
given
.
There are various options for evaluating
which are discussed now.
Evaluating
at
gives
which can be rearranged to give an explicit formula for
,
which is known as the forward Euler method.
Evaluating
at
gives
which can be rearranged to give an implicit formula for
,
which is known as the backward Euler method.
In general, this system is non-linear in
.
It is usually simpler to work out the forward Euler than the backward Euler approximation, but it is often possible to use a coarser mesh with the backward Euler method, since it remains stable for a larger step size.
We can extend this to solve systems of first-order ODEs by treating
as a vector (
) and
as a vector of functions (
).