%  Adj = adj(A);
%  Function to compute the adjoint of a matrix A
%  Written by: Kjetil Havre
%
   function [Adj] = adj(A)
   
   if nargin < 1
      disp('Usage: Adj = adj(A)')
      return
   end
   
   [mt,rd,cd,n] = minfo(A);
      
   if mt ~= 'cons'
      disp('Implemented only for constant matrices.')
      return;
   end
   
   if rd ~= cd 
      disp('The adjoint is only defined for square matrices.')
   end
   
   for i = 1:rd
      rds = [1:(i-1) (i+1):rd];
      for j=1:cd
         cds = [1:(j-1) (j+1):cd];
         Adj(j,i) = (-1)^(i+j)*det(sel(A,rds,cds));
      end
   end   
end
