x1=0:5; %tank1 capicity
x2=0:10; %tank2 capicity
x3= 0:1000000; %tank3 capicity
y1=2 %L/min pipe 1
y2=1 %L/min pipe 2
y3=0.5 %L/min pipe 3
v1=0 ;
while (v1<5)
v1=x1+y1;
end
why my loop is not running well.I get v1 6 and 7 even when my condition v1 < 5

回答 (1 件)

Torsten
Torsten 2023 年 2 月 10 日
編集済み: Torsten 2023 年 2 月 10 日

0 投票

At first (by your setting) v1 = 0. Thus the while loop is entered.
After entering the while loop, v1 becomes x1 + y1 = [2 3 4 5 6 7], an array of numbers.
After this, MATLAB exits the while loop because not all elements of v1 are < 5 (that's what v1 < 5 for a vector means: all elements must be < 5)
Everything as expected.

カテゴリ

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

タグ

質問済み:

2023 年 2 月 10 日

編集済み:

2023 年 2 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by