Symbolic environment and loops

조회 수: 1 (최근 30일)
Bruno Souza
Bruno Souza 2021년 4월 13일
답변: Swetha Polemoni 2021년 4월 16일
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