In sympy, given a matrix equation
M * x + N * y = 0 (or more complicated..)
how to solve this for x? (M,N = matrices, x,y = vectors)
I tried this with normal symbols, but obviously this failed. Using MatrixSymbol was not working as well. Is there some way to do it, or is sympy not capable of doing it?
To solve a linear matrix equation, use the numpy. linalg. solve() method in Python. The method computes the “exact” solution, x, of the well-determined, i.e., full rank, linear matrix equation ax = b.
To actually compute the transpose, use the transpose() function, or the . T attribute of matrices. Represents the trace of a matrix expression. Represents a matrix using a function ( Lambda ) which gives outputs according to the coordinates of each matrix entries.
As MRocklin noted, MatrixExpressions don't support this yet, but noncommutative symbols do:
In [13]: M, N, x, y = symbols('M N x y', commutative=False)
In [15]: solve(M*x + N*y, x)
Out[15]:
⎡ -1⎤
⎣-N⋅y⋅M ⎦
Unlike MatrixExpressions, noncommutative symbols don't have a notion of shape, so you'll need to keep track of that yourself. But this also shows that the basic things to implement this for MatrixExpression are already there. It will probably be easy to implement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With