|
Non-Programming Exercises:
Prove by mathematical induction that the following formula is true for all n >= 0:
n +--- \ F(i) = F(n+2) - 1 / +--- i = 0
Use a program to check out how good this approximation is. Specifically, compare the ratio St(n)/n! for n = 1, 2, 3, 4, 5, 10, 15, 20, 25, 50, 100, 150. [Hint: calculate everything as a double, since you can't represent anything bigger than 12! = 479001600 as an int. In either Java or C/C++ you will want to use the pow function. In C on a Sun, don't forget to compile with a -lm option because of the math functions. The program is especially easy to write in Java, with functions and constants: Math.pow, Math.PI, Math.E, and Math.sqrt. Your program should produce four columns, with n, n!, St(n), and St(n)/n! in the columns, roughly as shown below. You must include a source listing and the results of a run of the program.]
n n! St(n) St(n)/n! ----------------------------------------------------------- 1 1.0 0.9221370088957891 0.9221370088957891 2 2.0 1.9190043514889832 0.9595021757444916 3 6.0 5.836209591345864 0.972701598557644
In the program for item 1 above, use the first two terms of the Correction Factor to get more accurate results, that is, just multiply by (1.0 + 1.0/(12.0*n)) (ignoring the three higher terms) and see how much better the approximation is. (Print the same results as in 1.)
Then
Test this formula out by writing a program that will input an integer n and will calculate and print the three quantities:
Test the program at least with n = 1, 2, 3, 4, 5, 10, 15, 20, 25, 50, 100, 150.