Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xtol not honored in fzero #67

Open
mzaffalon opened this issue Apr 12, 2017 · 5 comments
Open

xtol not honored in fzero #67

mzaffalon opened this issue Apr 12, 2017 · 5 comments

Comments

@mzaffalon
Copy link

mzaffalon commented Apr 12, 2017

I cannot seem to be able to set some of fzero's keyword parameters, e.g. xtol and maxeval

julia> f(x) = cos(x) - x
julia> fzero(f, 0; maxeval=20, verbose=true)
Results of univariate zero finding:
<snip>
* iterations: 63
* function evaluations: 65
* stopped as x_n ≈ x_{n-1} using atol=xabstol, rtol=xreltol

julia> fzero(f, 0; xtol=0.2, verbose=true)
Results of univariate zero finding:
* Converged to: 0.7390851332151607
* iterations: 63
* function evaluations: 65

In both cases, there are 65 function evaluations and the root is found to full precision.

The same seems to hold for find_zero.

BTW, what functions are called? There is no line information with @which:

julia> @which find_zero(f, 0; xabstol=0.2, verbose=true)
(::Roots.#kw##find_zero){T<:Number}(::Array{Any,1}, ::Roots.#find_zero, f, x0::T)
@jverzani
Copy link
Member

The furrow function with the default order switches to bisection if possible
For Float64, the bisection algorithm ignores xtol. (Though not for big float ).
Specifying an order is usually faster, but less robust to initial point.

@mzaffalon
Copy link
Author

Is there a specific reason why xtol is ignored for Float64? I am computing the function by integration and I don't need the full numerical precision.

@jverzani
Copy link
Member

Well, because xtol is usually used as a necessary stopping rule, but in this case of Float64 we can stop when we run out of bits to subdivide. The only method that doesn't respect xtol is bisection over Float64 all others do. However, the default to fzero will use bisection for accuracy when a bracketing interval is stumbled upon so you end up in many cases not having xtol respected. You can specify other algorithms to fzero through its order argument, or you could call the unexported a42 method: Roots.a42(sin, 3.0, 4.0, xtol=1e-3), say.

@mzaffalon
Copy link
Author

If there is no fundamental reason why bisection on Float64 should not respect xtol and if you have no objections, I would like to take a shot at adding it.

In my application, the evaluation of the function is painfully long and I am fine with 3 digits of accuracy. Having to simply specify the pass the tolerance to fzero would be very convenient.

@jverzani
Copy link
Member

jverzani commented Apr 27, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants