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
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 Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!