## Description

- Write a Matlab code which will nd the linear spline function of the given sample points.

- Write a Matlab code which will nd the natural cubic spline function of the given sample points.

- We are now going to compare interpolation polynomials and spline functions. Consider the Runge

function f(x) = | 1 | on the interval [ 5; 5] using 11 equally spaced points. |

1 + x^{2} |

- Use either your LagrangeInt or NewtonInt de ned in homework 5 to nd the degree 12 polyno-mial through these points. Plot f and this polynomial on the same graph.

- Use your code in problem 1 to nd the linear spline function of f through the sample points. Plot f and its linear spline function on the same graph.

- Use your code in problem 2 to nd the cubic spline function of f through the sample points. Plot f and its cubic spline function on the same graph.

- Based on your results, discuss the di erence between the interpolation polynomial and the spline functions.

- Computer libraries often use tables of function values together with piecewise linear interpolation to evaluate elementary functions such as sin(x), because table lookup and interpolation can be faster than using a Taylor series expansion. Write a Matlab le to accomplish the following.

- Create a vector ~x of 1000 uniformly-spaced values between 0 and . Then, create a vector ~y with the values of the sine function at each of these points. This will serve as your lookup table.

- For a random value r, estimate sin(r) as follows:

Find the two consecutive x entries, x_{i} and x_{i+1} which satisfy

x_{i} r x_{i+1}. Having identi ed the subinterval containing r, use linear interpolation with sample points x_{i} and x_{i+1} to estimate sin(r).

- Pick 100 random r value and evaluate sin(r) using the method in (b). Compare your results with the accurate value obtained by typing sin(r). Find the maximum absolute error and maximum relative error.

- Repeat (c), but this time start from a look up table with 2000 points. How does this change the relative error?

- Show that s(x) is a natural cubic spline through the points (0; 1); (1; 1); (2; 0); and (3; 10).

s(x) = | ^{8}1 2(x 1) 3(x 1)^{2} + 4(x 1)^{3} |
; if 1 | x < 2 | ||||||

> | 1 + x x^{3}; |
if 0 | x < 1 | ||||||

4(x 2) + 9(x | 2 | 3 | if 2 | x | 3 | ||||

< | 2) | 3(x 2) ; | |||||||

> | |||||||||

: |

- Spline function can use polynomial with di erent degrees on di erent pieces. You can de ne spline function in any form as long as the number of variables/equations match.

(a) Find

(

_{P} _{(x) =} ^{P}1^{(x);} ^{if 0} ^{x} ^{1}

P_{2}(x); if 1 x 2

such that

1

- P
_{1}(x) is linear, - P
_{2}(x) is quadratic,

- P (x) and P
^{0}(x) are continuous at x = 1,

- P (0) = 1, P (1) = 1, and P (2) = 0.

- Graph this function P (x).

- If you want to de ne a spline function in (a) with P
_{1}(x) quadratic and P_{2}(x) cubic, how many equations do you need? List them (pick the ones you think are reasonable).

- Another popular cubic spline function is called the Cubic Hermite Spline. Google this concept and complete the following

- Summarize the idea of Cubic Hermite Spline.

- Compare Cubic Hermite Spline and Natural Cubic Spline in accuracy, e ciency. Figure out when to use which. (You can code both and compare, or you can nd this information online. )

2