Department of Computer Science

Numerical Calculus

Spring Semester 2012

Dr. Maury Eggen

For the fourth programming assignment of the semester, write two programs which will read a file of observations and calculate the best fit Lagrange polynomial for the data, as well as the divided differences polynomial for the data. Your programs should work for any number of observations, but polynomials of high degree may be somewhat unstable. Make sure you print the entire divided difference table.

Test your program on the following observations

  0.350000   0.096257
  4.410000  -1.008232
  3.200000  -0.188813
  5.560000  -0.683175
  7.100000   0.723111

Use your polynomials to approximate the values f(1), f(2), f(3), f(-5), and f(10). I got the values above from the function f(x) = sin(x) - x*exp(-x). Use gnuplot (or the Python function plotter I showed you early in the semester) to plot your polynomial function on the same graph as that of the above function to see where it matches and there it doesn't. The values of the actual function at the test points are: (warning: I wouldn't expect the polynomial function to approximate some of these values very well)
  1.000000   0.473592
  2.000000   0.638627
  3.000000  -0.008241
 -5.000000 743.024719	
 10.000000  -0.544475

Pay attention to the presentation -- work on a suitable user interface.