MATLAB: How to display symbol equations before actually calculating the result

matrixsymbolic equations

Hello,
so say I have two matrises A=[a b,c d] and B=[d c;b a] and I define X=A*inv(B) -> In command window I will see the final result.
Is there a way how I can see X=A*inv(B) as X=[a b,c d]*inv[d c,b a]? In other words X in actual matrix form before evaluation. Thanks in advance.

Best Answer

A_sym = sym('A', size(A));
B_sym = sym('B', size(B));
X_sym = A_sym * inv(B_sym);
X = subs(X_sym, {A_sym, B_sym}, {A, B});
However, it is going to go ahead and calculate the inv() symbolically and do the multiplication, so X_sym is going to be the formula for the result rather than something like
-1
[a b] * [d c]
[c d] [b a]
There is no way at the MATLAB level to "hold" a symbolic calculation; you would have to go to the MuPAD level for that (and when you do, the result cannot be displayed at the MATLAB level.)