Problem 6
The gamma function is defined by $$ \Gamma(x)=\int_{0}^{\infty} t^{x-1} e^{-t} d t, x>0 $$ It is known that for integer numbers the function has the value $$ \Gamma(n)=(n-1) !=1 \cdot 2 \cdot 3 \cdots(n-1) $$ (We define \(0 !=1 .\) ) Thus, for example, \((1,1),(2,1),(3,2),(4,6),(5,24)\) can be used as data points for an interpolating polynomial. (a) Write a MATLAB script that computes the polynomial interpolant of degree four that passes through the above five data points. (b) Write a program that computes a cubic spline to interpolate the same data. (You may use MATLAB's spline.) (c) Plot the two interpolants you found on the same graph, along with a plot of the gamma function itself, which can be produced using the MATLAB command gamma. (d) Plot the errors in the two interpolants on the same graph. What are your observations?
Problem 8
Consider using cubic splines to interpolate the function $$ f(x)=e^{3 x} \sin \left(200 x^{2}\right) /\left(1+20 x^{2}\right), \quad 0 \leq x \leq 1 $$ featured in Figure \(10.8\). Write a short MATLAB script using spline, interpolating this function at equidistant points \(x_{i}=i / n, i=0,1, \ldots, n .\) Repeat this for \(n=2^{j}, j=4,5, \ldots, 14 .\) For each such calculation record the maximum error at the points \(\mathrm{x}=0: .001: 1\). Plot these errors against \(n\), using loglog. Make observations in comparison to Figure \(10.8\).