Write a Matlab function that interpolates 4 points x1y1 x2y2
Write a Matlab function that interpolates 4 points, {(x1,y1), (x2,y2), (x3,y3),
(x4,y4)}, using three cubic splines with zero-derivative clamping at the end points. The function syntax should be yy= name(x,y,xx) where x = [x1 x2 x3 x4], y = [y1 y2 y3 y4], xx is a vector of x-values to be interpolated and yy is an output vector of interpolated values corresponding to xx. In addition to the function, you should submit a Matlab generated graph that shows a plot of the splines and the four data points. For testing purposes, assume the following data set: {(1,1), (2,-2), (3,0), (4,2)}. Use the following limits for your plot: [xmin xmax ymin ymax]=[1 4 -2.5 2]. Your function must not employ any built-in Matlab interpolation/spline functions. Your function must work for any set of four distinct points.
Write a Matlab function that interpolates 4 points, {(x1,y1), (x2,y2), (x3,y3), (x4,y4)}, using three cubic splines with zero-derivative clamping at the end points. The function syntax should be yy= name(x,y,xx) where x = [x1 x2 x3 x4], y = [y1 y2 y3 y4], xx is a vector of x-values to be interpolated and yy is an output vector of interpolated values corresponding to xx. In addition to the function, you should submit a Matlab generated graph that shows a plot of the splines and the four data points. For testing purposes, assume the following data set: {(1,1), (2,-2), (3,0), (4,2)}. Use the following limits for your plot: [xmin xmax ymin ymax]=[1 4 -2.5 2]. Your function must not employ any built-in Matlab interpolation/spline functions. Your function must work for any set of four distinct points.Solution
Function yy= name(x,y,xx)
xx=[ 1 2 3 4 ];
yy=[-2 0 1 2 ];
xval=linspace(1,4,0.5); % test abscissae for plotting
yval=linspace(-2.5,2,0.5);
yvalTrue=polyval(xval,yval); % true ordinates
yvalVander=polyval(cVander,xval); % our ordinates
plot(xval,yvalTrue,\'g\',\'linewidth\',4); % true curve: thick green
hold on
plot(xval,yvalVander,\'k\'); % interpolant curve: thin black
hold off
max(abs((yvalTrue-yvalVander)))/max(abs(yvalTrue))
% In order to work for distinct points replace xx and yy with the set of distinct points
