inverse of a matrix with Fraction entries

Robert Kern robert.kern at gmail.com
Wed Nov 24 12:58:07 EST 2010


On 11/24/10 9:10 AM, Daniel Fetchinson wrote:

> It's a mathematical problem so no uncertainty is present in the
> initial values. And even if there was, if there are many orders of
> magnitude differences between the entries in the matrix floating point
> does not suffice for various things like eigenvalue calculation and
> stuff like that.

Well, if you want to do eigenvalue calculations, you are going to have to start 
doing numerical approximations anyways. There is no analytical solution for 
matrices larger than 4x4.

Sympy will do inverses of matrices over rationals for you, though:

|4> from sympy import *

|6> m = Matrix([[S(1)/2, S(1)/3], [S(1)/4, S(1)/5]])

|7> m
[1/2, 1/3]
[1/4, 1/5]

|8> m.inv()
[ 12, -20]
[-15,  30]

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list