function value = trig_basis ( x, k )

%*****************************************************************************80
%
%% trig_basis() evaluates a trigonometric cardinal function.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 July 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real x(*), the evaluation points.
%
%    integer k, the order of the cardinal function.
%    K should be 1 or greater.
%
%  Output:
%
%    real value(*), the value of the cardinal function at the points.
%    

%
%  Suppress the "divide by zero" warning.
%
  ws = warning ( 'off', 'MATLAB:divideByZero' );

  if ( rem ( k, 2 ) == 1 )
    value =      sin ( k * pi * x / 2.0 ) ...
        ./ ( k * sin (     pi * x / 2.0 ) );
  else
    value =      sin ( k * pi * x / 2.0 ) ...
        ./ ( k * tan (     pi * x / 2.0 ) );
  end
%
%  Restore the warning.
%
  warning ( ws )
%
%  Fix the value at 0.
%
  value ( x == 0.0 ) = 1.0;

  return
end

