variable inside for loop with if and t variable

10 ビュー (過去 30 日間)
installdisc
installdisc 2016 年 5 月 29 日
コメント済み: Geoff Hayes 2016 年 5 月 29 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by