Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I'm not sure if I got your question correct, but if you want to find a common factor of the matrix elements, you can do so by computing gcd:

c = gcd(t1.list())

Then you can divide your matrix by this common factor and simplify the rest:

print( (t1 / c).apply_map(lambda z: z.full_simplify()) )

which gives

[-x + 2     -1     -1     -1]
[    -1 -x + 2     -1     -1]
[    -1     -1 -x + 2     -1]
[    -1     -1     -1 -x + 2]

Btw, if you know upfront that you'll deal with polynomial entries, it's better to define a polynomial ring in variable x, which eliminates the need in calling .full_simplify():

R.<x> = QQ[]
g=graphs.CompleteGraph(4)
h=g.am()
t=h-x*identity_matrix(4)
t1=t.adjugate()
c = gcd(t1.list())
print( t1 / c )