Symbolic environment and loops

1 次查看(过去 30 天)
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.

采纳的回答

Swetha Polemoni
Swetha Polemoni 2021-4-16
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 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by