HW6Sol
HW6Sol
Homework VI
This assignment has seven problems. The assignment is due in class on Tuesday, April 10,
2012. There are seven regular problems and two computer problems (using MATLAB). For
written problems, you need to show your work and it is insufficient to just give the results or
answers. For the computer problems, turn in your results (e.g., graphs, plots, simple analysis
and so on) and also a printout of your (MATLAB) code.
Problem 1 (15pts)
1. What is the basic distinction between interpolation and approximation of a function?
2. Is Interpolation an appropriate procedure for fitting a function to noisy data? If so, why?
and if not, what is a good alternative?
3. (a) For a given set of data points (ti , yi ), i = 1, ..., n, rank the following three methods
for polynomial interpolation according to the cost of determining the interpolant
(i.e., determining the coefficients of the basis functions), from 1 for the cheapest to
3 for the most expensive: Monomial basis, Lagrange Basis and Newton basis.
(b) Which of the three methods has the best-conditioned basis matrix A?
(c) For which of the three methods is evaluating the resulting interpolant at a given
point the most expensive?
4. Why is interpolation by a polynomial of high degree often unsatisfactory?
5. In fitting a large number of data points, what is the main advantage of piecewise poly-
nomial interpolation over interpolation by a single polynomial?
Solution
1. In approximation, function could be close to the points and not necessarily passes through
those points. Interpolating function fits given data exactly.
2. Interpolation is inappropriate, least squares approximation should be used.
3. (a) Monomial basis (3), Newton basis(2), Lagrange basis (1)
(b) Newton
(c) Lagrange
4. it’s expansive to determine and evaluate. In some bases, coefficients of polynomial may
be poorly determined due to ill-conditioning of linear system to be solved. High degree
polynomial necessarily has lots of ”wiggles” which may bear no relation to the data to
be fit. Polynomial may pass through required data point, but it may oscillate wildly
between data points
1
5. large number of data points can be fit with low-degree polynomials.
Problem 2 (15pts)
1. How many times is a Hermite cubic interpolant continuously differentiable?
2. How many times is a cubic spline interpolant continuously differentiable?
3. For Lagrange polynomial interpolation of n data points (ti , yi ), i = 1, ..., n,
(a) What is the degree of each polynomial function lj (t) in the Lagrange basis?
(b) What function results if we sum the n functions in the Lagrange basis (i.e., if we
take g(t) = l1 (t) + ... + ln (t), what function g(t) results)?
Solution
1. once
2. twice
3. (a) n-1
(b) one. The proof is quite simple. g(t) = l1 (t) + ... + ln (t) could be taken as inter-
polating zeroth order polynomial (constant function) with value 1 i.e. yi = 1. As
the interpolating polynomial is unique (property of Polynomial Interpolation, since
there are n data points and degree is n − 1) therefore g(t) = 1 implying summation
is 1.
Problem 3 (15pts) Given the three data points (−1, 1), (0, 0), (1, 1), determine the interpolat-
ing polynomial of degree two:
1. Using the monomial basis
2. Using the Lagrange basis
3. Using the Newton basis
Show that the three representations give the same polynomial.
Solution
1. The linear system using the monomial basis is
1 −1 1 x1 1
1 0 0 x2 = 0 (1)
1 1 1 x3 1
2
2. The form of a polynomial of degree two using the Lagrange basis is
(t − t2 )(t − t3 ) (t − t1 )(t − t3 ) (t − t1 )(t − t2 )
p(t) = y1 + y2 + y3
(t1 − t2 )(t1 − t3 ) (t2 − t1 )(t2 − t3 ) (t3 − t1 )(t3 − t2 )
substituting the data for this problem, the polynomial becomes
(t − 0)(t − 1) (t + 1)(t − 1) (t + 1)(t − 0)
p(t) = 1 +0 +1
(−1 − 0)(−1 − 1) (0 + 1)(0 − 1) (1 + 1)(1 − 0)
t(t − 1) t(t + 1)
p(t) = +
2 2
which is equivalent to the polynomial in part 1
2.
(t − t2 )(t − t3 ) . . . (t − tn ) (t − t1 )(t − t2 ) . . . (t − tn−1 )
pn−1 (t) = y1 + · · · + yn
(t1 − t2 )(t1 − t3 ) . . . (t1 − tn ) (tn − t1 )(tn − t2 ) . . . (tn − tn−1 )
3
for a given polynomial, y and the denominators are constants, so we have
Each basis function requires n multiplications, so for n bais function the total is n2 total
multiplications.
Problem 5 (10pts) Express the following polynomial in the correct form for evaluation by
Horner’s method:
2. p(t) = t3 − 1
Solution
2. p(t) = t3 − 1
p(t) = −1 + t(t(t))
Problem 6 (15pts)
1. For a given set of data points t1 , ..., tn , define the function π(t) by
Show that
2. Use the result of the previous part to show that the jth Lagrange basis function can be
expressed as
π(t)
lj (t) = .
(t − tj )π 0 (tj )
Solution
4
1. Differentiating π(t) with respect to t
π 0 (t) = (t − t1 )0 (t − t2 )...(t − tn )
+ (t − t1 )(t − t2 )0 ...(t − tn )
+ ...
+ (t − t1 )(t − t2 )...(t − tj )0 . . . (t − tn ) + . . .
+ (t − t1 )(t − t2 )...(t − tj ) . . . (t − tn )0
π 0 (t) = (t − t2 )...(t − tj ) . . . (t − tn )
+ (t − t1 )...(t − tj ) . . . (t − tn )
+ ...
+ (t − t1 )(t − t2 )...(t − tj−1 )(t − tj+1 ) . . . (t − tn ) + . . .
+ (t − t1 )(t − t2 )...(t − tj ) . . . (t − tn )0
When we evaluating at tj there will be only one term which will not contain (t − tj )
5
should given an approximation to the square root function.
1. Compute the polynomial of degree eight that interpolates these nine data points. Plot
the resulting polynomial as well as the corresponding values given by the MATLAB
function sqrt over the domain [0, 64].
2. Use a cubic spline routine (MATLAB function spline) to interpolate the same data and
again plot the resulting curve along with the MATLAB function sqrt over the same
domain as above.
3. Which of the two interpolants is more accurate over most of the domain?
For this problem, you need to implement a short piece of MATLAB code that does the poly-
nomial interpolation (part 1). You are allowed to use any method (basis) to compute the poly-
nomial interpolation. For part 2, you are allowed to use the MATLAB functions spline and
ppval. In case you do not know how to use the two MATLAB functions, use help to learn
more about them and try a few simple examples first.
An example of plotting sqrt function and a function f (t) on the domain [0, 64] is
> t = 0:0.1:64;
> y_1 = f(t);
> y_2 = sqrt(t);
> plot(t, y_1, ’-b’, t, y_2, ’-r’);
Solution
6
Computer Problem 2 (10pts) The gamma function is defined by
Z ∞
Γ(x) = tx−1 e−t dt, x > 0.
0
Γ(n) = (n − 1)!,
t: | 1 2 3 4 5
y: | 1 1 2 6 24
should yield an approximation to the gamma function over the given range.
1. Compute the polynomial of degree four that interpolates these five data points. Plot
the resulting polynomial as well as the corresponding values given by the MATLAB
function gamma over the domain [1, 5].
2. Use a cubic spline routine to interpolate the same data and again plot the resulting curve
along with the MATLAB function gamma over the domain [1, 5].
3. Which of the two interpolants is more accurate over most of the domain?
Solution