function dqrsl_test ( )

%*****************************************************************************80
%
%% DQRSL_TEST tests DQRSL.
%
%  Discussion:
%
%    DQRSL can solve a linear system that was factored by DQRDC.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    28 August 2016
%
%  Author:
%
%    John Burkardt
%
  n = 5;
  p = 3;
  lda = n;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'DQRSL_TEST\n' );
  fprintf ( 1, '  DQRSL solves a rectangular linear system A*x=b in the\n' );
  fprintf ( 1, '  least squares sense after A has been factored by DQRDC.\n' );
%
%  Set the matrix A.
%
  a = [ ...
    1.0,  1.0,  1.0; ...
    1.0,  2.0,  4.0; ...
    1.0,  3.0,  9.0; ...
    1.0,  4.0, 16.0; ...
    1.0,  5.0, 25.0 ];

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

  for i = 1 : n
    for j = 1 : p
      fprintf ( 1, '  %14f', a(i,j) );
    end
    fprintf ( 1, '\n' );
  end
%
%  Decompose the matrix.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Decompose the matrix.\n' );

  job = 0;
  ipvt(1:p) = 0;

  [ a, qraux, ipvt ] = dqrdc ( a, lda, n, p, ipvt, job );
%
%  Call DQRSL to compute the least squares solution A*x=b.
%
  job = 110;

  y = [  ...
    1.0; ...
    2.3; ...
    4.6; ...
    3.1; ...
    1.2 ];     

  b2 = [ ...
    -3.02; ...
     4.4914286; ...
    -0.72857143 ];

  [ qy, qty, b, r, xb, info ] = dqrsl ( a, lda, n, p, qraux, y, job );

  if ( info ~= 0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'DQRSL_TEST - Warning!' );
    fprintf ( 1, '  DQRSL returns INFO = %d\n', info );
    return
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '      X          X(expected):\n' );
  fprintf ( 1, '\n' );

  for i = 1 : p
    fprintf ( 1, '  %14.6g  %14.6g\n', b(i), b2(i) );
  end

  return
end
