function diff_trig_test ( )

%*****************************************************************************80
%
%% diff_trig_test applies diff repeatedly to y=sin(x), with equal spacing.
%
%  Discussion:
%
%    Each order of diff shortens the vector by one entry.
%
%    If equal spacing is used, then I presume that each diff value is 
%    associated with the average of the of the x coordinates of the diff 
%    values one level earlier.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 August 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'diff_trig_test\n' );
  fprintf ( 1, '  For sin(x) at x values spaced by h,\n' );
  fprintf ( 1, '  compute first, second and third differences,\n' );
  fprintf ( 1, '  divided by appropriate power of h,\n' );
  fprintf ( 1, '  and compare to corresponding derivatives.\n' );

  h = 0.01;
  x = 0.0 : h : pi;
  y = sin ( x );
  y1 = diff ( y, 1 ) / h;
  y2 = diff ( y, 2 ) / h^2;
  y3 = diff ( y, 3 ) / h^3;

  offset = 0.25;

  clf ( );
  hold ( 'on' );
  plot ( x(1:end-1)+h/2,   y1+offset, 'r-', 'linewidth', 3 );
  plot ( x,                cos(x),    'b-', 'linewidth', 3 );
  title ( 'First difference and derivative, slightly offset for comparison' );
  grid ( 'on' );
  hold ( 'off' );
  filename = 'diff_trig_test1.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  pause ( 5 );

  clf ( );
  hold ( 'on' );
  plot ( x(1:end-2)+2*h/2, y2+offset, 'r-', 'linewidth', 3 );
  plot ( x,                -sin(x),   'b-', 'linewidth', 3 );
  title ( 'Second difference and derivative, slightly offset for comparison' );
  grid ( 'on' );
  hold ( 'off' );
  filename = 'diff_trig_test2.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  pause ( 5 );

  clf ( );
  hold ( 'on' );
  plot ( x(1:end-3)+3*h/2, y3+offset, 'r-', 'linewidth', 3 );
  plot ( x,                -cos(x),   'b-', 'linewidth', 3 );
  title ( 'Third difference and derivative, slightly offset for comparison' );
  grid ( 'on' );
  hold ( 'off' );
  filename = 'diff_trig_test3.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  pause ( 5 );

  return
end

