function errors_test10 ( )

%*****************************************************************************80
%
%% errors_test10() seeks the nearest straight line to given data.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    21 August 2017
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '+=============================================+\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|  Exercise 10                                |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|  For the data:                              |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|       X       Y                             |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|    5201477   99999                          |\n' );
  fprintf ( 1, '|    5201478  100000                          |\n' );
  fprintf ( 1, '|    5201479  100001                          |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|  Find the "nearest" straight line:          |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|    Y(X) = A * X + B                         |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|  in the least squares sense.                |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|  Correct values:                            |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|    A = 1.0                                  |\n' );
  fprintf ( 1, '|    B = - 5101478                            |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|  Evaluate:                                  |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|    Y(5201480)                               |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|  Correct value:                             |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '|    Y(5201480) = 100002.0                    |\n' );
  fprintf ( 1, '|                                             |\n' );
  fprintf ( 1, '+=============================================+\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '                    Slope A    Intercept B    Y(5201480)\n' );
  fprintf ( 1, '\n' );

  x1 = 5201477.0;
  x2 = 5201478.0;
  x3 = 5201479.0;

  y1 =  99999.0;
  y2 = 100000.0;
  y3 = 100001.0;

  rm_top = ( x1 * y1 + x2 * y2 + x3 * y3 ...
         - ( x1 + x2 + x3 ) * ( y1 + y2 + y3 ) / 3.0 );

  rm_bot = ( x1 ^ 2 + x2 ^ 2 + x3 ^ 2 - ( x1 + x2 + x3 ) ^ 2 / 3.0 );

  if ( rm_bot == 0.0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, '  Slope calculation fails.\n' );
    fprintf ( 1, '  The divisor was computed as 0.\n' );
  else

    rm = rm_top / rm_bot;

    rb = ( y1 + y2 + y3 ) / 3.0 - rm * ( x1 + x2 + x3 ) / 3.0;

    x = 5201480.0;
    rv = rm * x + rb;

    fprintf ( 1, '  %20.16g  %20.16g  %20.16g\n', rm, rb, rv );
 
  end

  return
end
