function sine_curve ( )

%*****************************************************************************80
%
%% sine_curve() looks at a sine curve with a few bad values.
%
%  Discussion:
%
%    The data is two-dimensional, but the Y values should vary in a
%    continuous way, so they can be analyzed by isoutlier().
%
%    However, if we look at the data, we see that there are some bad
%    values, which break the local pattern of the data, but do not 
%    stick out when considered within the whole set of y values.
%
%    We can spot these outliers by using a moving average, which
%    compares each Y value to an average value computed from the
%    nearby values.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 April 2018
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'SINE_CURVE:\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Set up data defining a sine curve, but perturb\n' );
  fprintf ( 1, '  several data values.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Because these perturbations are not extreme,\n' );
  fprintf ( 1, '  a simple outlier test will not work.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  However, MATLAB offers a moving average, which compares\n' );
  fprintf ( 1, '  each Y data value to a local average, and this works.\n' );
%
%  Generate the data.
%
  x = linspace ( 0.0, 4.0 * pi, 1001 );
  y = sin ( x );
  y(350) = 0.1;
  y(500) = y(500) - 0.3;
%
%  Apply a moving-average outlier analysis to the Y data.
%
  check = isoutlier ( y, 'movmedian', 5 );
  bad_index = find ( check );
%
%  Plot the data.
%
  plot ( x, y, '-b', x(bad_index), y(bad_index), 'r.', 'Markersize', 25 )
  grid ( 'on' )
  xlabel ( '<-- X -->', 'FontSize', 16 )
  ylabel ( '<-- SIN(X) -->', 'FontSize', 16 )
  title ( 'Y = SIN(X) (plus a few bad points) ', 'FontSize', 24 )
%
%  Add the least squares line through the data.
%
  filename = 'sine_curve.png';
  print ( '-dpng', filename )
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'SINE_CURVE:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end
