simple, linear and cubic calculation for plot

matlab code for spline and cubic plot

您现在正在关注此提交

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. 检索时间: .

标签

添加标签

Add the first tag.

一般信息

MATLAB 版本兼容性

  • 兼容任何版本

平台兼容性

  • Windows
  • macOS
  • Linux
版本 已发布 发行说明 Action
1.1.0

change

1.0.0