Evaluating symbolic matrix equations
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a symbolic matrix of size 20x3, which I have created using the sym() function. I have another matrix B which is calculated using certain rows of A, or in general the matrix B is a function of A i.e.,
. Once I obtain all the numerical entries of A, how can I evaluate B after substituting A with the obtained numerical values?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/679708/image.png)
A = sym('a', [20, 3]); % Create a 20x3 symbolic matrix
% Create a matrix B whose values depend on some function of A's elements
B(1, :) = cross(A(1, :), A(3, :));
B(2, :) = A(5, :) .* A(10, :) .* A(20, :);
% Substitute A with numerical values
A = subs(A, A, rand(20, 3)); % Now, A is a 20x3 matrix with random entries
% How do I evaluate the matrix B?
subs(B) ?
subs(B, A) ? % Both commands aren't working
0 commentaires
Réponse acceptée
Nishanth Rao
le 10 Juil 2021
7 commentaires
Walter Roberson
le 23 Juil 2022
It is a syntax restriction. When you use the {} form of subs(), the second parameter must be a cell array in which each entry is a scalar symbolic variable, and the third parameter must be a cell array the same size as the second parameter
A = sym('a', [2, 2]);
B = sym('b', [2, 2]);
C=A*B;
Anum = rand(2,2);
Bnum = rand(2,2);
Ac = num2cell(A);
Bc = num2cell(B);
Anc = num2cell(Anum);
Bnc = num2cell(Bnum);
subs(C, [Ac, Bc], [Anc, Bnc])
note here that [Ac, Bc] is a cell array, and [Anc, Bnc] is a cell array the same size
Plus de réponses (1)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!