function a = lehmer_matrix ( m, n )

%*****************************************************************************80
%
%% lehmer_matrix() returns the LEHMER matrix.
%
%  Discussion:
%
%    This matrix is also known as the "Westlake" matrix.
%
%  Formula:
%
%    A(I,J) = min ( I, J ) / max ( I, J )
%
%  Example:
%
%    N = 5
%
%    1/1  1/2  1/3  1/4  1/5
%    1/2  2/2  2/3  2/4  2/5
%    1/3  2/3  3/3  3/4  3/5
%    1/4  2/4  3/4  4/4  4/5
%    1/5  2/5  3/5  4/5  5/5
%
%  Properties:
%
%    A is symmetric: A' = A.
%
%    A is positive definite.
%
%    A is symmetric positive definite.
%
%    Because A is symmetric, it is normal.
%
%    Because A is normal, it is diagonalizable.
%
%    A is totally nonnegative.
%
%    The inverse of A is tridiagonal.
%
%    The condition number of A lies between N and 4*N*N.
%
%    The family of matrices is nested as a function of N.
%
%    A is not diagonally dominant.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 October 2007
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Morris Newman, John Todd,
%    The evaluation of matrix inversion programs,
%    Journal of the Society for Industrial and Applied Mathematics,
%    Volume 6, Number 4, 1958, pages 466-476.
%
%    Solutions to problem E710, proposed by DH Lehmer: The inverse of
%    a matrix.
%    American Mathematical Monthly,
%    Volume 53, Number 9, November 1946, pages 534-535.
%
%    John Todd,
%    Basic Numerical Mathematics, Volume 2: Numerical Algebra,
%    Academic Press, 1977, page 154.
%
%  Input:
%
%    integer M: the number of rows.
%
%    integer N: the number of columns.
%    If N is not supplied, N = M is assumed.
%
%  Output:
%
%    real A(M,N), the matrix.
%
  if ( nargin < 2 )
    n = m;
  end

  a = zeros ( m, n );

  for i = 1 : m
    for j = 1 : n
      a(i,j) = ( min ( i, j ) ) / ( max ( i, j ) );
    end
  end

  return
end
