Symbolic matrix algebra calculation

3 views (last 30 days)
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
[ 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
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.
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.


Community Treasure Hunt

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

Start Hunting!

Translated by