variable inside for loop with if and t variable

10 次查看(过去 30 天)
Hello, how can i use variable inside for loop?
t(1)=0;
dt=0.01;
tvege=1000;
y=zeros(tvege,1)
Xt=zeros(tvege,1)
for i=1:tvege
aVARIABLE(i+1) =23950.*(( Xt(i))>0.1) +(10+10*exp(-0.5*( *t(i)*))).*((Xt(i))<=0.1);
YVARIABLE(i+1)=5* *Xt(i)*;
y(i+1)=y(i)+dt*( ( aVARIABLE(i) * ( YVARIABLE(i) - y(i) ))
Xt(i+1)=Xt(i)+dt(y(i)-0.5)
end
so i get wrong results.....the code is working if i use constants for aVARIABLE and YVARIABLE but with my (i+1) thing and with t(i)....something goes wrong...so my euler with contants working but if i want to put dependent variables (.*WITH IF) in my for loop.....goes wrong.... how can i do that?
  1 个评论
Geoff Hayes
Geoff Hayes 2016-5-29
baki - you will need to clarify what you mean by something goes wrong. Also, please provide code that is bug-free. The line
aVARIABLE(i+1) =23950.*(( Xt(i))>0.1) +(10+10*exp(-0.5*( *t(i)*))).*((Xt(i))<=0.1);
has at least two errors in it.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by