% spline_demo % load the splines package (needed for octave only) pkg load splines % delete all existing figures all_figs = findobj(0, 'type', 'figure'); delete(all_figs); % close all x = [0 1 2]; y = [-1 -1 7]; z = linspace(0, 2, 300); figure(1) % natural spline [s, ds, dds] = dcubicspline(x, y, z); plot(z, s, z, ds, z, dds, x, y, '*') title('natural spline - 2nd derivative = 0 at endpoints') type = 0; der = [0 0]; figure(2) % spline with first derivative at endpoints = der [s, ds, dds] = dcubicspline(x, y, z,type,der); plot(z, s, z, ds, z, dds, x, y, '*') title('complete spline - 1st derivative = 0 at endpoints') figure(3) % spline and 1st derivative plot(z, s, z, ds, x, y, '*') title('complete spline - spline + 1st derivative') figure(4) % lagrange interpolating polynomial and 1st derivative c = polyfit(x,y,2); d = polyder(c); % coefficients in derivative p = polyval(c,z); dp = polyval(d,z); plot(z,p,z,dp,x,y,'*') title('quadratic lagrange interpolating polynomial + 1st derivative')