function test_eigen_right ( )

%*****************************************************************************80
%
%% test_eigen_right() tests right eigensystems.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 May 2021
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'test_eigen_right():\n' );
  fprintf ( 1, '  Compute the Frobenius norm of the right eigensystem error:\n' );
  fprintf ( 1, '    A * X - X * LAMBDA\n' );
  fprintf ( 1, '  given K right eigenvectors X and eigenvalues LAMBDA.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Title                    N     K      ||A||          ' );
  fprintf ( 1, '||A*X-X*Lambda||\n' );
  fprintf ( 1, '\n' );
%
%  a123
%
  title = 'a123';
  n = 3;
  a = a123_matrix ( );
  lambda = a123_eigenvalues ( );
  x = a123_eigen_right ( );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  bab
%
  title = 'bab';
  n = 5;
  r8_lo = -5.0;
  r8_hi = +5.0;
  key = 123456789;
  rng ( key );
  alpha = r8_lo + ( r8_hi - r8_lo ) * rand ( 1, 1 );
  beta = r8_lo + ( r8_hi - r8_lo ) * rand ( 1, 1 );
  a = bab_matrix ( n, alpha, beta );
  lambda = bab_eigenvalues ( n, alpha, beta );
  x = bab_eigen_right ( n, alpha, beta );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  bodewig
%
  title = 'bodewig';
  n = 4;
  a = bodewig_matrix ( );
  lambda = bodewig_eigenvalues ( );
  x = bodewig_eigen_right ( );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  carry
%
  title = 'carry';
  n = 5;
  i4_lo = 2;
  i4_hi = 20;
  key = 123456789;
  rng ( key );
  i1 = randi ( [ i4_lo, i4_hi ], 1 );
  a = carry_matrix ( n, i1 );
  lambda = carry_eigenvalues ( n, i1 );
  x = carry_eigen_right ( n, i1 );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  chow
%
  title = 'chow';
  n = 5;
  r8_lo = -5.0;
  r8_hi = +5.0;
  key = 123456789;
  rng ( key );
  alpha = r8_lo + ( r8_hi - r8_lo ) * rand ( 1, 1 );
  beta = r8_lo + ( r8_hi - r8_lo ) * rand ( 1, 1 );
  a = chow_matrix ( alpha, beta, n, n );
  lambda = chow_eigenvalues ( alpha, beta, n );
  x = chow_eigen_right ( alpha, beta, n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  combin
%
  title = 'combin';
  n = 5;
  r8_lo = -5.0;
  r8_hi = +5.0;
  key = 123456789;
  rng ( key );
  alpha = r8_lo + ( r8_hi - r8_lo ) * rand ( 1, 1 );
  beta = r8_lo + ( r8_hi - r8_lo ) * rand ( 1, 1 );
  a = combin_matrix ( alpha, beta, n );
  lambda = combin_eigenvalues ( alpha, beta, n );
  x = combin_eigen_right ( alpha, beta, n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  defective
%
  title = 'defective';
  n = 2;
  a = defective_matrix ( );
  lambda = defective_eigenvalues ( );
  x = defective_eigen_right ( );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  dif2
%
  title = 'dif2';
  n = 5;
  a = dif2_matrix ( n, n );
  lambda = dif2_eigenvalues ( n );
  x = dif2_eigen_right ( n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  drmac_good
%
  title = 'drmac_good';
  n = 3;
  a = drmac_good_matrix ( );
  lambda = drmac_good_eigenvalues ( );
  x = drmac_good_eigen_right ( );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  exchange
%
  title = 'exchange';
  n = 5;
  a = exchange_matrix ( n, n );
  lambda = exchange_eigenvalues ( n );
  x = exchange_eigen_right ( n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  fibonacci2
%
  title = 'fibonacci2';
  n = 5;
  a = fibonacci2_matrix ( n );
  lambda = fibonacci2_eigenvalues ( n );
  x = fibonacci2_eigen_right ( n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  idempotent_random
%
  title = 'idempotent_random';
  n = 5;
  rank = 3;
  key = 123456789;
  a = idempotent_random_matrix ( n, rank, key );
  lambda = idempotent_random_eigenvalues ( n, rank, key );
  x = idempotent_random_eigen_right ( n, rank, key );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  identity
%
  title = 'identity';
  n = 5;
  a = identity_matrix ( n, n );
  lambda = identity_eigenvalues ( n );
  x = identity_eigen_right ( n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  ill3
%
  title = 'ill3';
  n = 3;
  a = ill3_matrix ( );
  lambda = ill3_eigenvalues ( );
  x = ill3_eigen_right ( );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  kershaw
%
  title = 'kershaw';
  n = 4;
  a = kershaw_matrix ( );
  lambda = kershaw_eigenvalues ( );
  x = kershaw_eigen_right ( );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  kms
%
  title = 'kms';
  n = 5;
  r8_lo = +0.0;
  r8_hi = +1.0;
  key = 123456789;
  rng ( key );
  alpha = r8_lo + ( r8_hi - r8_lo ) * rand ( 1, 1 );
  a = kms_matrix ( alpha, n, n );
  lambda = kms_eigenvalues ( alpha, n );
  x = kms_eigen_right ( alpha, n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  line_adj
%
  title = 'line_adj';
  n = 5;
  a = line_adj_matrix ( n );
  lambda = line_adj_eigenvalues ( n );
  x = line_adj_eigen_right ( n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  line_loop_adj
%
  title = 'line_loop_adj';
  n = 5;
  a = line_loop_adj_matrix ( n );
  lambda = line_loop_adj_eigenvalues ( n );
  x = line_loop_adj_eigen_right ( n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  magic
%
  title = 'magic';
  n = 5;
  a = magic_matrix ( n );
  lambda = magic_eigenvalues ( n );
  x = magic_eigen_right ( n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  one
%
  title = 'one';
  n = 5;
  a = one_matrix ( n, n );
  lambda = one_eigenvalues ( n );
  x = one_eigen_right ( n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  ortega
%
  title = 'ortega';
  n = 5;
  r8_lo = -5.0;
  r8_hi = +5.0;
  key = 123456789;
  rng ( key );
  v1 = r8_lo + ( r8_hi - r8_lo ) * rand ( n, 1 );
  v2 = r8_lo + ( r8_hi - r8_lo ) * rand ( n, 1 );
  v3 = r8_lo + ( r8_hi - r8_lo ) * rand ( n, 1 );
  a = ortega_matrix ( n, v1, v2, v3 );
  lambda = ortega_eigenvalues ( n, v1, v2, v3 );
  x = ortega_eigen_right ( n, v1, v2, v3 );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  oto
%
  title = 'oto';
  n = 5;
  a = oto_matrix ( n, n );
  lambda = oto_eigenvalues ( n );
  x = oto_eigen_right ( n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );;
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  pei
%
  title = 'pei';
  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 = pei_matrix ( alpha, n );
  lambda = pei_eigenvalues ( alpha, n );
  x = pei_eigen_right ( alpha, n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  reflection_random
%
  title = 'reflection_random';
  n = 5;
  key = 123456789;
  [ a, v ] = reflection_random_matrix ( n, key );
  lambda = reflection_random_eigenvalues ( n, key );
  x = reflection_random_eigen_right ( n, key );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, n, norm_frobenius, error_frobenius );
%
%  rodman
%
  title = 'rodman';
  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 = rodman_matrix ( n, n, alpha );
  lambda = rodman_eigenvalues ( n, alpha );
  x = rodman_eigen_right ( n, alpha );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  rosser1
%
  title = 'rosser1';
  n = 8;
  a = rosser1_matrix ( );
  lambda = rosser1_eigenvalues ( );
  x = rosser1_eigen_right ( );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  rutis1
%
  title = 'rutis1';
  n = 4;
  a = rutis1_matrix ( );
  lambda = rutis1_eigenvalues ( );
  x = rutis1_eigen_right ( );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  rutis2
%
  title = 'rutis2';
  n = 4;
  a = rutis2_matrix ( );
  lambda = rutis2_eigenvalues ( );
  x = rutis2_eigen_right ( );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  rutis3
%
  if ( true )
    title = 'rutis3';
    n = 4;
    a = rutis3_matrix ( );
    lambda = rutis3_eigenvalues ( );
    x = rutis3_eigen_right ( );
    [ ~, k ] = size ( x );
    error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
    norm_frobenius = norm ( a, 'fro' );
    fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
  end
%
%  rutis4
%
  title = 'rutis4';
  n = 5;
  a = rutis4_matrix ( n );
  lambda = rutis4_eigenvalues ( n );
  x = rutis4_eigen_right ( n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  rutis5
%
  title = 'rutis5';
  n = 4;
  a = rutis5_matrix ( );
  lambda = rutis5_eigenvalues ( );
  x = rutis5_eigen_right ( );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  spd_random
%
  title = 'spd_random';
  n = 5;
  key = 123456789;
  a = spd_random_matrix ( n, key );
  lambda = spd_random_eigenvalues ( n, key );
  x = spd_random_eigen_right ( n, key );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );;
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  sylvester_kac
%
  title = 'sylvester_kac';
  n = 5;
  a = sylvester_kac_matrix ( n );
  lambda = sylvester_kac_eigenvalues ( n );
  x = sylvester_kac_eigen_right ( n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  symmetric_random
%
  title = 'symmetric_random';
  n = 5;
  r8_lo = -5.0;
  r8_hi = +5.0;
  key = 123456789;
  rng ( key );
  d = r8_lo + ( r8_hi - r8_lo ) * rand ( n, 1 );
  a = symmetric_random_matrix ( n, d, key );
  lambda = symmetric_random_eigenvalues ( n, d, key );
  x = symmetric_random_eigen_right ( n, d, key );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  tribonacci2
%
  title = 'tribonacci2';
  n = 5;
  a = tribonacci2_matrix ( n );
  lambda = tribonacci2_eigenvalues ( n );
  x = tribonacci2_eigen_right ( n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  wilson
%
  title = 'wilson';
  n = 4;
  a = wilson_matrix ( );
  lambda = wilson_eigenvalues ( );
  x = wilson_eigen_right ( );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );
%
%  zero
%
  title = 'zero';
  n = 5;
  a = zero_matrix ( n, n );
  lambda = zero_eigenvalues ( n );
  x = zero_eigen_right ( n );
  [ ~, k ] = size ( x );
  error_frobenius = r8mat_is_eigen_right ( n, k, a, x, lambda );
  norm_frobenius = norm ( a, 'fro' );
  fprintf ( 1, '  %-20s  %4d  %4d  %14g  %14g\n', ...
    title, n, k, norm_frobenius, error_frobenius );

  return
end
