% PROB4BONA6  Solve problem 4(b) on Assignment #6: compute and plot the spline.

XY=[
0.1 0.98020;
0.2 0.92312;
0.3 0.83527;
0.4 0.72615;
0.5 0.60653;
0.6 0.48675;
0.7 0.37531];

x = XY(:,1)';
y = XY(:,2)';

xp = 0.1:.0005:0.7;
[yp, b, c, d] = bcd_ncspline(x,y,xp); % modified version of ncspline.m

set(0,'defaultlinelinewidth',2.0,'defaultlinemarkersize',12.0)
plot(x,y,'o',xp,yp), legend('data','natural cubic spline')
xlabel x, axis tight

for j=0:5
  lp = sprintf('(x - %.1f)',x(j+1));
  fprintf('S_%d(x) = %.5f + %.5f %s + %.5f %s^2 + %.5f %s^3\n',...
          j,y(j+1),b(j+1),lp,c(j+1),lp,d(j+1),lp)
end
