% banasplin.m,  naturliga splines
  x=[0.5 1.5 2.5 3 4 5]';  y=[3 1.5 1.5 1 1 0]'; 
  subplot(2,2,2), plot(x,y,'o'), axis equal, hold on
  h=diff(x);  dy=diff(y);
  dm=2*(h(2:5)+h(1:4));  dia=[2*h(1); dm; 2*h(5)];   
  supd=[h(1); h(1:4)];   subd=[h(2:5); h(5)];   
  bm=3*(h(1:4).*dy(2:5)./h(2:5) + h(2:5).*dy(1:4)./h(1:4));
  b=[3*dy(1); bm;  3*dy(5)];
  k=tridia(dia,supd,subd,b)
  g=h.*k(1:5)-dy;  c=2*dy-h.*(k(1:5)+k(2:6)); 
  t=0:0.1:1;
  for i=1:5         % Beräkna polynomvärdena i de fem delintervallen
    xt=x(i)+t*h(i);
    yt=y(i)+t*dy(i)+t.*(1-t)*g(i)+t.^2.*(1-t)*c(i);  plot(xt,yt,'--')
  end
  title('Naturliga splines')



