How does fzero determine its tolerance?

50 visualizzazioni (ultimi 30 giorni)
Bramvg
Bramvg il 26 Mar 2015
Commentato: Bramvg il 27 Mar 2015
In the fzero function, according to the help, it is possible to specify a TolX parameter (higher TolX value means less function calls, which in my situation will greatly reduce computation time). I assume this tolerance is the maximum allowed difference between the calculated root and the real root, but as following example shows this apparently not true.
options = optimset('TolX',0.01);
x0 = fzero(@cos,[0.1 3],options); % exact solution of cos(x)=0 is 0.5*pi
errorx = x0 - 0.5*pi % answer is 0.0139 (which is bigger than the tolerance of 0.01)
Note that in this simplified example the error is only slightly bigger than the tolerance, but in my own code the error was more than 10x bigger than the tolerance.
So my question is, what does the TolX parameter do?
How can I specify a maximum error on the result of fzero?

Risposta accettata

Alan Weiss
Alan Weiss il 26 Mar 2015
The meaning of TolX is explained here. If you are curious about what fzero is really doing, and why it stops, read the code by executing
edit fzero
The relevant stopping condition in the code is, where m is the difference between the old point a and the new point b (think of b being the point x):
toler = 2.0*tol*max(abs(b),1.0);
if (abs(m) <= toler) || (fb == 0.0)
break
end
So it stops when the RELATIVE difference between points is less than TolX, where relative means relative to the point x. I mean,
m/b < 2*TolX
So if x (I mean b) is large then the absolute difference can be large, but the relative difference is small.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 Commento
Bramvg
Bramvg il 27 Mar 2015
Thanks, I was not aware of the fact that the tolerance is relative. This explains why in my own code the tolerance was about a factor 100 too big. Intuitively I expected that the stop condition would be this:
m < 2*Tolx
which is only the case for b<1. This behavior is not mentioned in the help of fzero.
What I also find weird is that the help file recommends a TolX value 'well above eps, and usually above 1e-14' while in fact the default is eps.

Accedi per commentare.

Più risposte (0)

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by