Filter löschen
Filter löschen

Problem in using the "While" loop function

1 Ansicht (letzte 30 Tage)
Amr Sadek
Amr Sadek am 18 Sep. 2014
Bearbeitet: Yona am 22 Sep. 2014
Hello, I have a function, say x=x(t) where x(t=0)=xo and x(t=1)=x(t=0)-fun(t), and x(t=2)=x(t=1)-fun(t), and so on. I want to make a loop function to calculate x(t) till x(t)=0. How can I do that?
Thank you.
  4 Kommentare
Rick Rosson
Rick Rosson am 22 Sep. 2014
  • Is the time domain continuous or discrete?
  • If discrete, what is the time increment?
Amr Sadek
Amr Sadek am 22 Sep. 2014
The time domain is discrete with increment 1.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Yona
Yona am 22 Sep. 2014
Bearbeitet: Yona am 22 Sep. 2014
you need to define all variables.
n(1)=n0;
while 1
if n(end) <=0
break;
end
n(end+1)=n(end)-S*exp(-E/(k*t));
end
matlab don't like that the length of n change, so you get a warning but it will run. after this, you will have in n all data from t=0 until t: n(t)<=0.

Weitere 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