function value = hat ( x1, x2, x3, x )

%*****************************************************************************80
%
%% hat evaluates a "hat" function with nodes x1 < x2 < x3.
%
%  Input:
%
%    real x1, x2, x3: the three consecutive nodes used by the hat function.
%
%    real x: the point at which the hat function is to be evaluated.
%    x can be a vector.
%
%  Output:
%
%    real value: the value of the hat function at x.
%
  value = ( x1 <= x & x < x2 ) .* (  x - x1 ) ./ ( x2 - x1 ) ...
        + ( x2 <= x & x < x3 ) .* ( x3 - x  ) ./ ( x3 - x2 );
  return
end

