function l = lagrange(x, xj)
% LAGRANGE - evaluate all lagrange poly's at x, ie l_k(x) for k=0...n
% by Brad Nelson 1/22/12
% Inputs: x is a single coordinate, and xj is a row vector of nodes x_0,...,x_n  
% Outputs: l is a column vector containing the values l_0(x),...,l_n(x)

n=numel(xj);
l=zeros(n,1);
for k=1:n;
    xjmod=[xj(1:k-1) xj(k+1:n)];
    l(k)=prod((xj(k)-xjmod).\(x-xjmod));
end