Interpretation of a given while loop argument

hi all. can anybody tell me what the following while loop gets as an argument? here changeinvoltage_load and changeinvoltage_pv are the two vectors. and iter is the counter of the loop. initially it is zero.
iter=0;
while any(~(abs(changeinvoltage_load)<=0.00001)) && any(~(abs(changeinvoltage_pv)<=0.00001)) && iter > 1 && iter <100 ;
iter=iter+1;
do the following.......
end

 Réponse acceptée

That while will be asked to process the result of
any(~(abs(changeinvoltage_load)<=0.00001)) && any(~(abs(changeinvoltage_pv)<=0.00001)) && iter > 1 && iter <100
That is a series of conditions separated with && . In order to use && each of the conditions must evaluate to a scalar.
any(~(abs(changeinvoltage_load)<=0.00001))
will evaluate to a scalar provided that ~(abs(changeinvoltage_load)<=0.00001) evaluates to a scalar or to a vector. The code would have a problem if changeinvoltage_load were a 2D array. With a vector, each of the individual logical values (abs(changeinvoltage_load)<=0.00001) would be calculated, each of them would be logically negated because of the ~, and then any() would return true if at least one of those values were true. An equivalent expression would be
any( abs(changeinvoltage_load) > 0.00001 )
The second sub-expression any(~(abs(changeinvoltage_pv)<=0.00001)) follows the same logic.
The third subexpression iter > 1 is scalar true provided that iter is larger than 1. If iter is less than or equal to 1 at the start then the condition would be false and that would make the overall && false, leading to the while loop body never being executed. You initialize iter = 0, so the body of the while loop is never executed.
The fourth subexpression iter < 100 is scalar true provided that iter is less than 100. If iter is 0 or 1 at the beginning then the condition would not be reached because the previous condition would have been false.
There is probably no good reason for having the iter > 1 test in the while unless you want to be able to disable the while loop.

Plus de réponses (0)

Catégories

En savoir plus sur Historical Contests dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by