MATH 3650 Homework 9
MATH 3650 Homework 9
(a) Use Matlab to interpolate these points using 1) a polynomial, 2) a cubic spline, and 3)
a piece-wise linear function. Create a plot with the points and the three curves (in one
plot, include a legend).
Make sure all methods go through the data points.
Hint: You do not need to compute the piece-wise linear function, you can just ask
Matlab to connect the points with straight lines.
(b) Compute and output the value of the interpolating function at x = 1 for the three
methods.
Hint: Now you need to implement the expression for the segment of the piece-wise linear
interpolant that contains the point x.
(c) Compute the slope at x = 1 using the centered difference formula with h = 10−3 for the
three methods.
Submit code hw09q1.m that produces the plot and all other output when run.
(a) Create the matrix to determine the coefficients of the interpolating polynomial (see
ch8_interpolate_polynomial.m ) for n = 2 up to n = 14 and compute the condition
number (using the infinity norm).
(b) Based on the output from a) and your knowledge about errors in linear systems, for
which values of n do you expect small errors in the coefficient (10 accurate decimal
digits)? Why? Give your answer using fprintf .
(c) Based on the output from a) and your knowledge about errors in linear systems, for
which values of n do you expect the results to be useless (all digits could be incorrect)?
Why? Give your answer using fprintf .
(a) Write a function [a0,a1] = fit_line(x,y) that computes the line of best fit to a
given set of points (xi , yi ) given as a vector of x coordinates and a vector of y coordinates
and returns the coefficients a0 and a1 that describe the line of best fit L(x) = a0 + a1 · x.
(b) Using the function fit_line compute the line, exponential, and power fit to the data
points given in the file hw09q3_base.m . Create a plot that shows the points and the
three curves. Include a legend. Also print out the equations with coefficients for the
three curves.
1
Submit: fit_line.m and hw09q3.m that produces the plot.
4. (a) Manually compute an interpolating polynomial of the points (0, 1), (π/2, 1), (π, 0). Is
this polynomial unique?
(b) The data points above could be from a signal that we know is 2π periodic, so it makes
sense to find an interpolant that is periodic as well (which our polynomial from a) is
not). Let us find the coefficients a1 ,a2 ,a3 with
that interpolate the points in part a). Hint: Start with the definition of interpolation.
The process is very similar to a), except that the linear system is slightly different.