function test_plu ( )

%*****************************************************************************80
%
%% test_plu() tests the PLU factors.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    07 January 2020
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'test_plu():\n' );
  fprintf ( 1, '  A = a test matrix of order M by N\n' );
  fprintf ( 1, '  P, L, U are the PLU factors.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  |A| = Frobenius norm of A.\n' );
  fprintf ( 1, '  |A-PLU| = Frobenius norm of A-P*L*U.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Title                    M     N      ' );
  fprintf ( 1, '|A|            |A-PLU|\n' );
  fprintf ( 1, '\n' );
%
%  a123
%
  title = 'a123';
  m = 3;
  n = 3;
  a = a123_matrix ( );
  [ p, l, u ] = a123_plu ( );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  bodewig
%
  title = 'bodewig';
  m = 4;
  n = 4;
  a = bodewig_matrix ( );
  [ p, l, u ] = bodewig_plu ( );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  borderband
%
  title = 'borderband';
  m = 5;
  n = 5;
  a = borderband_matrix ( n );
  [ p, l, u ] = borderband_plu ( n );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  dif2
%
  title = 'dif2';
  m = 5;
  n = 5;
  a = dif2_matrix ( m, n );
  [ p, l, u ] = dif2_plu ( n );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  gfpp
%
  title = 'gfpp';
  m = 5;
  n = 5;
  r8_lo = -5.0;
  r8_hi = +5.0;
  key = 123456789;
  rng ( key );
  alpha = r8_lo + ( r8_hi - r8_lo ) * rand ( 1, 1 );
  a = gfpp_matrix ( n, alpha );
  [ p, l, u ] = gfpp_plu ( n, alpha );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  givens
%
  title = 'givens';
  m = 5;
  n = 5;
  a = givens_matrix ( m, n );
  [ p, l, u ] = givens_plu ( n );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  golub
%
  title = 'golub';
  m = 5;
  n = 5;
  key = 123456789;
  a = golub_matrix ( n, key );
  [ p, l, u ] = golub_plu ( n, key );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  kms
%
  title = 'kms';
  m = 5;
  n = 5;
  r8_lo = -5.0;
  r8_hi = +5.0;
  key = 123456789;
  rng ( key );
  alpha = r8_lo + ( r8_hi - r8_lo ) * rand ( 1, 1 );
  a = kms_matrix ( alpha, m, n );
  [ p, l, u ] = kms_plu ( alpha, n );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  lehmer
%
  title = 'lehmer';
  m = 5;
  n = 5;
  a = lehmer_matrix ( m, n );
  [ p, l, u ] = lehmer_plu ( n );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  maxij
%
  title = 'maxij';
  m = 5;
  n = 5;
  a = maxij_matrix ( m, n );
  [ p, l, u ] = maxij_plu ( n );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  minij
%
  title = 'minij';
  m = 5;
  n = 5;
  a = minij_matrix ( n, n );
  [ p, l, u ] = minij_plu ( n );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  moler1
%
  title = 'moler1';
  m = 5;
  n = 5;
  r8_lo = -5.0;
  r8_hi = +5.0;
  key = 123456789;
  rng ( key );
  alpha = r8_lo + ( r8_hi - r8_lo ) * rand ( 1, 1 );
  a = moler1_matrix ( alpha, n, n );
  [ p, l, u ] = moler1_plu ( alpha, n );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  moler3
%
  title = 'moler3';
  m = 5;
  n = 5;
  a = moler3_matrix ( m, n );
  [ p, l, u ] = moler3_plu ( n );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  oto
%
  title = 'oto';
  m = 5;
  n = 5;
  a = oto_matrix ( m, n );
  [ p, l, u ] = oto_plu ( n );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  pascal2
%
  title = 'pascal2';
  m = 5;
  n = 5;
  a = pascal2_matrix ( n );
  [ p, l, u ] = pascal2_plu ( n );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  plu
%
  title = 'plu';
  n = 5;
  key = 123456789;
  rng ( key );
  for i = 1 : n
    pivot(i) = randi ( [ i, n ], 1 );
  end
  a = plu_matrix ( n, pivot );
  [ p, l, u ] = plu_plu ( n, pivot );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  vand2
%
  title = 'vand2';
  m = 4;
  n = 4;
  r8_lo = -5.0;
  r8_hi = +5.0;
  key = 123456789;
  rng ( key );
  x = r8_lo + ( r8_hi - r8_lo ) * rand ( m, 1 );
  a = vand2_matrix ( m, x );
  [ p, l, u ] = vand2_plu ( m, x );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );
%
%  wilson
%
  title = 'wilson';
  m = 4;
  n = 4;
  a = wilson_matrix ( );
  [ p, l, u ] = wilson_plu ( );
  error_frobenius = r8mat_is_plu ( m, n, a, p, l, u );
  norm_a_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, m, n, norm_a_frobenius, error_frobenius );

  return
end
