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

CAAM 453: Numerical Analysis I

Problem Set 3

2022


Note: You can use the MATLAB codes posted on the CAAM453 web-page. If you modify these codes, please turn in the modified code. Otherwise you do not have to turn in printouts of the codes posted on the CAAM453 web-page. Turn in all MATLAB code that you have written and turn in all output generated by your MATLAB functions/scripts. MATLAB functions/scripts must be commented, output must be formatted properly, and plots must be labeled.

Problem 1

1. Write a Matlab routine for computing the Netwon polynomial interpoland of degree n for a given set of data points  (xj,f(xj)), 0  j n   where f is a   given function.

2. Let

n

pn(x) = anxn.

i=0

Horner’s method is an algorithm for calculating polynomials, which consists of transforming the monomial form into a computationally efficient form. To evaluate pn(x0), define a sequence of constants as follows:

bn := an (1)

bn1 :=  an1 + bnx0 (2)

.

b0 := a0 + b1x0. (3)

Then b 0 is the value of pn(x0). Write another routine to evaluate the polyno- mial using Horners nested evaluation scheme. Your evaluation scheme should be written in vectorized form so it can accept an arbitrary vector argument x and produce a vector of function values f with f (i) = pn(x(i)).

3. Write a third Matlab routine that will add a new data point (xn+1,f(xn+1))  to the existing set of points and update the Newton interpolant without re- computing anything done with the first set of data.

4. Apply your routines for computing and evaluating the Newton polynomial interpolant to the Gamma function (gamma in matlab) on the interval [.1, 4]. First, construct the polynomial interpolants at 5, 10, 15 equally spaced points in [.1, 4]. Include the end points (automatic with linspace). Plot the Gamma



function on this interval and then plot the three polynomial interpolants you constructed on the same graph (using hold on). Your graph should include a legend identifying the gamma function and the three different interpolants. Be sure to use different line types for each of these. Use 1000 equally spaced points in the plot.

 

Second, compute the interpolant on the interval [.5, 3.5] using 10 equally spaced points in this interval. Plot the Gamma function and the interpolating polynomial on the same graph as above. Examine the result and judiciously add a few more interpolation points with xj in the interval [.1, 4] to improve the quality of the interpolation approximation. When you have a decent fit, plot the improved interpolating polynomial on the same graph as the gamma function and first interpolating polynomial. This plot should be over the in- terval [.1, 4] using 1000 equally spaced points as before. Again a legend and distinct line types are required.


Problem 2 Let {xi ih}n

with h = 1/n be a uniform partition


of the interval [0

i=0

, 1]. Consider a function f

œ C2([0, 1]), and its piecewise


linear polynomial interpolation p(x). You are going to prove that the L2 error estimate for piecewise linear interpolation if


 

Î Î

= Û⁄  1[

( )

(  )]2 Æ

.  ÕÕ.


For that, follow the steps below:

1. Show that the Taylor expansion of f (x) for x close to zero can be written as

x

f (x) = f (0) + f (0)x + 0 f (s)(x s)ds.

Hint: You should use the integration by parts formula

⁄  u(x)vÕ(x)dx u(x)v(x ⁄  uÕ(x)v(x)dx.

2. Then, show that since p(x) is the linear interpolation of f œ C([0, h]),

p(x) = f (0) + f Õ()x,  œ [0, h].

3. Use the results from parts 1 and 2 to show that for x œ [0, h],


Ô       A⁄  h -

-2 B1/2


|f (x p(x)| Æ

3hx

0   -f ÕÕ(s)-  ds .


 

Hint: notice that

x Õ


 

Hint: use the following result (without proof)

h h 1/2

0  |f (x)| dx Æ h 0  f (x)dx .

 

4. Now prove that

Îf  pÎL2([0,1]) Æ h2 .f ÕÕ.L2([0,1]) .


Problem 3 This problem is pledged!

The Hermite interpolant hn P2n+1 of f C1([a, b]) at the points xj j = 0, 1, 2,. .., n is the interpolating polynomail such that hn(xj) = f (xj) and hÕn(xj) = f Õ(xj).

It can be written in the form

n

hn(x) = Aj(x)f (xk)+ Bj(x)f Õ(xj)

j=0

 

where the functions Aj and Bj generalize the Lagrange basis functions:

Aj(x) = 11  2ljÕ (xj)(x  xj)2 l2j(x) (4)

Bj(x) = (x  xj)l2(x) (5)


where

lj(x) = Ÿ


 x  xk . (6)

xj xk


k=0,k  j

Calculate explicitly (by hand) the cubic hermite polynomials A0, A1, B0 and

B1 for x0 = 0 and x1 = h, for h> 0.  For  that, assume that A0 is of the form

A0(x) = a + bx + cx2 + dx3.

Then, calculate the coefficients a, b, c and d by superimposing the constraints A0(0) = 1, A0(h) = 0, AÕ(0) = AÕ(h) = 0.  Do  the  same  thing  for  A1, B0 and B1 to get the final result. Verify that the results correspond to the formulas 4 and 5.

We want to build a piecewise hermite interpolation HN (x) of degree 3 for the function f (x) = 1/(1 + x2) in x = [ 4, 4]. For that, we divide [ 4, 4] into N intervals of size 8/N . In each of those intervals, we approximate f using cubic Hermite polynomials. The result is the piecewise cubic function HN (x).



Write a Matlab program that computes HN (x) and plot HN (x),x [ 4, 4] for different values of N . Superimpose f on that graph.

Write  a  Matlab  program  that  computes  HNÕ  (x)  and  plot  HNÕ  (x),x [   4, 4] for different values of N . Superimpose f Õ on that graph.

Write  a  Matlab  program  that  computes  HNÕÕ (x)  and  plot  HNÕÕ (x),x [   4, 4] for different values of N . Superimpose f ÕÕ on that graph.

Compute  eN  =  maxx  [  4,4] HN (x) f (x) for N = 1, 2,. .. Plot eN vs N

using a log scale on the y axis. Comment on the graph.