MATLAB: Interpolation methods to calculate the value of y

interpolationMATLAB

use linear, spline and cubic interpolation methods to calculate the value of y. Plot data points and graphs of three interpolation methods.Estimate the value of y for x = 7.5 using three interpolation methods. displayyour results along with text which technique was used to produce each value.
x = [10 20 30 40 50];
y = [0.9530 0.7221 0.4510 0.6132 0.5518];
this is what I got, but I do not know if it any correct
x = [10 20 30 40 50];
y = [0.9530 0.7221 0.4510 0.6132 0.5518];
plot(x,y,'ob')
xi=1:0.1:10;
method=char('linear','cubic','spline');
col={'--r',':g','-k'};
for k=1:3
yi{k}=interp1(x,y,xi,method(k,:));
hold on;
plot(xi,yi{k},col{k})
end
legend('linear','cubic','spline', 'Location', 'best');
title(sprintf('x = 7.5 y is %.2f ',polyval(fit,7.5)))
y1=yi{1};
y2=yi{2};
y3=yi{3};

Best Answer

x = [10 20 30 40 50];
y = [0.9530 0.7221 0.4510 0.6132 0.5518];
plot(x,y,'ob')
xi=min(x):0.1:max(x);
method=char('linear','cubic','spline');
col={'--r',':g','-k'};
yi = zeros(3,length(xi)) ;
for k=1:3
yi(k,:)=interp1(x,y,xi,method(k,:));
end
plot(xi,yi) ;
legend('linear','cubic','spline', 'Location', 'best');
% title(sprintf('x = 7.5 y is %.2f ',polyval(fit,7.5)))