Prevent MATLAB from expanding matrix symbolic expression

4 visualizaciones (últimos 30 días)
Wit
Wit el 5 de Dic. de 2018
Respondida: Walter Roberson el 5 de Dic. de 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.
  2 comentarios
madhan ravi
madhan ravi el 5 de Dic. de 2018
Editada: madhan ravi el 5 de Dic. de 2018
str2sym(' ') %?
Wit
Wit el 5 de Dic. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 5 de Dic. de 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 .

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by