0

I'm wondering when my while loop expression is satisfied. Err is a [1x1551] complex double. Is my loop stopping when one value satisfies the expression (abs(real(err))>1e-4)? or when all values in the array satisfies the expression. The function is converting towards a constant with increasing p

dt=0.01;
t=0:dt:T;
err=1;
p=-1;
dphi_sum=0;

while abs(real(err))>1e-4
    p=p+1
    dphi_sum2 = function(p);
    err = (dphi_sum+dphi_sum2)./(dphi_sum)-1;
    dphi_sum = dphi_sum+dphi_sum2;   
end
Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
Malthe Eisum
  • 189
  • 11
  • 1
    It seems for `all` the values in `err` if `dphi_sum2` is not a scalar. Also, why do you have a function named `function` there? It's out of the context though, but seemed like a bad practice. – Divakar Mar 18 '14 at 12:10
  • 1
    Your loop will stop when any one of `abs(real(err)) <= 1e-4`. To continue looping, all the values must satisfy the condition. – R. Schifini Mar 18 '14 at 12:25
  • Hint: why not try this at the command line? e.g. set `err = 1:5` and then try a basic while loop which starts with `while err>3`. What happens? – nkjt Mar 18 '14 at 14:43

0 Answers0