fzero - how to set maximum number of iterations

7 Ansichten (letzte 30 Tage)
Alessandro D
Alessandro D am 9 Jul. 2018
Kommentiert: Alessandro D am 9 Jul. 2018
Dear users, I am using fzero to find the root of a nonlinear function. I call the routine as
x = fzero(fun,x0,options)
and I set options as
options = optimset('TolX',1e-6);
However I would like to set the maximum number of iterations as well, but it seems it's not possible, at least according to the documentation. If someone has a suggestion, please let me know! Thanks

Akzeptierte Antwort

dpb
dpb am 9 Jul. 2018
"Yes, we have no bananas today!"
fzero doesn't use the iteration count variables in the options object, true.
If it were important-enough to you, you could write an output function and have it count the times it was called and return the stop flag variable as true when a desired number of iterations reached. The internal counter would have to be made persistent, of course, to retain the count between calls.
I've never tried such a thing but seems at least theoretically possible altho begs the question of "why?" would you need it...
  1 Kommentar
Alessandro D
Alessandro D am 9 Jul. 2018
In general it is always a good idea to have a stopping rule also on the number of iterations, otherwise the algorithm could go on forever :)
In my specific problem, convergence is not guaranteed so I wanna stop the algorithm after a given number of iterations. I will implement your suggestion then. Even though I am considering writing my own bisection routine (it could be simpler). In the end fzero is just a fancier bisection based on Brent method

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by