Symbolic environment and loops
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Bruno Souza
el 13 de Abr. de 2021
Respondida: Swetha Polemoni
el 16 de Abr. de 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 comentarios
Respuesta aceptada
Swetha Polemoni
el 16 de Abr. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Conversion Between Symbolic and Numeric en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!