How to exit a for loop if the conditions within it are already met?
Mostrar comentarios más antiguos
I am using an iterative Newton- Raphson method to calculate the square root of an input number from an initial guess of the square root. The exit condition of the loop is that the absolute relative percentage error condition (=(abs((x-xprevious)/x))*100) is met however if the input guess is already close enough to the square root of the input number how can I stop the loop running an iteration of the for loop?
Respuestas (1)
James Tursa
el 29 de Nov. de 2015
0 votos
Sounds like you have two conditions, your relative error calculation and your guess being close enough. If you want to forgo the iteration as you suggest, then you will need to code up the guess part as well. E.g., maybe wrap your iteration code in an if-test for the guess calculation, or maybe make the guess calculation part of the loop test. If you post your code we could suggest ways to do it.
1 comentario
anonymous
el 3 de Dic. de 2015
Categorías
Más información sobre Newton-Raphson Method en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!