Problem in using the "While" loop function

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 件のコメント

A Jenkins
A Jenkins 2014 年 9 月 18 日
This sounds like a homework question. What have you tried so far?
Amr Sadek
Amr Sadek 2014 年 9 月 22 日
Unfortunately this is not a homework question. Here is the details: I want to calculate the function n(t) which is a function in time. At t=0, the initial condition, n(t=0)=no. As the time increases, this function decreases as: n(t)=n(t-1) - S exp(-E./(k.*t) wher E, S, and k are some constant parameters. I want to calculate this function,n(t), until reaching the minimum value which is ~0. I hope this is enough. Thank you for your help.
Rick Rosson
Rick Rosson 2014 年 9 月 22 日
  • Is the time domain continuous or discrete?
  • If discrete, what is the time increment?
Amr Sadek
Amr Sadek 2014 年 9 月 22 日
The time domain is discrete with increment 1.

サインインしてコメントする。

 採用された回答

Yona
Yona 2014 年 9 月 22 日
編集済み: Yona 2014 年 9 月 22 日

0 投票

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.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2014 年 9 月 18 日

編集済み:

2014 年 9 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by