function interp_trig_test ( )

%*****************************************************************************80
%
%% INTERP_TRIG_TEST tests INTERP_TRIG.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    02 February 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../interp_trig' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'INTERP_TRIG_TEST\n' );
  fprintf ( 1, '  MATLAB version:\n' );
  fprintf ( 1, '  Test INTERP_TRIG.\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Use interpolant test function #5\n' );
  interp_trig_test01 ( @f5 );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'INTERP_TRIG_TEST\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../interp_trig' );

  return
end
function interp_trig_test01 ( f )

%*****************************************************************************80
%
%% INTERP_TRIG_TEST01 tests INTERP_TRIG on a particular function.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    02 February 2019
%
%  Author:
%
%    John Burkardt
%
  xmin = 0.0;
  xmax = 1.0;

  for log2n = 1 : 6

    nd = 2 ^ log2n;

    xd = linspace ( xmin, xmax, nd );
    yd = f ( xd );

    ni = 101;
    xi = linspace ( xmin, xmax, ni );
    yi = interp_trig ( xd, yd, xi );

    ye = f ( xi );

    plot ( xd, yd, 'k.', ...
           xi, yi, 'b-', ...
           xi, ye, 'r-', 'Markersize', 35, 'Linewidth', 3 );

    filename = sprintf ( 'interp_trig_test_%d.png', nd );
    print ( '-dpng', filename );
    fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  end

  return
end
function value = f1 ( x )

%*****************************************************************************80
%
%% F1 evaluates trigonomentric interpolation test function #1.
%
%  Discussion:
%
%    F1(0) does not equal F1(1).
%
  value = ( x - 0.5 ) .* ( x - 0.25 ) .* ( x - 1.2 ) .* ( x - 2.0 );

  return
end
function value = f2 ( x )

%*****************************************************************************80
%
%% F2 evaluates trigonomentric interpolation test function #2.
%
%  Discussion:
%
%    F1(0) equals F1(1).
%
  v0 = f1(0.0);
  v1 = f1(1.0);
  value = f1(x) + x * ( v0 - v1 );

  return
end
function value = f3 ( x )

%*****************************************************************************80
%
%% F3 evaluates trigonomentric interpolation test function #3.
%
%  Discussion:
%
%    F3 is periodic but nondifferentiable at an interior point.
%
  value = ( 3.0 * x <= 1.0 ) .* 3.0 .* x ...
        + ( 1.0 <= 3.0 * x ) .* 1.5 .* ( 1.0 - x ); 

  return
end
function value = f4 ( x )

%*****************************************************************************80
%
%% F4 evaluates trigonomentric interpolation test function #4.
%
%  Discussion:
%
%    F4 is periodic but discontinuous.
%
  value = ( 4.0 * x <= 1.0 ) .* 3.0  ...
        + ( 1.0 <= 4.0 * x ) .* ( 4.0 * x <= 2.0 ) * 5.0 ...
        + ( 2.0 <= 4.0 * x ) .* ( 4.0 * x <= 3.0 ) * 9.0 ...
        + ( 3.0 <= 4.0 * x ) .* 3.0; 

  return
end
function value = f5 ( x )

%*****************************************************************************80
%
%% F5 evaluates trigonomentric interpolation test function #5.
%
%  Discussion:
%
%    F5 is linear.
%
  value = 2.0 * x + 1.0;

  return
end

