function spd_test ( )

%*****************************************************************************80
%
%% spd_test() demonstrates tests for symmetric positive definiteness.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 September 2022
%
%  Author:
%
%    John Burkardt
%
  timestamp ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'spd_test():\n' );
  fprintf ( 1, '  Demonstrate some tests for determining if a matrix\n' );
  fprintf ( 1, '  is symmetric positive definite (SPD)\n' );

  for test = 1 : 6
%
%  Real matrix case.
%
    if ( test == 1 )
      n = 10;
      A = dif2_matrix ( n );
      fprintf ( 1, '\n' );
      fprintf ( 1, '  dif2 matrix of order n = %d\n', n );
    elseif ( test == 2 )
      n = 5;
      a = n - 1;
      b = - 1;
      A = combin_matrix ( a, b, n );
      fprintf ( 1, '\n' );
      fprintf ( 1, '  combinatorial matrix of order n = %d\n', n );
    elseif ( test == 3 )
      n = 5;
      A = cheby_t_matrix ( n );
      fprintf ( 1, '\n' );
      fprintf ( 1, '  Chebyshev T matrix of order n = %d\n', n );
    elseif ( test == 4 )
      n = 5;
      A = randn ( n, n );
      fprintf ( 1, '\n' );
      fprintf ( 1, '  Random matrix of order n = %d\n', n );
    elseif ( test == 5 )
      m = 5;
      n = 4;
      A = rand ( m, n );
      fprintf ( 1, '\n' );
      fprintf ( 1, '  Random matrix of shape %d x %d\n', m, n );
    elseif ( test == 6 )
      n = 5;
      A = complex ( rand ( n, n ), rand ( n, n ) );
      fprintf ( 1, '\n' );
      fprintf ( 1, '  Random complex matrix of order %d\n', n );
    end
%
%  Is the matrix real?
%
    if ( norm ( imag ( A ) ) ~= 0.0  )
      fprintf ( 1, '  Matrix is complex.  These tests are inadequate.\n' );
      continue;
    end
%
%  Is the matrix square?
%
    [ m, n ] = size ( A );
    if ( m ~= n )
      fprintf ( 1, '  Matrix is not symmetric!\n' );
      continue;
    end
%
%  Is the matrix symmetric?
%
    err = r8mat_is_symmetric ( A );
    fprintf ( 1, '  Deviation from symmetry = %g\n', err );
%
%  Real positive eigenvalues?
%
    err = r8mat_eigenvalues_positive ( A );
    if ( 0.0 < err )
      fprintf ( 1, '  All eigenvalues are real and positive.\n' );
      fprintf ( 1, '  Minimum eigenvalue is %g\n', err );
    elseif ( err == 0.0 )
      fprintf ( 1, '  At least one eigenvalue is 0.\n' );
    else
      fprintf ( 1, '  At least one eigenvalue is negative or complex\n' );
    end
%
%  x'Ax for 100 random real vectors.
%
    test = 100;
    satisfy = r8mat_xtax ( A, test );
    fprintf ( '  Out of %d real vectors x, x''Ax was positive %d times\n', test, satisfy );

  end
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'spd_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end
