Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Math 4446, Project 1

Compress the MATLAB les and project report into a zip (or tar, gz) file and upload to Canvas . The report should be typed (eg.  by LATEXor MS WORD), with requested MATLAB codes and answers to  questions .  Note  that this  is  not  a group project  and  an honor code pledge  must  be  included in the submitted report.

1.  Piecewise cubic Hermite interpolation.

(a)  Show that the cubic Hermite polynomial interpolating f (x) and its derivative at the points xi  and xi+1  can be written explicitly as

si(x) = fi+(f )τ + τ 2 + τ 3 ,

where hi  = xi+1  - xi , fi  = f (xi), f  = f\ (xi), fi+1  = f (xi+1), f+1  = f\ (xi+1), and τ = x - xi .

(b)  Based on the formula above, develop a function mypchip .m with the following header for piecewise cubic Hermite interpolation. The output pp is a piecewise polynomial structure generated by mkpp. Note that the built-in MATLAB function pchip is different from the Hermite interpolation in this problem. Include the printed code to the report so that I can make necessary comments.

function   [ pp]= mypchip ( x , y , dy )

%MYPCHIP -  p i e c e w i s e    c u b i c   Hermite   i n t e r p o l a t i n g   p o l y n o m i a l %        i n p u t

%                  x       -      a   v e c t o r   f o r   x   i    v a l u e s

%                  y       -      a   v e c t o r   f o r   fu n c t i o n    v a l u e s   f ( x   i )

%                  dy     -      a   v e c t o r   f o r    d e r i v a t i v e s   f ’ ( x   i )

%        o u t p u t

%                 pp     -      A  p i e c e w i s e   p o l y n o m i a l   s t r u c t u r e   f o r   t h e %                                      PCHIP

2.  Consider

f (x) = x exp(-x),    0 s x s 4.

(a)  Compute piecewise cubic Hermite polynomial that interpolates f (x) and its derivative at equidistant points xi  = ih, i = 0, 1, . . . n, where h = 4/n. Generate data to complete the following table. For each grid spacing h, obtain the actual numerical error enum(h) and compute the numerical order of accuracy α . Is α consistent with your expectation? Find the theoretical error bound for each grid spacing. Does the error bound provide a good estimation of the actual error?  Attach the matlab code (save the code as P2a .m) that you have used in this problem to the report.

k

nk

hk

 

enum(hk)

αk   

ebound(hk)

 

1

4

1

 

 

2

8

1/2

 

 

 

3

16

1/4

 

 

 

4

32

1/8

 

 

 

5

64

1/16

 

 

 

Here, we can approximate enum(hk)by the maximum error evaluated at x = 0 : 0.001 : 4

enum(hk)= x=0:0(m)00(ax)1:4 f (x) - phk (x),

where phk   is the piecewise cubic Hermite polynomial for grid spacing hk .  The order of accuracy α is the greatest number such that the error e(h) = O(hα ). Numerically, it can

be obtained from

ln (enum(hk)/enum(hk -1 ))

ln (hk/hk -1 )             .

(b)  Consider different piecewise interpolating polynomials (piecewise cubic Hermite, natural spline, not-a-knot spline, and clamped spline) for n  = 4  (i.e.   5 points).   Plot these piecewise polynomials together with f (x) and interpolating points on [0,4].  Based on your plot, rank the different polynomials according to their accuracy. Does natural spline work well for this problem? Explain why it does not (or does) work well. Comment on the advantages and disadvantages of these piecewise polynomials.

Optional:  You are welcome to include results of additional polynomials supplied by MATLAB.

3.  Polynomial interpolation makes it possible to differentiate functions based on discrete points only.   Suppose we want to compute the curvature of f (x) = x exp(-x) on  [0, 4] based on {xi, yi}i(8)=0 , with xi  equally distributed on [0, 4].

FYI: The curvature of a function f (x) is given by κ(x) =  , which is positive if the

f is concave up and negative otherwise.

(a) Which method  (mypchip,  interp1 with method  linear”,  natural spline,  not-a-knot spline, and clamped spline) would you use to perform this task? Why?

(b) Write a script (save it as P3 .m) to the plot the curvature on [0,4] together with the exact curvature. You may proceed as follows:  (i) find the pp structure of the piecewise inter- polating polynomial P (x); (ii) work with the coefficient matrix to get the pp structures of P\ (x) and P\\ (x); (iii) compute the curvature of P (x) at points x=0:0 .01:4 and plot it together with the exact curvature of f (x).  Comment on your results.  Include the printed code to the report.