How does fzero determine its tolerance?
61 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Alan Weiss
on 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
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!