Symbolic matrix algebra calculation
1 次查看(过去 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?
0 个评论
回答(1 个)
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
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
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!