function least_squares_plots ( )

%*****************************************************************************80
%
%% LEAST_SQUARES_PLOTS: plot data, least squares line, exact formula.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    19 July 2018
%
%  Author:
%
%    John Burkardt
%
  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'LEAST_SQUARES_PLOTS\n' );
  fprintf ( 1, '  MATLAB/Octave version %s:\n', version ( ) );
  fprintf ( 1, '  Compare 15 data points with the least squares line\n' );
  fprintf ( 1, '    y = A * x + B\n' );
  fprintf ( 1, '  which minimizes the root-mean-square error.\n' );
  fprintf ( 1, '  The data is actually perturbed values of a quadratic\n' );
  fprintf ( 1, '  formula, which is shown for comparison:\n' );
  fprintf ( 1, '    y = 1/2 x^2 + 1\n' );
%
%  Read the 15 data points.
%
  filename = 'least_squares1_data.txt';
  xy_data = load ( filename );
%
%  Read two points on the least squares line
%
  filename = 'least_squares2_data.txt';
  xy_lsq = load ( filename );
%
%  Read data on the exact formula.
%
  filename = 'least_squares3_data.txt';
  xy_exact = load ( filename );
%
%  Plot three curves on one image.
%
  clf ( );
  hold ( 'on' );
    plot ( xy_lsq(:,1), xy_lsq(:,2), 'r-', 'Linewidth', 2 );
    plot ( xy_data(:,1), xy_data(:,2), 'b.', 'Markersize', 25 );
    plot ( xy_exact(:,1), xy_exact(:,2), 'g-', 'Linewidth', 2 );
    grid ( 'on' );
    xlabel ( '<-- X -->' );
    ylabel ( '<-- Y -->' );
    title ( '  Formula (green), Data (blue), least squares fit (red).' );
  hold ( 'off' );

  pause ( 5 )
%
%  Save graphics to a file.
%
  filename = 'least_squares_plots.png';
  print ( '-dpng', filename );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Graphics file saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'LEAST_SQUARES_PLOTS\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( );

  return
end
