Creating a symbolic array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Aleem Andrew
le 24 Nov 2020
Commenté : Aleem Andrew
le 25 Nov 2020
When I tried to create an array consisting of expressions in terms of a symbolic variable I get the error message
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.
But I don't want to evaluate the expressions at a particular value. Instead I want expressions in terms of the symbolic variable q. Does anyone have suggestions regarding how this can be done?
syms q
a = [];
for i = 1:5
for j = 1:5
a(i,j) =q;
end
end
0 commentaires
Réponse acceptée
Plus de réponses (2)
Stephan
le 24 Nov 2020
Modifié(e) : Stephan
le 24 Nov 2020
>> q = sym('q', [5, 5])
q =
[ q1_1, q1_2, q1_3, q1_4, q1_5]
[ q2_1, q2_2, q2_3, q2_4, q2_5]
[ q3_1, q3_2, q3_3, q3_4, q3_5]
[ q4_1, q4_2, q4_3, q4_4, q4_5]
[ q5_1, q5_2, q5_3, q5_4, q5_5]
>> whos q
Name Size Bytes Class Attributes
q 5x5 8 sym
>> q(1,1:end) = 42
q =
[ 42, 42, 42, 42, 42]
[ q2_1, q2_2, q2_3, q2_4, q2_5]
[ q3_1, q3_2, q3_3, 42, q3_5]
[ q4_1, q4_2, q4_3, q4_4, q4_5]
[ q5_1, q5_2, q5_3, q5_4, q5_5]
0 commentaires
Voir également
Catégories
En savoir plus sur Symbolic Variables, Expressions, Functions, and Preferences 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!