while loop question about the count

I am wonder how can I make e become a change number because when I running my code e is always equal 5 even I changed my enter number? Thanks.

1 件のコメント

Yixuan Zhang
Yixuan Zhang 2019 年 10 月 5 日
編集済み: the cyclist 2019 年 10 月 5 日
e is my count
e=0;
PerValue=11;
while PerValue>Pererror && e<5
V0=x;
Vn=V0-(polyval(Vector,V0)/polyval(A,V0));
e=e+1;
PerE=abs((Vn-V0)/V0)*100;
x=Vn;
end
finalroot=Vn;
fprintf('The volume at T=0 for the given equation is %0.5f [m^3]\n',V0)
fprintf('The solution coverged in %0.0f iterations\n',e)

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

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 10 月 5 日
編集済み: KALYAN ACHARJYA 2019 年 10 月 5 日

0 投票

I am wonder how can I make e become a change number because when I running my code e is always equal 5 even I changed my enter number? Thanks.
Because of While loop condition
PerValue>Pererror && e<5
%.....................^...
The while loop condition true, when PerValue>Pererror and e<5,
At 1st iter e=0+1
2nd iter e=2....
.....
when e=>5, the while loop becomes false, no stop the iteration at when e<5, irrespective of any changes within the loop

カテゴリ

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

タグ

質問済み:

2019 年 10 月 5 日

編集済み:

2019 年 10 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by