Matrices: adjoint and cofactors

+- HP Forums (http://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: Matrices: adjoint and cofactors (/thread-4119.html)



Matrices: adjoint and cofactors - salvomic - 06-09-2015 04:07 PM

hi,
a little program to get adjoint matrix and cofactor matrix of a given matrix

Salvo M.

Code:

minor();

EXPORT cofactors(m)
BEGIN
local tempmat, cofact, deter;
local r, c, j, k;
  r:=rowDim(m);
  c:=colDim(m);
  cofact:=  MAKEMAT(0,r,c);
  tempmat:= m;
  FOR j FROM 1 TO r DO
  FOR k FROM 1 to c DO
    cofact:= minor(m, j, k);
    deter:= ((-1)^(j+k)) * det(cofact);
    tempmat(j,k):= deter;
  END; // inner for
  END; //for
  RETURN tempmat;
END;

minor(mat, r,c)
BEGIN
  mat:= delrows(mat,r);
  mat:= delcols(mat,c);
  RETURN mat;
END;

EXPORT adj(m)
BEGIN
local ad;
  ad:= cofactors(m);
RETURN TRN(ad);
END;