Symbolic environment and loops
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Bruno Souza
le 13 Avr 2021
Réponse apportée : Swetha Polemoni
le 16 Avr 2021
Hi all,
I am trying to use the symbolic environment to generate T symbolic objects in my function. Since T is an input, I would like to generate the symbolic objects in a loop.
I was thinking in something like this:
for j = 1:T
syms x'j' real
x'j' = expression
end
Where the 'j' part is there to denote each symbolic variable. For T = 3, I would have 3 symbolic objects: x1, x2, and x3
Do you know if that is possible in Matlab?
I was trying to use vectors, but the problem is that I don't know how to declare a different symbolic object for each period in my loop:
sym_vector = zeros(T1,1);
for j = 1:T
syms x real
sym_vector(j) = x
end
All the best,
B.
0 commentaires
Réponse acceptée
Swetha Polemoni
le 16 Avr 2021
Hi Bruno Souza
It is my understanding that you want to use loop variable j to create different symbolic variable names. Following code snippent might help to serve the purpose.
for j = 1:5 % line 1
symbolicvariable=strcat("x",int2str(j)); % line2
syms symbolicvariable real % line 3
end % line 4
line 2 gives variable names such as x1, x2.... xT which can be used as symbolic variable in every iteration.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox 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!