function llsq_test03 ( )

%*****************************************************************************80
%
%% llsq_test03() calls LLSQ0 to match 15 data values.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    08 April 2018
%
%  Author:
%
%    John Burkardt
%
  n = 14;

  x_data = [ ...
    0.00; 0.10; 0.15; 0.20; 0.25; ...
    0.30; 0.35; 0.40; 0.45; 0.50; ...
    0.55; 0.60; 0.65; 0.7 ];

  y_data = [ ...
    0.0000;  0.0865;  0.1015;  0.1106;  0.1279; ...
    0.1892;  0.2695;  0.2888;  0.2425;  0.3465; ...
    0.3225;  0.3764;  0.4263;  0.4562 ];

  fprintf ( 1, '\n' );
  fprintf ( 1, 'llsq_test03()\n' );
  fprintf ( 1, '  LLSQ0 can compute the formula for a line of the form\n' );
  fprintf ( 1, '    y = A * x\n' );
  fprintf ( 1, '  which minimizes the RMS error to a set of N data values.\n' );

  a = llsq0 ( n, x_data, y_data );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Estimated relationship is y = %g * x\n', a );
  fprintf ( 1, '\n' );
  fprintf ( 1, '     I      X       Y          A*X      |error|\n' );
  fprintf ( 1, '\n' );
  error = 0.0;
  for i = 1 : n
    fprintf ( 1, '  %4d  %7f  %7f  %7f  %7f\n', ...
      i, x_data(i), y_data(i), a * x_data(i), a * x_data(i) - y_data(i) );
    error = error + ( a * x_data(i) - y_data(i) ).^2;
  end
  error = sqrt ( error / n );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  RMS error =                           %g\n', error );
%
%  Plot the data versus the approximate linear relationship.
%
  clf
  hold on
    x_line = linspace ( 0.0, 0.7, 101 );
    y_line = a * x_line;
    plot ( x_line, y_line, 'b-', 'Linewidth', 2 );
    plot ( x_data, y_data, 'r.', 'Markersize', 25 );
    grid on
    xlabel ( '<-- X -->' );
    ylabel ( '<-- Y -->' );
    title ( '  Data, and linear least squares line.' );
  hold off
%
%  Save a copy of the plot.
%
  filename = 'llsq_test03.png';
  print ( '-dpng', filename );

  return
end
