MatLab While loop indexing?

5 ビュー (過去 30 日間)
YOUNGJUN Park
YOUNGJUN Park 2020 年 10 月 14 日
コメント済み: YOUNGJUN Park 2020 年 10 月 14 日
I am learning while loop in MATLAB.
I got an assignment where I have to figure out how many times loop was executed.
Is there any way to do this?
my code is following:
Balance=0;
while Balance < 1000000
Balance= 10000+Balance*(1+0.06)
end
This assignment require user to figure out how long will it take to reach 1million dolloar when its initial balance is 10000 and the annual compound interest was given as 6%.
I am not even sure if I created the right loop but trying to figure out how many times loop would execute if that loop is executed.
  1 件のコメント
James Tursa
James Tursa 2020 年 10 月 14 日
Is the interest compounded annually or monthly? Your code would indicate annually.

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

採用された回答

James Tursa
James Tursa 2020 年 10 月 14 日
Add a counter to your loop. Initialize the counter to 0 and add 1 to it within the loop. E.g.,
counter = 0;
% other stuff
while (whatever condition)
% other stuff
counter = counter + 1;
end
  1 件のコメント
YOUNGJUN Park
YOUNGJUN Park 2020 年 10 月 14 日
Thanks !

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

その他の回答 (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