Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Assignment sheet for Sections 5.1, 5.3, 5.5, 5.6, 5.7, 5.8
Read Pages 341 - 349
Exercises for Section 5.1 Lagrange Interpolation #1, #4, #7, #13, #14
California Problem
Enter the data in Table 2, into MATLAB. Call the years x and the populations y.
Use routine divpoly in MATLAB do the following.
a) The population in 1930 was about 5.7 million. Evaluate the interpolation polynomial to
the data in Table 2 at x = 30. Compute the absolute and relative error in the value
obtained from the evaluation of the interpolant.
b) Use divpoly as in part a, but predict the populations in 1985, 2000, and 2010. Do
these values seem reasonable? Explain.
c) Use routine pinterp with the data in Table 2 and sketch the interpolant over 1900 to
2010 by setting the minimum value of x to 0 and the maximum to 110. Print out the
graph and annotate it to explain your answers to parts a and b. (Generate the sketch
with y-coordinates 0.)
DD-Table Problem
Given the following divided difference table.
0th DD 1st DD 2nd DD 3rd DD 4th DD
4
a
f
7
m
g
r
n
h
10
t
s
p
k
12
(a) Write an expression for the interpolant that goes through the set of ordered pairs
{(4,a), (7,b), (9, c)}.
(b) Write an expression for the interpolant that goes through the set of ordered pairs
{ (7,b), (9, c), (10, d), (12, e)}.
(c) The point (15, w) is to be added to the table. Write and expression for the interpolant
through the ordered pairs {(12, e), (15, w)}.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
plot(px,py,'*r'), figure(gcf)
Experiment with this a few times to get the feel for the mouse and think about where
you will collect the sample data.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#2. Next type
hold off,close(gcf)
followed by
iprob,figure(gcf),axis(axis),hold on
to get a fresh picture. Use the following commands to sample the curve at 6 points
and generate a polynomial interpolant of degree 5.
[sx sy]=ginput(6) %collect the 6 point sample using your mouse
plot(sx,sy,'*r'),figure(gcf) %plotting the sample
A=vander(sx);c5=A\sy; % set up Vandermode matrix &
%solve for coefficients of quintic interpolant
z5=polyval(c5,x); % evaluate quintic model at x-coords for the curve
plot(x,z5,':k'),figure(gcf) % plot the cubic model
If your model isnt very good to start anew type
hold off,close(gcf)
followed by
iprob,figure(gcf),axis(axis),hold on
then repeat the code for sampling. Once you get a good approximation to the curve,
put your name in the title of the graph and print it out. Turn in your graph.
#3. Repeat Exercise 2, but this time sample the curve at 20 point instead of 6. If your
model isnt very good to start anew type
hold off,close(gcf)
followed by
iprob,figure(gcf),axis(axis),hold on
then repeat the code for sampling. Were there any warnings from MATLAB? If so copy
them as part of your solution. Try to get a good approximation to the curve, put your
name in the title of the graph and print it out. Were you able to get a good
approximation? Discuss you attempts. Turn in your graph.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#4. An alternative to polynomial interpolation through an entire data set is to construct
polynomial interpolants to subsets of the data. Thus different polynomials can be used
over subintervals of the data points involved. The simplest such procedure is piecewise
linear interpolation which amounts to connecting successive data points with straight
lines (connect-the-dots). While the interpolating function constructed in this way is
continuous, it is usually not differentiable because sharp points occur at the data
points. Such procedures generalize to piecewise quadratic and piecewise cubics by
appropriately subdividing the data set into successive subsets of three and four points
respectively with one point overlap to ensure continuity. To experiment with piecewise
polynomial interpolation of this type use routine pwinterp. A brief description follows.
PWINTERP Piecewise polynomial interpolation using:
LINEAR QUADRATIC or CUBIC pieces.
INPUT: Vectors x and y must contain the x and y
coordinates of the data points respectively.
OUTPUT: The coefficients the pieces are in arrays
lf qf and cf respectively.
Various interpolants can be superimposed graphically.
=> pwinterp(x,y) or [lf,qf,cf]=pwinterp(x,y) <=
x
Consider the serpentine curve' f(x)
over [-2, 2] .
0.25 x 2
In MATLAB type figure
(a) Sketch the curve f(x) using routine ezplot. Print out the curve or draw a facsimile.
(b) Let x = [-2, -1, -0.5, -0.25, 0, 0.25, 0.5, 1, 2] be the x-coordinates of sample points.
Enter this vector of data in to MATLAB. Compute the corresponding y-coordinates in
MATLAB using command y = x./(0.25+x.*x); Record the data set.
(c) Use pinterp to construct the polynomial interpolant to this data and graph it. (Set the
viewing window so that -2 x 2 and -11 y 11. Superimpose the graph of f(x)
entering the formula as x/(0.25 + x^2). Briefly discuss the approximation qualities of
the polynomial model. Print out the superimposed graph or draw a facsimile.
(d) Use pwinterp on the data from part (b). Print out each of the three possible
models.
Briefly discuss the approximation qualities of the piecewise polynomial models.
Which model seems better than the others and why?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Read Pages 393 402 ; Read the document splinedefs. See the website.
Exercises for Section 5.6 Cubic Spline Interpolation #1, 2, 3, 10, 15, and H1
Use MATLAB files for spline computations. Display the coefficients of the cubic pieces
in all the problems. The mfiles are nspline, cspline, and nakspline. It is assumed that
you have read the document splinedefs. See also Section 5_6 Example with details.
f(x)
f(x)
-1
-.79
-.15
-1.0
-1.0
-14.6
-49.0
3x
c) The function sample is from f(x) = 2xe e . Compute the absolute error in each of
the results from parts a and b.
d) Graph the absolute error expressions for parts a and b over [-1,1]. Comment on the
accuracy of part a vs that in part b.
2. A switching track is to be constructed between a pair of parallel trolley tracks as
shown in the figure. The transition between the two tracks is to be smooth. Assume that
the tracks are horizontal and the switch points have coordinates (3,2) and (0,0) on
tracks #1 and #2 respectively. Construct a Hermite interpolating polynomial that goes
through the points and matches the slope of the track at each of the two points.
Generate a graph of your track over [0,3].
LM n x 2 n x OP
i iP
M
i 1
provided the matrix C M i n1
is nonsingular. To verify that this is indeed true
P
MM xi n PP
N i 1
Q
LM x1 1OP
MMx2 1PP
when all the x are distinct we use the matrix formulation, C = A A, where A = .
MM PP
MNxn 1PQ
Lk1 O
Let k M P . Then we know the following: the homogeneous linear system Ck = 0 has
Nk 2 Q
i
only the trivial solution if and only if matrix C is nonsingular. Verify the following to show
that C is nonsingular.
a) Explain why the columns of A are linearly independent.
b) Explain why Ak can only be equal to the zero vector 0 if k = 0.
c) Explain why kTAT = (Ak)T.
d) Assume Ck = 0. Explain why (Ak)T(Ak) = 0. (Note: the right side is the zero scalar.)
e) Explain why (Ak)T(Ak) = 0 is the same as the dot product (Ak)(Ak) = 0.
f) When can the dot product of a vector with itself be zero?
g) Use parts b, e, and f to explain why k = 0 and hence C is nonsingular.
2. For a given data set S, let line L be the least squares line and E L be the minimum
value of the sum of the squares of the deviations. For the same data set D let quadratic
Q be the least squares quadratic and EQ be the minimum value of the sum of the
squares of its deviations. Why must EQ EL? (Hint: We can think that the least squares
process for determining L looks over all polynomials of degree 1 or less to determine
the one that minimizes the sum of the squares of the deviations. Similarly, the least
squares process for determining Q looks over all polynomials of degree 2 or less.)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++