Post Reply 
Adjoint matrix (my function): ok with numbers but not symbolics
11-10-2017, 05:05 PM (This post was last modified: 11-10-2017 05:39 PM by salvomic.)
Post: #5
RE: Adjoint matrix (my function): ok with numbers but not symbolics
Here there is the code, if someone would like to collaborate to find the error in it, that prevent the use of a letters instead of numbers in the matrix:

Code:

minor();

EXPORT cofactors(m)
// Cofactors of the matrix 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)
// Returns the matrix without row r and col c
BEGIN
  mat:= delrows(mat,r);
  mat:= delcols(mat,c);
  RETURN mat;
END;

EXPORT adj(m)
// adjoint matrix (=transpose of cofactors(m))
BEGIN
local ad;
  ad:= cofactors(m);
RETURN TRN(ad);
END;

The problem is in input, I suppose:
type([1,2],[4,3]) -> DOM_LIST
TYPE([1,2],[4,3]) -> 4
(matrix)
but
type([1,sin(x)],[2,3]) -> DOM_LIST
TYPE([1,sin(x)],[2,3]) -> 6
(list)
...

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Adjoint matrix (my function): ok with numbers but not symbolics - salvomic - 11-10-2017 05:05 PM



User(s) browsing this thread: 1 Guest(s)