function a = llsq0 ( n, x, y )

%*****************************************************************************80
%
%% llsq0() solves a linear least squares problem matching y=a*x to data.
%
%  Discussion:
%
%    A formula for a line of the form Y = A * X is sought, which
%    will minimize the root-mean-square error to N data points ( X(I), Y(I) );
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    15 January 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of data values.
%
%    real X(N,1), Y(N,1), the coordinates of the data points.
%
%  Output:
%
%    real A, the slope of the least-squares approximant to the data.
%

%
%  Force data to be column vectors!
%
  x = x(:);
  y = y(:);
%
%  Special case.
%
  if ( n == 1 )
    if ( x(1) == 0.0 )
      a = 1.0;
    else
      a = y(1) / x(1);
    end
    return
  end

  a = ( x' * y ) / ( x' * x );

  return
end
