% spline_sine.m generates a coarse sine curve, then interpolates with splines x = 0:12; % set up x data points, x=(0 1 2 3 ... 10) y = sin(x); % set up y data points subplot(3,1,1) % this is the first of three plots plot(x,y,'o') title('Data points from sine curve'); axis([min(x) max(x) -1.5 1.5]); xi = 0:.05:12; % x values for interpolation - finer than x yi = spline(x,y,xi); % interpolated y values subplot(3,1,2) % this is the second of three plots plot(x,y,'o',xi,yi) % plot data points and interpolated curve title('Data points and interpolating spline'); axis([min(x) max(x) -1.5 1.5]); yt = sin(xi); % values of y according to the sine function subplot(3,1,3) % this is the third of three plots plot(xi,yt-yi); % the difference between the true and interpolated title('Difference between interpolation and actual sine curve');