function inverse_test ( )

%*****************************************************************************80
%
%% inverse_test computes the inverse of a matrix.
%
%MATLAB version of FORTRAN program for calculating the inverse of a given
% matrix on page 167 of conte/deboor. This program uses FACTOR and SUBST
% It also makes use of the fact that the MATLAB version of SUBST can solve
% A*? = B for matrices B.
%
%  Reference:
%
%    Samuel Conte, Carl de Boor,
%    Elementary Numerical Analysis,
%    Third Edition,
%    SIAM, 2017,
%    ISBN: 978-1-611975-19-2.
%

  fprintf ( 1, '\n' );
  fprintf ( 1, 'inverse_test:\n' );
  fprintf ( 1, '  Demonstrate computation of inverse matrix\n' );
  fprintf ( 1, '  using factor_cd() and subst()\n' );

  A = [2 3 -1;4 4 -3;-2 3 -1];

  [W,IPIVOT,IFLAG] = factor_cd(A);
  if ~IFLAG, disp(' The matrix is singular'), return, end
  [N,~] = size(A);
  AINV = subst(W,IPIVOT,eye(N));

  disp('  the computed inverse is ')
  AINV

  return
end

