simple, linear and cubic calculation for plot

matlab code for spline and cubic plot

You are now following this Submission

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));

Cite As

Arthur Matlabus (2026). simple, linear and cubic calculation for plot (https://uk.mathworks.com/matlabcentral/fileexchange/167331-simple-linear-and-cubic-calculation-for-plot), MATLAB Central File Exchange. Retrieved .

Tags

Add Tags

Add the first tag.

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.1.0

change

1.0.0