EulerMethod Excel Implementation Elementary Differential Equations
EulerMethod Excel Implementation Elementary Differential Equations
1/7
https://www.math.ksu.edu/math240/book/chap1/numerical.php
, we
2.1.2016 14:38
2/7
https://www.math.ksu.edu/math240/book/chap1/numerical.php
Naturally, you can use this technique to handle other equations. The only thing you need to edit is
the formula for y' in column B. Do be sure to copy the edited formula down the whole column.
Since our example equation
problem is
approximating the true solution. In cell D1 of the spreadsheet enter y exact and in cell E1 enter
rel error (which stands for relative error). Then in cell D2 enter =3*exp(-A2)+2*A2-2 and in cell
E2 enter =(D2-C2)/D2. It will be convenient to right-click on cell E2 and Format Cells as Percentage
since relative error is a percent. Now click and drag to select cells D2 and E2 and drag those
2.1.2016 14:38
3/7
https://www.math.ksu.edu/math240/book/chap1/numerical.php
formulas down. This will show you how accurate the approximation produced by Euler's method is.
As you can see, Euler's method isn't particularly accurate. We can improve the approximation by
taking smaller steps. If you change cell H2 to 0.05 to cut the step size in half, you find that the
error in the value of
has been cut from 5.87% to 2.85%. Of course you had to take 10 steps
of size 0.05 to get to 0.5 while it only took 5 steps of size 0.1. So you do twice as much work but
you cut the error roughly in half. This is actually the standard pattern.
? Well what we
2.1.2016 14:38
4/7
https://www.math.ksu.edu/math240/book/chap1/numerical.php
. In fact,
All those "approximates" in the last sentence may look scary, but the process is actually fairly
straightforward. For the initial value problem
we set
and
and compute
and
from
to
We repeat this procedure as many times as needed to reach our desired point just as with the
original Euler's method. For example, to approximate
using a step size of 0.1 we compute
the following (calculations here have only been reported to 4 decimal places):
2.1.2016 14:38
5/7
https://www.math.ksu.edu/math240/book/chap1/numerical.php
As before, you can apply this method for other equations just by editing the formulas for the slopes
in columns B and D. And as before, you can add columns for the exact values and the relative error.
Enter y exact in cell F1 and rel error in cell G1. Enter the formulas =3*exp(-A2)+2*A2-2 in cell
F2 and =(F2-E2)/F2 in cell G2. Click and drag to select F2..G2 and then copy those formulas down
the sheet to show the exact values and the relative error. As before it looks nicer if you set the
format of the cells in column G to Percentage.
Note that the improved Euler's method is twice as much work as the original Euler's method, since
you do an extra improvement step each row. On the other hand, the error for
is now just
0.2%, which is much closer than the 2.85% error we got by doing twice as much work with a
smaller step size with the original Euler's method. We can improve the accuracy of our
approximation further by using a smaller step size of
. The result of this calculation is off by
only 0.05% of the true value. While halving the step size (hence doubling the work) halved the
error for Euler's method, it reduces the error in the improved Euler's method by about a factor of 4.
This is another advantage of the improved Euler's method.
2.1.2016 14:38
6/7
https://www.math.ksu.edu/math240/book/chap1/numerical.php
Concluding Discussion
We could repeat the process of improving the estimate by using both
and
from the improved
Euler's method to get a New And Improved Euler's method. And of course we could then improve
the estimate another time and yet another time. This leads to a class of methods called
Runge-Kutta methods. To find the best approximations of the slope by taking weighted averages of
different simpler approximations at different points requires that we replace the simple tangent line
approximation by a Taylor series approximation and do some more algebra. But since that's all been
done, you can just look up the formulas and enter them into a spreadsheet in the same manner as
we've done here.
Of course, applying these methods requires you to pick the correct step size. Looking back at the
geometry you should realize there is no reason you have to always use the same step size. Indeed,
you will be better off if you vary the step size to be small where the solution is curving quickly and a
larger step size (hence fewer steps so quicker execution and less roundoff) where the solution is
moving in more of a straight line. In developing code to track the motion of space probes (which
have long straight paths between planets and complicated curves as the swing around planets),
Fehlberg developed a further refinement using two different Runge-Kutta methods where you
compare their answers to get an approximation for the error. This approximation can then be used
to adjust the step size automatically. These are called Runge-Kutta-Fehlberg methods and are
perhaps the best of the common techniques for finding careful approximations to initial value
problems.
While the RKF techniques are recommended for careful approximations, the methods we've learned
here, besides introducing the basic ideas, are also useful when you need rough approximations
quickly. Being so simple, Euler's method and the improved Euler's method will run quicker than
more accurate techniques. The physics model of many video games is implemented using these
methods. To update the screen 60 times a second, you need to compute the position of many
different objects as quickly as possible. And you just need things to look and feel right to the
players; you don't need precise answers (for example, any error less than one pixel is irrelevant). In
this situation, using Euler's method or the improved Euler's method is the best choice.
Exercises
Approximate
for each of the initial value problems using Euler's method, first with a step size
of
and then with a step size of
.
1.
2.
2.1.2016 14:38
7/7
https://www.math.ksu.edu/math240/book/chap1/numerical.php
3.
4.
5.
6.
Approximate
for each of the initial value problems using the improved Euler's method, first
with a step size of
and then with a step size of
.
7.
8.
9.
10.
11.
12.
Find the exact solution to each of these equations and use that to find an exact value for
for
each of the initial value problems and compare the errors in the different methods used above.
13.
14.
15.
16.
17.
18.
If you have any problems with this page, please contact [email protected].
2010, 2014 Andrew G. Bennett
2.1.2016 14:38