



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solutions to various interpolation problems using polynomials and splines. The problems involve finding the coefficients of the polynomials that pass through given points and evaluating the errors of the interpolation. The document also includes the use of chebyshev nodes and matlab code for plotting and comparing the interpolants and exact functions.
Typology: Assignments
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Numerical Computing Summer ’10 MATH/CSCI 4800- Homework-
Assigned Tuesday July 27, 2010 Due Tuesday August 3, 2010
(a) The points are (0, 0), (1, 1), (2, 2), (3, 7). Let the full-degree polynomial interpolant be
p(x) = c 1 + c 2 x + c 3 x^2 + c 4 x^3.
Then the interpolation requirement leads to the following linear system.
c 1 = 0 , c 1 + c 2 + c 3 + c 4 = 1 , c 1 + 2c 2 + +4c 3 + 8c 4 = 2 , c 1 + 3c 2 + 9c 3 + 27c 4 = 7.
The solution is c 1 = 0, c 2 = 7/ 3 , c 3 = − 2 , c 4 = 2/ 3 , leading to the polynomal p(x) =
(7x − 6 x^2 + 2x^3 ).
(b) Any polynomial that takes zero values at the nodes can be added to p(x). Such a polynomial is
W (x) = ax(x − 1)(x − 2)(x − 3),
where a is an arbitrary constant. Of course, any polynomial multiple of W (x) is eligible as well; for example, xW (x) or (x − 4)(x − 5)W (x). (c) There is a unique polynomial of degree 3 passing through the first 4 points; the polynomial p(x) of part (a) above. It is easy to check that p(4) = 20, so that p(x) does not pass through (4, 7).
(a) Let the parabola through the last three data points be
p(x) = c 1 + c 2 (x − 40) + c 3 (x − 40)(x − 50).
Then, interpolation imposes the constraints
c 1 = 75 , c 1 + 10c 2 = 63 , c 1 + 20c 2 + 200c 3 = 54.
The solution is found to be c 1 = 75, c 2 = − 1. 2 , c 3 = 0. 015. Then, p(70) = 48.
(b) Let the cubic passing through the four points be
q(x) = c 1 + c 2 (x − 40) + c 3 (x − 40)(x − 50) + c 4 (x − 40)(x − 50)(x − 60).
Now the interpolation conditions lead to
c 1 = 75 , c 1 + 10c 2 = 63 , c 1 + 20c 2 + 200c 3 = 54 , c 1 − 15 c 2 + 375c 3 + 13125c 4 = 95.
Then, the new coefficient c 4 is given by
c 4 = − 2. 7619 × 10 −^4.
Then, q(70) = 49. 66.
We have f (x) = (x + 5)−^1 and the six nodes are 0, 2 , 4 , 6 , 8 , 10. If p 5 (x) is the interpolating polynomial, then the interpolation error is given by E(x) = f (x) − p 5 (x) =
f vi(c) 6! W (x)
where W (x) = x(x − 2)(x − 4)(x − 6)(x − 8)(x − 10). Now, f vi(c) = (−1)^6 6!(c + 5)−^7. Note that in the interval [0, 10] the maximum value of |f vi(c)| occurs at c = 0 and is given by 6!/ 57. Then, |E(1)| = |
f vi(c) 6!
Similarly, |E(5)| = |
f vi(c) 6!
We have f (x) = 1/x^3 , x ∈ [3, 4]. We seek an interpolating polynomial of degree 3. Therefore, there are n = 4 data points.
(a) For the interval [a, b] the Chebyshev points are
b + a 2
b − a 2
cos(jπ/8), j = 1, 3 , 5 , 7.
Here these points are
3 .5 + 0.5 cos(π/8), 3 .5 + 0.5 cos(3π/8), 3 .5 + 0.5 cos(5π/8), 3 .5 + 0.5 cos(7π/8),
or, when arranged in ascending order,
x 1 = 3. 5 − 0 .5 cos(π/8), x 2 = 3. 5 − 0 .5 cos(3π/8), x 3 = 3.5+0.5 cos(3π/8), x 4 = 3.5+0.5 cos(π/8).
lead to automatic continuity of S′′^ at x = 1 and x = 2. Furthermore, with the values of the ki determined as above, we note that
S(x) = 4 −
x + 2x^2 −
x^3
over the entire domain [0, 3]. Thus it is a not-a-knot spline.
x y 0 0
We wish to interpolate the data with a smooth curve in the hope of obtaining reasonable values of y for values of x between the points at which measurements were taken.
(a) Using any method that you like, determine the polynomial of degree 5 that interpolates the given data, and make a smooth plot of it (including clearly marked data points) on the interval x ∈ [0, 9]. (b) Determine a cubic spline that interpolates the given data, and make a smooth plot of it as above. (c) Which interpolant seems to give more reasonable values between the data points? Explain why each curve behaves the way it does. (d) Would piecewise linear interpolation be a better choice for these data? Why or why not?
The MATLAB code and figures are reproduced below. We note that the polynomial interpolant has a pronounced wiggle between the nodes 1 and 6, and also near the right end of the interval. The spline, on the other hand, has only a small hump between 1 and 6 and appears to be a better representation of the data. A piecewise linear interpolant would suffer from lack of smoothness, which may be unacceptable if the derivative of the interpolant is needed in an application.
% Script File HW4P7.m % Polynomial and spline fit to data % Provide data % x=[0,0.5,1,6,7,9]; y=[0,1.6,2.0,2.0,1.5,0]; % Compute polynomial interpolant p=polyfit(x,y,length(x)-1); % Plot data and interpolant xx=linspace(0,9); yy=polyval(p,xx); figure plot(x,y,’ro’,xx,yy,’LineWidth’,2); title(’Polynomial Interpolation’) % figure % Compute cubic spline interpolant pp=spline(x,y); % Plot spline interpolant zz=ppval(pp,xx); plot(x,y,’ro’,xx,zz,’g’,’LineWidth’,2) title(’Cubic Spline Interpolation’)
Problem 5.
The MATLAB code and figures are reproduced below.
% Script File HW4P5.m f=inline(’exp(abs(x))’); NN=[11,21]; for j=1: N=NN(j); % Specify Chebyshev Nodes i=1:N; xc=cos((pi/2/N)(2N+1-2i)); yc=f(xc); pc=polyfit(xc,yc,N-1); % Specify evenly-spaced nodes h=2/(N-1); x=-1+(i-1)h; y=f(x); p=polyfit(x,y,N-1); % Sampling points for plotting t=-1:0.01:1; ppc=polyval(pc,t); pp=polyval(p,t); % % Plot Chebyshev data points figure subplot(221), plot(xc,yc,’rs’,’MarkerSize’,7,’MarkerFaceColor’,’r’); hold on; % Plot Chebyshev interpolant plot(t,ppc,’r’);hold on; % Plot exact function plot(t,f(t),’k’,’LineWidth’,2) %legend(’Chebyshev data points’,’Chebyshev interpolant’); % % Plot evenly spaced data points % figure subplot(222), plot(x,y,’bs’,’MarkerSize’,7,’MarkerFaceColor’,’b’); hold on; % Plot polynomial interpolant plot(t,pp,’b’);hold on; % Plot exact function plot(t,f(t),’k’,’LineWidth’,2) ylim([1 2.8])
Figure 2: Results for n = 20. Top left: Chebyshev nodes and interpolant (in red) and exact function (in black). Top right: Evenly-spaced nodes and interpolant (in blue) and exact function (in black). Bottom left: Chebyshev interpolation error. Bottom right: Evenly-spaced interpolation error. Note that compared to the n = 10 case the Chebyshev interpolation error has almost been halved while the evenly-spaced interpolation error has increased by almost a factor of 100. The Runge phenomenon exhibited by the evenly-spaced interpolation is now the dominant feature.