Hello, I'm just getting started with SymPy, so this mnay be something obvious or maybe I am doing it completely wrong. Any help is greatly appreciated.
I would like SymPy to compute for me some matrix algebra and return the expressions for the manipulations of the matrix elements. One way I found to do this is the following: A = Matrix(MatrixSymbol('a', 1, 3)) B = Matrix(MatrixSymbol('b', 3, 3)) z = A * B which returns the familiar looking matrix elements expression. However, if I try to compute the inverse of matrix B, I get an error: b.inv() AttributeError Traceback (most recent call last) <ipython-input-168-f0554a79bc7e> in <module>() ----> 1 b.inv() //anaconda/lib/python3.5/site-packages/sympy/matrices/matrices.py in inv(self, method, **kwargs) 307 if method is not None: 308 kwargs['method'] = method --> 309 return self._eval_inverse(**kwargs) 310 311 def inv_mod(self, m): //anaconda/lib/python3.5/site-packages/sympy/matrices/dense.py in _eval_inverse(self, **kwargs) 304 M = self.as_mutable() 305 if method == "GE": --> 306 rv = M.inverse_GE(iszerofunc=iszerofunc) 307 elif method == "LU": 308 rv = M.inverse_LU(iszerofunc=iszerofunc) //anaconda/lib/python3.5/site-packages/sympy/matrices/matrices.py in inverse_GE(self, iszerofunc) 2627 2628 big = Matrix.hstack(self.as_mutable(), Matrix.eye(self.rows)) -> 2629 red = big.rref(iszerofunc=iszerofunc, simplify=True)[0] 2630 if any(iszerofunc(red[j, j]) for j in range(red.rows)): 2631 raise ValueError("Matrix det == 0; not invertible.") //anaconda/lib/python3.5/site-packages/sympy/matrices/matrices.py in rref(self, iszerofunc, simplify) 2685 break 2686 if simplify: -> 2687 r[pivot, i] = simpfunc(r[pivot, i]) 2688 if iszerofunc(r[pivot, i]): 2689 for k in xrange(pivot, r.rows): //anaconda/lib/python3.5/site-packages/sympy/simplify/simplify.py in simplify(expr, ratio, measure, fu) 3706 _e = cancel(expr) 3707 expr1 = shorter(_e, _mexpand(_e).cancel()) # issue 6829 -> 3708 expr2 = shorter(together(expr, deep=True), together(expr1, deep=True)) 3709 3710 if ratio is S.Infinity: //anaconda/lib/python3.5/site-packages/sympy/simplify/simplify.py in shorter(*choices) 3700 if not has_variety(choices): 3701 return choices[0] -> 3702 return min(choices, key=measure) 3703 3704 expr = bottom_up(expr, lambda w: w.normal()) //anaconda/lib/python3.5/site-packages/sympy/core/function.py in count_ops(expr, visual) 2250 while args: 2251 a = args.pop() -> 2252 if a.is_Rational: 2253 #-1/3 = NEG + DIV 2254 if a is not S.One: AttributeError: 'str' object has no attribute 'is_Rational' which I don't get if I construct a Matrix object manually: b = symbols('b_:3\,:3'); B = Matrix([[b[0], b[1], b[2]], [b[3], b[4], b[5]], [b[6], b[7], b[8]]]) simplify(B.inv()) but this gets very boring very quickly for large matrices. Is this a bug or am I doing it the wrong way? Thanks! Cheers, Daniele -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/c0ca19a8-4269-bac2-74dc-99283d3f5305%40grinta.net. For more options, visit https://groups.google.com/d/optout.