The fuel economy of a car (miles per gallon) varies with its speed. In an experi
ID: 1857049 • Letter: T
Question
The fuel economy of a car (miles per gallon) varies with its speed. In an experiment, the following five measurements are obtained: By hand: Determine the fourth-order polynomial in the Lagrange form that passes through the points. Use the polynomial to calculate the fuel economy at 65 mph. MATLAB: Use MATLAB built-in function interp1 to perform cubic spline interpolation (to calculate mpg at speeds ranging from 10 mph to 70 mph in increments of 5 mph) and generate a plot that shows both the original data points and interpolation points.Explanation / Answer
Cubic spline data interpolation
yy = spline(x,Y,xx)
pp = spline(x,Y)
yy = spline(x,Y,xx)uses a cubic spline interpolation to findyy, the values of the underlying functionYat the values of the interpolantxx. For the interpolation, the independent variable is assumed to be the final dimension ofYwith the breakpoints defined byx.
The sizes ofxxandyyare related as follows:
IfYis a scalar or vector,yyhas the same size asxx.
IfYis an array that is not a vector,
Ifxxis a scalar or vector,size(yy)equals[d1, d2, ..., dk, length(xx)].
Ifxxis an array of size[m1,m2,...,mj],size(yy)equals[d1,d2,...,dk,m1,m2,...,mj].
pp = spline(x,Y)returns the piecewise polynomial form of the cubic spline interpolant for later use withppvaland the spline utilityunmkpp.xmust be a vector.Ycan be a scalar, a vector, or an array of any dimension, subject to the following conditions:
If x and Y are vectors of the same size, the not-a-knot end conditions are used.
If x or Y is a scalar, it is expanded to have the same length as the other and the not-a-knot end conditions are used. (SeeExceptions(1)below).
If Y is a vector that contains two more values than x has entries, the first and last value in Y are used as the endslopes for the cubic spline. (SeeExceptions(2)below.)
IfYis a vector that contains two more values thanxhas entries, the first and last value inYare used as the endslopes for the cubic spline. IfYis a vector, this means
f(x) = Y(2:end-1)
df(min(x)) = Y(1)
df(max(x)) = Y(end)
IfYis a matrix or anN-dimensional array withsize(Y,N)equal tolength(x)+2, the following hold:
f(x(j))matches the valueY(:,...,:,j+1)forj=1:length(x)
Df(min(x))matchesY(:,:,...:,1)
Df(max(x))matchesY(:,:,...:,end)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.