Prevent MATLAB from expanding matrix symbolic expression

5 views (last 30 days)
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.
  2 Comments
Wit
Wit on 5 Dec 2018
This doesn't work because it doesn't check the dimension of the matrix. For example:
>> x = sym('x', [2,1])
Obviously, A = 3x3 matrix cannot be multiplied with x. Using
>> str2sym('A*x')
ans =
A*x
doesn't check the dimension requirements.

Sign in to comment.

Answers (1)

Walter Roberson
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 .

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!