function [C,L] = lagran(X,Y)
% [C] = lagran(X,Y)
% [C,L] = lagran(X,Y)
% Construction of the collocation polynomial.
% The method is Lagrange interpolation.
% X is the list of abscissas, input.
% Y is the list of ordinates, input.
% W is the coefficient list for the polynomial, output.
% L is the matrix for the Lagrange coefficient polynomials, output.
n1 = length(X);
n = n1-1;
L = zeros(n1,n1);
for k=1:n+1, % Form the Lagrange coefficient polynomials
V = 1; % by using poly(r1) to create a polynomial
for j=1:n+1, % with a known root, and conv(P2,P1)
if k ~= j, % which is polynomial multiplication.
V = conv(V,poly(X(j)))/(X(k)-X(j));
end
end
L(k,:) = V;
end
C = Y*L;