Support for Multiplication and Transpose of Block Matrices of Symbolic Matrices?

17 visualizaciones (últimos 30 días)
Does MATLAB not support multiplying and transposing block symbolic matrices? For instance, the following multiplication and transpose are not evaluated on the individual matrices inside of the block matrices:
syms A B C D E F G H [2 2] matrix
X = [A B;C D].'
X = 
Y = [A B;C D]*[E F;G H]
Y = 
The outputs I am expecting are:
X = [A.' C.';B.' D.']
X = 
Y = [A*E+B*G A*F+B*H;C*E+D*G C*F+D*H]
Y = 

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Mayo de 2023
Does MATLAB not support multiplying and transposing block symbolic matrices?
No, it does not. Most operations are postponed on symmatrix. Some operations are performed immediately though
syms A(x) [2 2] matrix
syms B [2 2] matrix
syms Z [2 2] matrix
Z(:) = 0
Z = 
X = [A B; Z A']
X(x) = 
diff(X, x)
ans(x) = 
  1 comentario
FingersCrossed
FingersCrossed el 23 de Mayo de 2023
Thanks, hope to see this get added in the future. I've been unable to find a competitor's software capable of doing this either, though maybe I just don't know the right syntax.

Iniciar sesión para comentar.

Más respuestas (1)

Suraj
Suraj el 23 de Mayo de 2023
Greetings,
Based on your inquiry, I understand that you are trying to multiply and transpose block matrices of symbolic matrices.
MATLAB does support multiplying and transposing block symbolic matrices, but I think in your example, the reason why the expected outputs are not obtained is because there is a syntax error in the matrix declaration.
When you declare the matrices A, B, C, D, E, F, G, H, you need to use the sym function instead of syms. The syms function is used for declaring multiple symbolic variables, while sym is used for declaring a single symbolic variable or a matrix of symbolic variables.
Here is a workaround for that:
% Declare symbolic matrices
A = sym('A', [2 2]);
B = sym('B', [2 2]);
C = sym('C', [2 2]);
D = sym('D', [2 2]);
E = sym('E', [2 2]);
F = sym('F', [2 2]);
G = sym('G', [2 2]);
H = sym('H', [2 2]);
% Transpose of a block matrix
X = [A B; C D].';
% Product of two block matrices
Y = [A B; C D] * [E F; G H];
% Display results
disp('X =')
disp(X)
disp('Y =')
disp(Y)
This code should give you the desired results.
Regards,
Suraj
  2 comentarios
FingersCrossed
FingersCrossed el 23 de Mayo de 2023
Editada: Walter Roberson el 23 de Mayo de 2023
Thank you for your reply, though this is not what I am trying to do. I would like to operate on A, B, C, D as symbolic matrix variables as in my example and not on an element by element basis. Examples of these operations for non-block matrices are given at:
Walter Roberson
Walter Roberson el 23 de Mayo de 2023
The syms function is used for declaring multiple symbolic variables, while sym is used for declaring a single symbolic variable or a matrix of symbolic variables.
That is not correct.
The sym function is primarily intended as a function that returns a single symbolic expression without itself assigning to any variable . So sym('A', [2 2]) returns a symbolic array for whatever purpose you need; you can assign it to a variable if you want.
The syms function is primarily intended for command syntax that builds one or more symbolic expressions and assigns them to variables . So syms A [2 2] functionally does A = sym('A', [2 2]) . But syms can also create symbolic functions, such as syms f(x) and with the matrix keyword creates symmatrix
Note the difference:
syms A [2 2]
syms B [2 2] matrix
A
A = 
B
B = 
whos A B
Name Size Bytes Class Attributes A 2x2 8 sym B 2x2 8 symmatrix
Without the matrix keyword, the variable A becomes a matrix containing symbols A1_1, A1_2, A2_1, A2_2 whereas with the matrix keyword, B becomes a 2 x 2 symmatrix . A symmatrix is treated differently than a sym matrix:
A * magic(2)
ans = 
ans.'
ans = 
B * magic(2)
ans = 
ans.'
ans = 

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematical Functions en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by