Section D.1 Simple ODE Solvers — Derivation
The first order of business is to derive three simple algorithms for generating approximate numerical solutions to the initial value problem
The first is called Euler’s method because it was developed by (surprise!) Euler.
1
Leonhard Euler (1707–1783) was a Swiss mathematician and physicist who spent most of his adult life in Saint Petersberg and Berlin. He gave the name to the ratio of a circle’s circumference to its diameter. He also developed the constant
Subsection D.1.1 Euler’s Method
Our goal is to approximate (numerically) the unknown function
for We are told explicitly the value of namely So we know But we do not know the integrand for On the other hand, if is close then will remain close to So pick a small number and define
2
This will be the case as long as is continuous.
By the above argument
Now we start over from the new point We now know an approximate value for at time If were exactly then the instantaneous rate of change of at time namely would be exactly and would remain close to for close to Defining
we have
We just repeat this argument ad infinitum. Define, for
Suppose that, for some value of we have already computed an approximate value for Then the rate of change of for close to is and
This algorithm is called Euler’s Method. The parameter is called the step size.
Here is a table applying a few steps of Euler’s method to the initial value problem
with step size For this initial value problem
Of course this initial value problem has been chosen for illustrative purposes only. The exact solution is
3
Even if you haven’t learned how to solve initial value problems like this one, you can check that obeys both and
0 | 0.0 | 3.000 | ||
1 | 0.1 | 3.300 | ||
2 | 0.2 | 3.610 | ||
3 | 0.3 | 3.931 | ||
4 | 0.4 | 4.264 | ||
5 | 0.5 | 4.611 |
The exact solution at is to four decimal places. We expect that Euler’s method will become more accurate as the step size becomes smaller. But, of course, the amount of effort goes up as well. If we recompute using we get (after much more work)
Subsection D.1.2 The Improved Euler’s Method
Euler’s method is one algorithm which generates approximate solutions to the initial value problem
In applications, is a given function and and are given numbers. The function is unknown. Denote by the exact solution for this initial value problem. In other words is the function that obeys
4
Under reasonable hypotheses on there is exactly one such solution. The interested reader should search engine their way to the Picard-Lindelöf theorem.
exactly.
Fix a step size and define By turning the problem into one of approximating integrals, we now derive another algorithm that generates approximate values for at the sequence of equally spaced time values We shall denote the approximate values with
By the fundamental theorem of calculus and the differential equation, the exact solution obeys
So Euler approximates the area of the complicated region (represented by the shaded region under the parabola in the left half of the figure below) by the area of the rectangle (the shaded rectangle in the right half of the figure below).
Our second algorithm, the improved Euler’s method, gets a better approximation by using the trapezoidal rule. That is, we approximate the integral by the area of the trapezoid on the right below, rather than the rectangle on the right above.
The exact area of this trapezoid is the length of the base multiplied by the average of the heights of the two sides, which is Of course we do not know or exactly.
Recall that we have already found and are in the process of finding So we already have an approximation for namely But we still need to approximate We can do so by using one step of the original Euler method! That is
So our approximation of is
and
Putting everything together, the improved Euler’s method algorithm is
5
Notice that we have made a first approximation for by using Euler’s method. Then improved Euler uses the first approximation to build a better approximation for Building an approximation on top of another approximation does not always work, but it works very well here.
Equation D.1.2. Improved Euler.
Here are the first two steps of the improved Euler’s method applied to
Here is a table which gives the first five steps.
0 | 0.0 | 3.000 | 3.000 | 3.300 | 3.100 | 3.305 |
1 | 0.1 | 3.305 | 3.105 | 3.616 | 3.216 | 3.621 |
2 | 0.2 | 3.621 | 3.221 | 3.943 | 3.343 | 3.949 |
3 | 0.3 | 3.949 | 3.349 | 4.284 | 3.484 | 4.291 |
4 | 0.4 | 4.291 | 3.491 | 4.640 | 3.640 | 4.647 |
5 | 0.5 | 4.647 |
Subsection D.1.3 The Runge-Kutta Method
The Runge-Kutta algorithm is similar to the Euler and improved Euler methods in that it also uses, in the notation of the last subsection,
6
Carl David Tolmé Runge (1856–1927) and Martin Wilhelm Kutta (1867–1944) were German mathematicians.
But rather than approximating by the area of a rectangle, as does Euler, or by the area of a trapezoid, as does improved Euler, it approximates by the area under a parabola. That is, it uses Simpson’s rule. According to Simpson’s rule (which is derived in Section 1.11.3)
Analogously to what happened in our development of the improved Euler method, we don’t know or So we have to approximate them as well. The Runge-Kutta algorithm, incorporating all these approximations, is
7
It is well beyond our scope to derive this algorithm, though the derivation is similar in flavour to that of the improved Euler method. You can find more in, for example, Wikipedia.
Equation D.1.3. Runge-Kutta.
That is, Runge-Kutta uses
to approximate- both
and to approximate and to approximate
Here are the first two steps of the Runge-Kutta algorithm applied to
with
Now, while this might look intimidating written out in full like this, one should keep in mind that it is quite easy to write a program to do this. Here is a table giving the first five steps. The data is only given to three decimal places even though the computation has been done to many more.
0 | 0.0 | 3.000 | 3.000 | 3.150 | 3.050 | 3.153 | 3.053 | 3.305 | 3.105 | 3.305 |
1 | 0.1 | 3.305 | 3.105 | 3.460 | 3.160 | 3.463 | 3.163 | 3.621 | 3.221 | 3.621 |
2 | 0.2 | 3.621 | 3.221 | 3.782 | 3.282 | 3.786 | 3.286 | 3.950 | 3.350 | 3.949 |
3 | 0.3 | 3.950 | 3.350 | 4.117 | 3.417 | 4.121 | 3.421 | 4.292 | 3.492 | 4.291 |
4 | 0.4 | 4.292 | 3.492 | 4.466 | 3.566 | 4.470 | 3.570 | 4.649 | 3.649 | 4.648 |
5 | 0.5 | 4.6487206 |
As we saw at the end of Section D.1.2, the exact is 4.6487213, to seven decimal places, Euler’s method gave 4.611, and improved Euler gave 4.647.
So far we have, hopefully, motivated the Euler, improved Euler and Runge-Kutta algorithms. We have not attempted to see how efficient and how accurate the algorithms are. A first look at those questions is provided in the next section.