function compressed_solve_test ( )

%*****************************************************************************80
%
%% compressed_solve_test() tests compressed_solve().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 March 2026
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../compressed_solve' );

  timestamp ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'compressed_solve_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test compressed_solve(), which seeks a solution of an\n' );
  fprintf ( 1, '  underdetermined linear system A*x=b, with the maximum\n' );
  fprintf ( 1, '  number of zero entries in x.\n' );

  A = [ ...
    87, 190, 118, 140, 101; ...
    72, 170,  90, 135, 104; ...
    12,  31,  14,  25,  20 ];

  fprintf ( 1, '\n' );
  fprintf ( 1, '  matrix A:\n' );
  disp ( A );

  b = [ 5; 10; 8 ];
  fprintf ( 1, '\n' );
  fprintf ( 1, '  right hand side b:\n' );
  disp ( b );
%
%  Compute compressed solution.
%
  x1 = compressed_solve ( A, b );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  compressed solution x1:\n' );
  disp ( x1 );
%
%  Compute MATLAB solution by mldivide or backslash.
%
  x2 = A \ b;
  fprintf ( 1, '\n' );
  fprintf ( 1, '  backslash solution x2:\n' );
  disp ( x2 );
%
%  Least squares solution.
%
  [ Q, R ] = qr ( A );
  qtb = Q' * b;
  x3 = R \ qtb;
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Least squares solution x3:\n' );
  disp ( x3 );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'compressed_solve_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  timestamp ( );

  rmpath ( '../compressed_solve' );

  return
end
function timestamp ( )

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

  return
end
