Asked by Wit
on 5 Dec 2018

I wonder if there is any way to prevent MATLAB from expanding the matrix symbolic expression?

For example, let's A = 3x3 matrix and b = constant.

Desired output:

>> A = sym('A', [3,3]);

>> syms b;

>> A^-1 + b*eye(3)

ans =

A^-1 + b*eye(3)

But MATLAB expands the inverse expression of A and gives :

[ b + (A2_2*A3_3 - A2_3*A3_2)/(A1_1*A2_2*A3_3 - A1_1*A2_3*A3_2 - A1_2*A2_1*A3_3 + A1_2*A2_3*A3_1 + A1_3*A2_1*A3_2 - A1_3*A2_2*A3_1), -(A1_2*A3_3 - A1_3*A3_2)/(A1_1*A2_2*A3_3 - A1_1*A2_3*A3_2 - A1_2*A2_1*A3_3 + A1_2*A2_3*A3_1 + A1_3*A2_1*A3_2 - A1_3*A2_2*A3_1), (A1_2*A2_3 - A1_3*A2_2)/(A1_1*A2_2*A3_3 - A1_1*A2_3*A3_2 - A1_2*A2_1*A3_3 + A1_2*A2_3*A3_1 + A1_3*A2_1*A3_2 - A1_3*A2_2*A3_1)]

[ -(A2_1*A3_3 - A2_3*A3_1)/(A1_1*A2_2*A3_3 - A1_1*A2_3*A3_2 - A1_2*A2_1*A3_3 + A1_2*A2_3*A3_1 + A1_3*A2_1*A3_2 - A1_3*A2_2*A3_1), b + (A1_1*A3_3 - A1_3*A3_1)/(A1_1*A2_2*A3_3 - A1_1*A2_3*A3_2 - A1_2*A2_1*A3_3 + A1_2*A2_3*A3_1 + A1_3*A2_1*A3_2 - A1_3*A2_2*A3_1), -(A1_1*A2_3 - A1_3*A2_1)/(A1_1*A2_2*A3_3 - A1_1*A2_3*A3_2 - A1_2*A2_1*A3_3 + A1_2*A2_3*A3_1 + A1_3*A2_1*A3_2 - A1_3*A2_2*A3_1)]

[ (A2_1*A3_2 - A2_2*A3_1)/(A1_1*A2_2*A3_3 - A1_1*A2_3*A3_2 - A1_2*A2_1*A3_3 + A1_2*A2_3*A3_1 + A1_3*A2_1*A3_2 - A1_3*A2_2*A3_1), -(A1_1*A3_2 - A1_2*A3_1)/(A1_1*A2_2*A3_3 - A1_1*A2_3*A3_2 - A1_2*A2_1*A3_3 + A1_2*A2_3*A3_1 + A1_3*A2_1*A3_2 - A1_3*A2_2*A3_1), b + (A1_1*A2_2 - A1_2*A2_1)/(A1_1*A2_2*A3_3 - A1_1*A2_3*A3_2 - A1_2*A2_1*A3_3 + A1_2*A2_3*A3_1 + A1_3*A2_1*A3_2 - A1_3*A2_2*A3_1)]

Edited:

• The reason is I want to do some complicated matrix symbolic manipulation, and don't want to expand the internal elements of the matrices.

• Fixed the dimension.

Answer by Walter Roberson
on 5 Dec 2018

No. To do this you would need to code many new MuPAD level routines as it violates the design principles of the existing symbolic linear algebra routines .

It would probably be easier to drop in a bunch of MuPAD level hold() calls and some careful manipulation .

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## madhan ravi (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/433922-prevent-matlab-from-expanding-matrix-symbolic-expression#comment_646469

## Wit (view profile)

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/433922-prevent-matlab-from-expanding-matrix-symbolic-expression#comment_646473

Sign in to comment.