How to facilitate the input of syms (automatization)

조회 수: 1 (최근 30일)
Delia Bosshart
Delia Bosshart 2021년 6월 20일
댓글: Delia Bosshart 2021년 6월 20일
Hi there. I would liket to automatize the syms input in my code such that I wouldn't have to list each sym from x1 to x21. The thing is that I also have iterations with x1 to x100 which almost makes it unbearable having to list all these syms.
The number of syms is always connected to t_end such that x1 x2 x3 .... xt_end. In this case t_end is equal to 21. Is there a way to connect these two?
syms x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21
x = [x2;x3;x4;x5;x6;x7;x8;x9;x10;x11;x12;x13;x14;x15;x16;x17;x18;x19;x20;x21];
T1 = [];
T2 = [];
t_end = length(t) -1;
for k=2:t_end
a = trapz(t(k:k+1),q_ext(k:k+1))/(t(k+1)-t(k));
b = trapz(t(k:k+1),q_losses(k:k+1))/(t(k+1)-t(k));
c = trapz(t(k:k+1),beta_ch(k:k+1))/(t(k+1)-t(k));
d = h_ch + (x(k-1)-c).*(t(k+1)-t(k));
e = 232.87.*d.^(-0.46);
gamma_mean = (gamma(k)+gamma(k+1))/2;
eqn = (a + b + gamma_mean*6.96.*x(k-1) + (6-(31*e)/1000).*x(k-1)/60*1000 + 31.*e/1000.*c/60*1000)*0.0077 - 0.0424 - x(k-1) == 0;
vpasolve(eqn, x(k-1));
beta = double(vpasolve(eqn, x(k-1)));

채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 20일
syms x [1,t_end]
x = x(2:end) ; %remove x1

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by