Symbolic matrix algebra calculation

1 view (last 30 days)
Wouter
Wouter on 26 Sep 2014
Commented: Roger Stafford on 26 Sep 2014
I want to do some algebra with matrices. However when I would create
A = sym('A',2)
B = sym('B',2)
and then
A*B
Then
[ A2_2/(A1_1*A2_2 - A1_2*A2_1), -A1_2/(A1_1*A2_2 - A1_2*A2_1)]
[ -A2_1/(A1_1*A2_2 - A1_2*A2_1), A1_1/(A1_1*A2_2 - A1_2*A2_1)]
Roles out. While I still want it to be A*B. Now I cannot use normal symbolic variables since they change the order of the multiplication, which is normally not allowed with matrices.
syms a b
(a + b)*b
becomes
b*(a + b)
Which is not correct for matrices. Is it possible to create symbolic variables which do not change the order?

Answers (1)

Roger Stafford
Roger Stafford on 26 Sep 2014
Edited: Roger Stafford on 26 Sep 2014
If you use the form a = sym('a',n) or a = sym('a',[m.n]) to declare symbolic vectors or matrices, I seriously doubt that the order of multiplication with other such symbolic vectors or matrices will ever be reversed, so that is presumably what you have to do to handle your algebra. Note that without such detailed descriptions as to size, matlab would not be able to recognize when a proposed multiplication was improper due to non-matching inner dimensions.
  3 Comments
Roger Stafford
Roger Stafford on 26 Sep 2014
I think you mean you don't want that output when you type inv(A)*A or A*inv(A). The output you mentioned can't happen unless you have defined B as B = inv(A). (Note that in this case it is legitimate to reverse the order of multiplication - A*B is indeed then equal to B*A.)
Roger Stafford
Roger Stafford on 26 Sep 2014
I don't know how you can avoid getting the expanded form displayed when you type A*B. However if you write
C = A*B;
with a semicolon you should not see an expansion displayed just as is the case with numerical variables.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!