Ask Your Question
0

Invertible matrix with integer coefficients

asked 2022-12-03 20:43:24 +0100

DreDd gravatar image

I try to build an invertable matrix, but using the .inverse() method returns matrix with rational coefs, so is there an opportunity in sage to return the inverse matrix with integer coefficients by taking out a common factor?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2022-12-04 00:21:49 +0100

Emmanuel Charpentier gravatar image

Do you mean something like what follows ?

sage: foo=MatrixSpace(ZZ,2).random_element()
sage: while foo.det()==0: foo=MatrixSpace(ZZ,2).random_element()
sage: foo
[-9 -1]
[ 2 -1]
sage: bar=foo.inverse() ; bar
[-1/11  1/11]
[-2/11 -9/11]
sage: gee=gcd(bar.list()) ; gee
1/11
sage: bar/gee
[-1  1]
[-2 -9]

HTH,

edit flag offensive delete link more
1

answered 2022-12-03 21:45:55 +0100

FrédéricC gravatar image

Maybe like that

M=matrix(ZZ,2,2,[1,-1,1,0])
M.inverse_of_unit()
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-12-03 20:43:24 +0100

Seen: 89 times

Last updated: Dec 04 '22