By definition, derivatives are limits of Newtonian quotients and approximating this limit provides one of the basic ideas in the construction of numerical methods. More precisely, let be the solution of the initial value problem , . The derivative of at time is the limit Hence we expect
to be a good approximation of at time for small . Indeed, by Taylor’s formula with an appropriate . Thus, the error made in the approximation in (??) is the size as long as the second derivative of is bounded. Consequently, if we know the value of the solution at time , then we can use the right hand side in the differential equation to compute an approximation of the solution at time .Euler’s Method
Since is the derivative of at time , there is a simple geometric interpretation of (??) (see Figure ??). Recall that the tangent line to the graph of the function at the point is the line going through the point whose slope is . The approximation of at time is just the one given by the value of that tangent line at . The numerical method that is based on (??) is called Euler’s method. It seems evident that smaller values of should lead to a more accurate approximation of the solution on the interval . On the other hand, note that simultaneously the length of the interval is shrinking and that more approximations are needed to approximate a solution on a fixed time interval.
Concretely, Euler’s method produces a sequence of approximations to a solution of an initial value problem. To understand this point, begin the numerical integration at the exact initial value . Choose a step size . Use (??) to obtain after one integration step the approximation where Continuing this process, construct a sequence
for where is the total number of steps that are performed in the numerical approximation.An Example of Euler’s Method
We illustrate how Euler’s method works for the example
by using MATLAB to compute an approximation to . Suppose that we set the step size to . Then the number of steps needed to reach is . The code for computing the sequence in (??) is:h = 0.2;The result is shown in Figure ??(a). Note that the ’o’ in the MATLAB command plot(t,x,’o’) puts o’s at the 11 numerically computed points and the ’- -’ in the command plot(t,x,’--’) interpolates dashed lines between successive o’s. Moreover, the statements within the for loop — that is the lines from for k = 1:K up to the end — reproduce the iteration procedure given in (??). (In MATLAB the index of a vector is not allowed to be zero. Therefore, the for loop is programmed to run from rather than from .)
t(1) = 1;
x(1) = 2;
K = 10;
for k = 1:K
t(k+1) = t(k)+h;
x(k+1) = x(k)+h*(x(k)+t(k));
end
plot(t,x,’o’)
hold on
plot(t,x,’--’)
xlabel(’(a)’)
Comparison of Numerical Solutions with Exact Solutions
We now compare the numerical approximation with the exact solution of (??), that is given by This comparison is made in Figure ??(b). The second curve in the figure is obtained using the additional commands
s = 1 : 0.01 : 3;Note that in that figure the scale on the vertical axis is different from the one in Figure ??(a).
y = 4*exp(s-1)-s-1;
plot(s,y)
xlabel(’(b)’)
In this example we see that after just steps the numerical solution of the initial value problem by Euler’s method has led to a significant error (see Figure ?? (b)). There are two ways to proceed. Either we can use a smaller step size in Euler’s method in an attempt to improve accuracy or we can develop numerical methods that give more precise results for the same step size. For an illustration of the first approach we show in Figure ?? an approximation with Euler’s method using a step size . It can be seen that the error is now indeed much smaller but that also quite a few iterations of Euler’s method are needed to produce this result. Therefore the latter approach has generally proved preferable and one idea for improving accuracy is to replace in the right hand side of (??) by another expression in ways that we now explain.
Implicit Methods
In Euler’s method, the approximation is computed using the tangent line to the graph of the solution at the point . Another idea is to approximate the graph of by the line passing through the point whose slope is . This idea leads to the numerical approximation which is known as the implicit Euler method. One difficulty with this method is that we do not yet know what the value of is. However, it is implicitly defined in the sense that we can think of the iteration step
as an equation in the unknown and use this nonlinear equation to solve for . We remark that there are ODEs (e.g. so-called stiff equations) for which implicit schemes typically produce more reliable results. On the other hand, implicit methods require considerable additional numerical effort at each time step in order to solve the equations for .An implicit numerical method that is more accurate than implicit Euler is obtained by just averaging the Euler and implicit Euler approximations, to obtain
This method is called the implicit trapezoidal rule.The Modified Euler Method
As we discussed, the problem with implicit methods is that they require the solution of a nonlinear equation at each time step. In principle this can also be done numerically, but such solutions require much numerical effort. This problem can partly be overcome by using a clever idea discovered by Runge (1895). We illustrate this idea on the implicit trapezoidal rule. Rather than determining directly from (??), first estimate by using Euler’s (tangent line) method. Then use the estimate in the implicit trapezoidal rule. In formulas we obtain: or, in one line,
The resulting numerical method is called the modified Euler method.Let us use MATLAB to solve the initial value problem (??) by the modified Euler method. Using the same data as in the previous example we type
h = 0.2;to obtain the illustration in Figure ??(a). We see that the approximation can hardly be distinguished from the exact solution. Even if we double the step size to and reduce the number of steps to , the approximation is still acceptable. See Figure ??(b).
t(1) = 1;
x(1) = 2;
K = 10;
for k = 1:K
t(k+1) = t(k)+h;
y(k) = x(k)+h*(x(k)+t(k));
x(k+1) = x(k)+(h/2)*(x(k)+t(k)+y(k)+t(k+1));
end
plot(t,x,’o’)
hold on
plot(t,x,’--’)
s = 1 : 0.01 : 3;
y = 4*exp(s-1)-s-1;
plot(s,y)
xlabel(’(a)’)
Fourth Order Runga-Kutta Method
The idea in the construction of the modified Euler method is to obtain a better approximation of the solution by using more information on the underlying differential equation. This is realized in the scheme by taking the arithmetic average of two evaluations of the right hand side at different points rather than at just one point as in the standard Euler methods.
In the frequently used fourth order Runge-Kutta method four different evaluations of are taken into account in the computation of the next iterate. The method is given as follows: set
Systems of Differential Equations
All the methods we have introduced in this section can also be used to find numerically solutions of systems of differential equations. We illustrate this fact for systems of two equations using Euler’s method.
In the scalar case the underlying idea for Euler’s method was to approximate the solution of the differential equation over a short interval by a line that is tangent to the solution curve (see Figure ??). We now use the same approach by applying this idea to each component of the solution.
Suppose that is a solution of the initial value problem
where . As in (??) we obtain for the components and by using the differential equationSimilarly, the implicit Euler method takes the form
h = 0.05;The result is shown in Figure ??.
t(1) = 1;
x(1) = 0;
y(1) = 2;
K = 40;
for k = 1:K
t(k+1) = t(k)+h;
x(k+1) = x(k)+h*(y(k)-3*t(k));
y(k+1) = y(k)+h*(y(k)+x(k)^2);
end
plot(x,y,’o’)
hold on
plot(x,y,’--’)
xlabel(’x’)
ylabel(’y’)
Observe that the solution is graphed in the -plane. In particular, the variable does not appear in the figure and this is the reason why the single steps in the approximation do not seem to be equally spaced. However, in Figure ?? we show graphs of the approximations of the time series vs. and vs. . Here it can be seen that the step size is indeed constant.
There are several ways to improve the accuracy of numerical schemes approximating solutions of initial value problems. One very successful method is to adapt the step size in each step of the numerical approximation. We illustrate this strategy in Appendix ??.
General Runga-Kutta Methods
The modified Euler method as well as the fourth order Runge-Kutta method are specific examples of a general class of numerical schemes for the solution of initial value problems. These schemes are called Runge-Kutta methods. A general explicit Runge-Kutta method is fully described by numbers and With these numbers the step in the numerical solution of an initial value problem using a Runge-Kutta method can be described as follows. Given first evaluate for times:
- Euler’s method: set and there are no ’s.
- The modified Euler method: set Indeed, using these data
- Fourth order Runge-Kutta method: set and
Exercises
In Exercises ?? – ?? decide whether or not the following numerical schemes are Runge-Kutta methods.
- Suppose that a Runge-Kutta method leads to exact results for all step sizes , that is . What does this imply for the numbers ?
- Verify that the relation on the numbers derived in part (a) is satisfied for Euler’s method, for the modified Euler method and for the fourth order Runge-Kutta method.
In Exercises ?? – ?? solve the given initial value problem by the explicit and the modified Euler method. Approximate the solution on the given interval and use the prescribed step size .