フィルターのクリア

the value of y in the while loop doesn't vary from the previous ?

1 回表示 (過去 30 日間)
mohamed
mohamed 2013 年 2 月 26 日
>> n=2;
>>t=520
>> r=5;
>> p=1000;
>> x=n*r*t/p;
a=1; , b=2;
>> y=n*r*t/(p+a*n^2/x^2))+n*b;
while abs(x-y)<= 0.001
x=y;
y=n*r*t/((p+a*n^2/x^2))+n*b;
end

採用された回答

Walter Roberson
Walter Roberson 2013 年 2 月 26 日
I suspect you will find that your while loop body is not executing at all.
  7 件のコメント
bym
bym 2013 年 2 月 28 日
so the loop should continue while the difference is greater than .001?
Image Analyst
Image Analyst 2013 年 2 月 28 日
It's not even satisfied the very first time! Like Walter tried to tell you, the first time it hits that line, x = 5.2, and y = 9.1992, so abs(x-y) = 3.992 and since this is not less than 0.001, your loop never even gets entered the very first time. If you learn how to use the debugger, or simply leave off semicolons, you will discover these kinds of things very very easily and quickly.

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

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