Symbolic matrix algebra calculation

2 次查看(过去 30 天)
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?

回答(1 个)

Roger Stafford
Roger Stafford 2014-9-26
编辑:Roger Stafford 2014-9-26
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 个评论
Roger Stafford
Roger Stafford 2014-9-26
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 2014-9-26
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by