- You should find it useful to think of how the 1 + a + a + ... vs. a + a + ... + 1 problem from Session 2 relates to this one. (That might also be a good code to start from in writing one for this problem.)
- If you only consider relatively small N, you will not see any difference between summing up and summing down, since both will have an error about equal to the machine precision. So be sure to increase N until you see a different trend (I used up to 10^8).
- If you are looking for the effects of errors over a logarithmic
range (e.g., N from 10^2 to 10^8), you should vary N by multiplying
by a factor each time through a loop and not by adding 1 (or some other
number). That is, don't use:
for (N = 100; N <= 100000000; N++) {

which will take an enormous amount of time calculating lots of N values you don't need. Instead, use something like:} for (N = 100; N <= 100000000; N *= 10) {

which just calculates for 100, 1000, 100000, etc.} - When you output relative errors to a file for plotting, the "scientific" format is usually most useful, again because you are looking at logaithmic intervals. (See the codes we've used in class for examples.)
- It is only the absolute value of the relative error that is of
interest. So use "fabs" (you need to "input
"). It is particularly important to have only positive numbers if you are going to plot on logarithmic scales! - Be careful that you don't confuse the machine precision with the
smallest floating point number. For example,
in single precision, the machine
precision is about 10
^{-7}, but that*does not*mean that 10^^{-10}is set to zero. It is only when you add two numbers that*differ*by a factor of more than 10^{-7}that the smaller number is effectively zero. - A common bug when you have an outer loop stepping through
N_max and an inner loop that does the sum of 1/n up to N_max
is forgetting to reset your sum to zero when you start the
inner loop. So if your summation variable is
`sum_up`, make sure that`sum_up = 0.;`appears within the outer loop and not just at the beginning of the program.

- You will just be modifying a code from Session 2, not writing one from scratch.
- The interpretation of the graph should mainly explain the meaning of the regions where the plotted error is about unity and where it is very small. (I.e., which result is good and which is poor, or are both good or poor?)
- For part c), remember that you need
the linker option
`-lgsl -lgslcblas`in your makefile to run a program that uses the GSL library. Don't forget that you need to`#include`a header file (see the Bessel function example from Session 1).

[780.20 Home Page] [OSU Physics]

Last modified: 08:58 pm, January 03, 2010.

furnstahl.1@osu.edu