Support for Multiplication and Transpose of Block Matrices of Symbolic Matrices?
17 次查看(过去 30 天)
显示 更早的评论
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 个评论
ZHEN CHEN
2024-7-8
I have found a solution using "NCAlgebra" package of Mathematica:https://ncalgebra.github.io/#BasicMatrices.
采纳的回答
Walter Roberson
2023-5-23
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)
更多回答(1 个)
Suraj
2023-5-23
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 个评论
Walter Roberson
2023-5-23
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.'
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mathematical Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!