function lb = lagrange_base_1d ( nd, xd, ni, xi ) 

%*****************************************************************************80
%
%% lagrange_base_1d() evaluates a 1D Lagrange basis.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 October 2012
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer ND, the number of data points.
%
%    real XD(ND,1), the interpolation nodes.
%
%    integer NI, the number of evaluation points.
%
%    real XI(NI,1), the evaluation points.
%
%  Output:
%
%    real LB(NI,ND), the value, at the I-th point XI, of the
%    Jth basis function.
%
  lb = zeros ( ni, nd );
  
  w = zeros ( nd, 1 );

  for j = 1 : nd
    k = find ( 1 : nd ~= j );
    w(j) = 1.0 / prod ( xd(j) - xd(k) );
  end

  for i = 1 : ni
    lx = prod ( xi(i) - xd(1:nd) );
    lb(i,1:nd) = ( lx * w(1:nd) ./ ( xi(i) - xd(1:nd) ) )';
  end

  return
end
