# Use Roots.Brent() in fzero Roots.jl

**URL:** <https://discourse.julialang.org/t/use-roots-brent-in-fzero-roots-jl/37126>\
**Category:** Optimization (Mathematical)\
**Tags:** question, roots\
**Created:** [April 6, 2020, 9:31pm UTC](https://discourse.julialang.org/t/use-roots-brent-in-fzero-roots-jl/37126 "2020-04-06T21:31:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [April 6, 2020, 9:31pm UTC](https://discourse.julialang.org/t/use-roots-brent-in-fzero-roots-jl/37126/1 "2020-04-06T21:31:28Z")

</div>

Hello,

I would like to use the method Brent-Dekker in Roots.jl without using the `find_zero` wrapper since I will only do one run of root-finding for the function of interest. `fzero` seems to be the way to go, but I don’t know how to provide the argument `Roots.Brent()`

```julia
fzero(z->u(z), zlim[1], zlim[2], Roots.Brent())

```

MethodError: no method matching fzero(::var"#60#62", ::Float64, ::Float64, ::Roots.Brent)  
Closest candidates are:  
fzero(::Any, ::Any, !Matched::Roots.AbstractUnivariateZeroMethod, ::Roots.AbstractBracketing; kwargs…) at /home/mat/.julia/packages/Roots/sNoys/src/fzero.jl:73  
fzero(::Any, ::Number, ::Number; kwargs…) at /home/mat/.julia/packages/Roots/sNoys/src/fzero.jl:85  
fzero(::Any, ::Number; kwargs…) at /home/mat/.julia/packages/Roots/sNoys/src/fzero.jl:63

A more mathematical question: which root-finding will you recommend for a monotone increasing function. I can only use bracketing methods since Newton’s method will have a non-convergent cycle.

---

<div class="post-metadata">

**Author:** ![Vasily\_Pisarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vasily_pisarev/32/7929_2.png) [@Vasily\_Pisarev](https://discourse.julialang.org/u/Vasily_Pisarev)\
**Post date:** [April 6, 2020, 11:06pm UTC](https://discourse.julialang.org/t/use-roots-brent-in-fzero-roots-jl/37126/2 "2020-04-06T23:06:22Z")

</div>

It looks like `x0` must be a tuple for a bracketing solver:

```julia
fzero(u, (zlim[1], zlim[2]), Roots.Brent())

```

As for which method to use, there’s no simple answer. Mathematically, it is best to have a higher \frac{\ln{(order)}}{\text{number of function evaluations per iteration}} ratio. In practice, that depends on the complexity of the function. Higher order methods may require more bookkeeping with a lot of conditionals, and the time per iteration may be mostly due to those conditionals, if the function is relatively cheap. In that case, you may actually save time by doing a few more evaluations of a theoretically “worse” method, but with a more straightforward bracket update logic.

So, try several methods and choose whichever is fastest for your problem.

---

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [April 6, 2020, 11:18pm UTC](https://discourse.julialang.org/t/use-roots-brent-in-fzero-roots-jl/37126/3 "2020-04-06T23:18:33Z")

</div>

Thank you for your answer, however this is not the syntax written in the documentation of Roots.jl (Section Usage Examples) [GitHub - JuliaMath/Roots.jl: Root finding functions for Julia](https://github.com/JuliaMath/Roots.jl)

```julia
f(x) = exp(x) - x^4
## bracketing
fzero(f, 8, 9) # 8.613169456441398
fzero(f, -10, 0) # -0.8155534188089606
fzeros(f, -10, 10)  

```

> [@Vasily\_Pisarev](#):
>
> fzero(u, (zlim[1], zlim[2]), Roots.Brent())

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [April 7, 2020, 12:00am UTC](https://discourse.julialang.org/t/use-roots-brent-in-fzero-roots-jl/37126/4 "2020-04-07T00:00:26Z")

</div>

Vasily is correct, you should specify the initial value with a tuple. The `fzero` interface is not passing through that method argument. I’ll make an issue for that so that your invocation works as expected.
