variable inside for loop with if and t variable

2 Ansichten (letzte 30 Tage)
installdisc
installdisc am 29 Mai 2016
Kommentiert: Geoff Hayes am 29 Mai 2016
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 Kommentar
Geoff Hayes
Geoff Hayes am 29 Mai 2016
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by