For each of the following exercises create the specified files with your answer(s). Submit your homework using the course submit utility.
with(CurveFitting); p := x -> PolynomialInterpolation([x1, x2, x3, x4, x5, x6,x7,x8],[y1, y2, y3, y4, y5, y6, y7, y8],x);The first vector argument lists the eight zeros of T(8,x) and the second lists the values of y = x*exp(-x) at these same points. After you insert the values for the xi's and yi's, evaluate p(x) at few x values to be sure it is behaving correctly. Then plot the difference p(x) - x*exp(-x) on the interval [-1,1]. Then try evaluating the difference slightly outside this interval.
In your answer file optimum.txt describe what you observed.
int(exp(-t)/t^(x+1),t=0..infinity)
Please see Maple for details. Note that Gamma(n+1) = n!.
The Gamma function has no zeros in the finite complex plane and has poles at all negative integers and zero. So it makes a good testing ground for Pade approximation.
For better readability, normalize the coefficients of the polynomials in the numerator and denominator so the coefficient of x4 in the denominator is 1.
Although this exercise does not use Numerical Recipes code, we use the C++ datatypes . The C++ part of the exercise involves understanding the NR matrix and vector classes, which are very similar to the ones we used in PHYCS 6720.
Here are the components of the program:
| File | Purpose of procedure |
|---|---|
| interp.cc | Main program. |
| neville.cc | Does the Neville iteration |
| bulirsch_stoer.cc | Does the Bulirsch-Stoer iteration. |
| Makefile | Rule for compiling the above. |
See ~p6730/examples/a02 for the nearly complete code. You are asked to complete the subroutines neville.cc and bulirsch_stoer.cc. The lines to be completed are indicated by comments bordered by //**************.
Please hand in the two files indicated in red above with your changes. We will supply the rest.
x = 1.5
x = 0.5
Estimate the error from the change in the last diagonal element.
Compare both methods with the exact result from Maple. In both cases
discuss whether the estimated error gives a reasonable accounting
for the difference between the interpolated (extrapolated) value and
the exact answer.
x = 0.5
x = -0.5
Compare with the exact result in both cases and discuss in terms
of the applicability of each method to such an extrapolation problem.