terminating the while if loop
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
while abs(dE) > 1e-12
iteration=iteration+1;
E_old = E;
E = M+(ecc(1)*sin(E)); %eccentric anomaly
dE=E-E_old;
if iteration==1000
warndlg('iteration cannot be converged ', 'Error!', 'modal')
end
end
How can I modify above code to terminate the while loop when iteration exceeds 1000?
0 Commenti
Risposta accettata
Star Strider
il 14 Lug 2017
Modificato: Star Strider
il 14 Lug 2017
I would add a break or return in your if block:
if iteration>=1000
warndlg('iteration cannot be converged ', 'Error!', 'modal')
return
end
2 Commenti
Star Strider
il 14 Lug 2017
change the if condition to:
if (iteration>=1000) || (abs(dE) < 1e-12)
warndlg('iteration cannot be converged ', 'Error!', 'modal')
return
end
That should work as you want it to.
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!