function [ u_h, dudx_h ] = fe_linear2 ( f, x, xc )

%  FE_LINEAR2 evaluates the finite element solution and derivative at every X.
%
%  [ u_h, dudx_h ] = fe_linear2 ( f, x, xc )
%
%  F(NX) is the finite element coefficients.
%  X(*) is the point or points at which to evaluate.
%  XC(NX) is the set of nodes.
%
%  U_H(*) is the value of U at every X.
%  DUDX_H(*) is the value of dUdX at every X.
%
%  This version tries to be more efficient by only evaluating the two nonzero
%  basis functions.

%
%  Find the value XC(LEFT) just to the left of X.
%
  left = bracket ( x, xc );
%
%  The solution value U is a weighted sum of the basis functions
%  LEFT and LEFT+1.
%
  u_h = 0.0;
  dudx_h = 0.0; 

  for i = left : left+1

    [ bi, dbidx ] = bf_linear ( i, x, xc );

    u_h    = u_h    + f(i) *  bi;
    dudx_h = dudx_h + f(i) * dbidx; 

  end
