0

If I have the 2X2 matrix [(1,1/b),(b,-b)] and 2x1 matrix (a,a) is there a way to carry out algebraic matrix multiplication (for example 1/b * a being a/b, and so on for the rest of the matrix elements) using any packages, and what packages would be make this possible.

As the matrices contain strings the multiply operation doesn't work. I was considering the SymPy package but I am not sure whether this would work in this case and if not how would you solve this problem and carry out this multiplication.

Ad270
  • 13
  • 4
  • 2
    No, you cannot do this with numpy. Yes, you can do this with sympy. – erip Mar 06 '23 at 01:32
  • Does this answer your question? [Abstract matrix multiplication with variables](https://stackoverflow.com/questions/46849168/abstract-matrix-multiplication-with-variables) – Mislah Mar 06 '23 at 01:32

1 Answers1

1

You can pretty much paste your example into Sympy with almost no modification:

from sympy import Matrix, Symbol

a, b = Symbol('a'), Symbol('b')
m1 = Matrix([(1, 1/b), (b, -b)])
m2 = Matrix([(a,), (a,)])
m1 * m2

See the matricies docs for more.

Nick ODell
  • 15,465
  • 3
  • 32
  • 66