Physics 305, Fall 2009
Homework 3
Due Monday, September 14, 10 pm
This week we will use the same basic problem as last week - numerical integration --
to practice writing and using functions,
to explore the effects of using double precision
and to see some of the problems you can encounter in ``simple'' integrations.
You will also learn something about programming -- using functions.
- Modify the programs you wrote last week to do numerical integrations using
the left-hand rule, the midpoint method, and trapezoid rule so that the
function to be integrated is evaluated by code in a separate file from the
driving routine. Use this opportunity to fix up any remaining problems in
your codes from last week, and fix up your table and plot of errors versus bin size
if necessary.
- Now modify the programs to use double precision variables. Repeat your evaluation
of
using double precision, using
the number of bins 2, 4, 10, 20, 50, 100, 1000, 10000, 100000 and 1000000.
Make a new table and log-log plot of the error versus number of bins, and compare your
results to last week's results.
- Now let's try an integral that you can't do with your pencil! After all,
that's the point of this course. Use the midpoint or trapezoid rule
to calculate
Estimate your error. (You have to think about how to do this, since you
don't know the correct value. Using the integrate function on your
graphing calculator is not legal. After all, that is just a computer
program written by someone else that does the integral numerically.)
(Assignment continues on next page)
-
Now write a new function for this integral.
Compile it together
with the same main procedures you used in the previous part. Use numbers of
bins 10, 20, 40, 80 and 160 (doubling each time!).
Use other numbers of bins if you think that
will be useful.
To cut down on the work, you can use just the left-hand rule and midpoint rule
for this integral.
Again, study the dependence of the error
on the number of bins. This integral is not quite as nice as the one we
have been practicing on, and you should expect to have to think a little bit
to understand your results, or even to get good results.
Make a log-log plot to explore the dependence of error on step
size. What is the slope? (Hint: it is not two).
In your report, compare your answers to the exact answer.
(Extra credit: Can you explain why this integral doesn't converge
as well as the first problem?)
Doug Toussaint
2009-09-08