Support for Multiplication and Transpose of Block Matrices of Symbolic Matrices?
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
FingersCrossed
le 20 Mar 2023
Commenté : ZHEN CHEN
le 8 Juil 2024
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].'
Y = [A B;C D]*[E F;G H]
The outputs I am expecting are:
X = [A.' C.';B.' D.']
Y = [A*E+B*G A*F+B*H;C*E+D*G C*F+D*H]
1 commentaire
ZHEN CHEN
le 8 Juil 2024
I have found a solution using "NCAlgebra" package of Mathematica:https://ncalgebra.github.io/#BasicMatrices.
Réponse acceptée
Walter Roberson
le 23 Mai 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
X = [A B; Z A']
diff(X, x)
Plus de réponses (1)
Suraj
le 23 Mai 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 commentaires
Walter Roberson
le 23 Mai 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
B
whos A B
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.'
B * magic(2)
ans.'
Voir également
Catégories
En savoir plus sur Mathematical Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!