function Splines = ClampedSplines(x,f,df)
%
% This code implements the clamped splines
%
% Written by Ming Gu for Math 128A, Fall 2008
%
n = length(x);
h = diff(x(:));
rhs = 3 * diff([df(1);diff(f(:))./h;df(end)]);
A = zeros(n,n);
for k=1:n-1
    A(k,k+1) = h(k);
    A(k+1,k) = h(k);
    A(k,k)   = 2 * h(k);
end
for k=2:n
    A(k,k)   = A(k,k)+2 * h(k-1);
end
%
% compute the c coefficients. This is a simple 
% but very slow way to do it.
%
c         = A \ rhs;
d         = (diff(c)./h)/3;
b         = diff(f(:))./h-(h/3).*(2*c(1:n-1)+c(2:n));
Splines.a = f(:);
Splines.b = b;
Splines.c = c;
Splines.d = d;
