In [9]:
import sympy
sympy.init_printing(use_latex='mathjax')

In [12]:
t0,t1,t2,t3,t4,t5 = sympy.symbols("t_0,t_1,t_2,t_3,t_4,t_5")
M = sympy.Matrix([[1, t0, t3], [0, t1, t4], [0, t2, t5]])
M


Out[12]:
$$\left[\begin{matrix}1 & t_{0} & t_{3}\\0 & t_{1} & t_{4}\\0 & t_{2} & t_{5}\end{matrix}\right]$$

In [16]:
MI = M.inv()
MI


Out[16]:
$$\left[\begin{matrix}1 & - \frac{t_{0}}{t_{1}} + \frac{t_{2} \left(- \frac{t_{0} t_{4}}{t_{1}} + t_{3}\right)}{t_{1} \left(t_{5} - \frac{t_{2} t_{4}}{t_{1}}\right)} & - \frac{- \frac{t_{0} t_{4}}{t_{1}} + t_{3}}{t_{5} - \frac{t_{2} t_{4}}{t_{1}}}\\0 & \frac{1}{t_{1}} + \frac{t_{2} t_{4}}{t_{1}^{2} \left(t_{5} - \frac{t_{2} t_{4}}{t_{1}}\right)} & - \frac{t_{4}}{t_{1} \left(t_{5} - \frac{t_{2} t_{4}}{t_{1}}\right)}\\0 & - \frac{t_{2}}{t_{1} \left(t_{5} - \frac{t_{2} t_{4}}{t_{1}}\right)} & \frac{1}{t_{5} - \frac{t_{2} t_{4}}{t_{1}}}\end{matrix}\right]$$

In [17]:
sympy.printing.print_tree(MI)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-17-c8f604793704> in <module>()
----> 1 sympy.printing.print_tree(MI)

/home/redhog/Projects/skytruth/pelagos/deps/local/lib/python2.7/site-packages/sympy/printing/tree.pyc in print_tree(node)
    115     See also: tree()
    116     """
--> 117     print(tree(node))

/home/redhog/Projects/skytruth/pelagos/deps/local/lib/python2.7/site-packages/sympy/printing/tree.pyc in tree(node)
     63     """
     64     subtrees = []
---> 65     for arg in node.args:
     66         subtrees.append(tree(arg))
     67     s = print_node(node) + pprint_nodes(subtrees)

/home/redhog/Projects/skytruth/pelagos/deps/local/lib/python2.7/site-packages/sympy/matrices/matrices.pyc in __getattr__(self, attr)
   3082         else:
   3083             raise AttributeError(
-> 3084                 "%s has no attribute %s." % (self.__class__.__name__, attr))
   3085 
   3086     def integrate(self, *args):

AttributeError: MutableDenseMatrix has no attribute args.

In [20]:
print repr(MI)


Matrix([
[1, -t_0/t_1 + t_2*(-t_0*t_4/t_1 + t_3)/(t_1*(t_5 - t_2*t_4/t_1)), -(-t_0*t_4/t_1 + t_3)/(t_5 - t_2*t_4/t_1)],
[0,                  1/t_1 + t_2*t_4/(t_1**2*(t_5 - t_2*t_4/t_1)),            -t_4/(t_1*(t_5 - t_2*t_4/t_1))],
[0,                                -t_2/(t_1*(t_5 - t_2*t_4/t_1)),                     1/(t_5 - t_2*t_4/t_1)]])

In [38]:
p,l,x, y = sympy.symbols("p,l,x,y")
e = sympy.Matrix([[1, x, y]]) * MI
print sympy.Eq(p, e.tolist()[0][1])


p == -t_0/t_1 + x*(1/t_1 + t_2*t_4/(t_1**2*(t_5 - t_2*t_4/t_1))) - t_2*y/(t_1*(t_5 - t_2*t_4/t_1)) + t_2*(-t_0*t_4/t_1 + t_3)/(t_1*(t_5 - t_2*t_4/t_1))

In [39]:
print sympy.Eq(l, e.tolist()[0][2])


l == y/(t_5 - t_2*t_4/t_1) - (-t_0*t_4/t_1 + t_3)/(t_5 - t_2*t_4/t_1) - t_4*x/(t_1*(t_5 - t_2*t_4/t_1))

In [ ]: