function subst_test ( )

%*****************************************************************************80
%
%MATLAB program for testing FACTOR_CD and SUBST on pages 165-6 of conte/deboor
%
%  Reference:
%
%    Samuel Conte, Carl de Boor,
%    Elementary Numerical Analysis,
%    Third Edition,
%    SIAM, 2017,
%    ISBN: 978-1-611975-19-2.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'subst_test:\n' );
  fprintf ( 1, '  Test subst()\n' );

  X = rand(3,1);

  for j=1:5

    switch j
    case 1
      A = triu(ones(3)); 
    case 2
      A = tril(ones(3)); A(1,1)=.5;
    case 3
      A= eye(3); A(3,2)=1; A(2,1)=1;
    case 4
      A = rand(3);
    case 5
      A = triu(eye(3)); A = A(:,[3,1,2]);
    end

    [W,IPIVOT,IFLAG] = factor_cd(A)
    XA = subst(W,IPIVOT, A*X); 
    XA-X
  end

  return
end

