variable inside for loop with if and t variable
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Geoff Hayes
el 29 de Mayo de 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.
Respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!