For the given x-y data points in table below, use linear, spline and cubic interpolation methods to calculate the value of y. Plot data points and graphs of three interpolation methods on the same figure. Find the value of y for x=7 using three interpolation methods.
x=1:5;
y=[0.8530 0.6221 0.3510 0.5132 0.4018];
x2=1:0.01:10;
ylin=interp1(x,y,x2,'linear');
yspl=interp1(x,y,x2,'spline');
ycub=interp1(x,y,x2,'cubic');
plot(x2,ylin,'r',x2,yspl,'k',x2,ycub,'s');
fprintf('at x=7 value:\n');
fprintf('linear: %f\n spline: %f\n cubic: %f',ylin(7),yspl(7),ycub(7));
引用格式
Arthur Matlabus (2026). simple, linear and cubic calculation for plot (https://ww2.mathworks.cn/matlabcentral/fileexchange/167331-simple-linear-and-cubic-calculation-for-plot), MATLAB Central File Exchange. 检索时间: .
