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

Réponses (1)

Torsten
Torsten le 10 Fév 2023
Modifié(e) : Torsten le 10 Fév 2023

0 votes

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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by