function minfit_test ( )

%*****************************************************************************80
%
%% MINFIT_TEST tests MINFIT, which is a sort of SVD computation.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    30 July 2016
%
%  Author:
%
%    John Burkardt
%
  n = 5;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'MINFIT_TEST\n' );
  fprintf ( 1, '  MINFIT computes part of the SVD of a matrix A.\n' );
  fprintf ( 1, '    SVD: A = U * D * V''\n' );
  fprintf ( 1, '  MINFIT is given A, and returns the diagonal D\n' );
  fprintf ( 1, '  and the orthogonal matrix V.\n' );

  a = zeros ( n, n );

  for i = 1 : n
    a(i,i) = 2.0;
  end
  for i = 1 : n - 1
    a(i,i+1) = -1.0;
  end
  for i = 2 : n
    a(i,i-1) = -1.0;
  end

  r8mat_print ( n, n, a, '  The matrix A:' );

  tol = sqrt ( eps );

  [ a, d ] = minfit ( n, tol, a );

  r8mat_print ( n, n, a, '  The vector V:' );

  r8vec_print ( n, d, '  The singular values D:' );
%
%  Because A is positive definite symmetric, the "missing" matrix V = U.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Because A is positive definite symmetric,\n' );
  fprintf ( 1, '  we can reconstruct it as A = V * D * V''\n' );

  a2 = zeros ( n, n );

  for i = 1 : n
    for j = 1 : n
      for k = 1 : n
        a2(i,j) = a2(i,j) + a(i,k) * d(k) * a(j,k);
      end
    end
  end

  r8mat_print ( n, n, a2, '  The product A2 = V * D * V''' );

  return
end
