Sie sind auf Seite 1von 9

Assignments for Bradie Fall 2016 for Chapter 5

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

For #1 use MATLAB to draw the graphs.


For #4 do part (d) carefully.
For #13 use MATLAB routine pinterp; capture the formula and graph to include with
your answer to the question.
For #14 part (b) use MATLAB routine pinterp capture the formula and graph to include
with your answer to part (c).
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Read Pages 363 369
Exercises for Section 5.3 Divided Difference Form of Interpolation #3, #6, #7, #10, #11, #15, California
Problem, DD-Table Problem

For #3 and #6 do the calculations by hand; show the work.


For #7 construct the divided difference table by hand; do not compute the values of any
logarithms.
For #15 use MATLAB routines divdiff and divpoly; include print outs from MATALB.

California Problem

Consider the following population data for the state of California.


Year
1940
1950
1960
1970
1980
1990
Population
6.9
10.5
15.7
19.9
23.6
29.7
in Millions
Table 1.
We are to build an interpolation polynomial model to this data. To simplify the values
involved and also possibly to aid in the prevention of roundoff error we 'rescale' the data
as follows.
Year
40
50
60
70
80
90
Population
6.9
10.5
15.7
19.9
23.6
29.7
in Millions
Table 2.

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)}.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Section 5.5 Piecewise Interpolation

Read my Notes for Piecewise Interpolation

Do the following Exercises.


#1. Given a curve, collect a sample of points, generate the corresponding polynomial
interpolant, and then compare the graph of the interpolant with the original curve.
Since a limited sample of points will be permitted it is important to take the sample
from portions of the curve that in some sense control or significantly affect its shape.
Such a strategy can aid the model constructed by the interpolant, but is not a
guarantee that the model produced will match the shape of the entire curve.
Enter the following MATLAB commands:
help iprob
To see a picture of the curve you are asked to sample and build an interpolation
model for, type iprob,figure(gcf)
The x-coordinates are in the vector x and the y-coordinates in the vector y.
To retain this image so we can superimpose models you create, type
axis(axis),hold on
PRACTICE SAMPLING THE CURVE
MATLAB has a command that lets us sample a curve
using your mouse. For a description type
help ginput
To try this command we will collect a sample of 3 points from
the curve. Type command [px py] =ginput(3)
Position your mouse over the curve and click the left mouse button when you are at
the point you want to include in the sample. Press ENTER after you have selected
the 3 points. The coordinates will be displayed. To see your points on the graph use
the following commands.

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.

H1. Section 5.6


The 1995 Kentucky Derby was won by a horse named Thunder Gulch in a time of 2:01
1/5 (2 min 1 and 1/5 sec) for the 1.25 mile race course. Times at the quarter mile, halfmile, and mile poles were 22.4 secs, 45.8 secs, and 1 min 35.6 secs.
a) Use the previous data together with the initial data, t = 0, dist = 0, to construct a
natural cubic spline for Thunder Gulch's race.
b) Use the spline to predict the time at the three-quarter-mile pole, and compare this to
the actual time of 1 min 10.2 secs.
c) Use the spline to predict the speed at which Thunder Gulch left the starting gate and
the speed at which he crossed the finish line. Give answers in miles per hour.
Show all your work.
For #1, discuss the question also discuss the type of relationship between z an T
implied by the spline.
For #2, discuss the question also discuss the type of relationship between z an p
implied by the spline.
For #10 use the MATLAB routines to generate the requested graphs. Include a copy of
the graphs as part of your solution.
For #15, include a graph of the error for the natural cubic spline.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Read pages 405-418


Section 5.7 Hermite Interpolation and Cubic Hermite Interpolation #8, 10 (in the
text) There is an mfile for the data set for #8 & 10; Bradie_data_Sec5_7_Exer8.m
Dr. Hills problems #1, 2, 3

For #8 use MATLAB routine pwhermitecubic.m .


For #10 use MATLAB routine cspline.m .
IMPORTANT: For Dr. Hills problems use the generalization of divided differences
to compute any Hermite interpolation polynomial. Show the divided difference
tables for each problem.

1. The following sample of function


f is given.
a) Approximate f(0.5)
using a polynomial interpolant.
b) Approximate f(0.5) using a
Hermite interpolant.
x

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].

3. At another construction site a switching track like that in Exercise 2 is to be


constructed with an additional requirement. Namely, the track must also go through
point (1,1). Modify the result from Exercise 2 to include this requirement. Generate a
graph of your track over [0,3]. Are there any construction difficulties in this case?
Explain.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Read Pages 418 425
Exercises for Section 5.8 Regression #2, 5, 8, 13, and Dr. Hills problems
Use MATLAB and the matrix approach for computing least squares lines and
linearized fits.
Use MATLAB to generate appropriate graphs for #2 and 13

Dr. Hills problems.


1. The normal system of equations for the least squares line has a unique solution

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.)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Das könnte Ihnen auch gefallen