JuliaIntervals / IntervalRootFinding.jl

Library for finding the roots of a function using interval arithmetic
https://juliaintervals.github.io/IntervalRootFinding.jl/
Other
129 stars 26 forks source link

Do not impose `tol` to be `Float64` #133

Open lbenet opened 5 years ago

lbenet commented 5 years ago

The following throws a MethodError:

julia> using IntervalArithmetic, IntervalRootFinding

julia> f(x) = -4*x^3 + 5*x^4
f (generic function with 1 method)

julia> dom = big(0) .. big(1)
[0, 1]₂₅₆

julia> roots(f, dom, Newton, 1.0e-5)  # works ok
2-element Array{Root{Interval{BigFloat}},1}:
 Root([0.799999, 0.800001]₂₅₆, :unique)
 Root([0, 6.67704e-06]₂₅₆, :unknown)   

julia> roots(f, dom, Newton, parse(BigFloat, "1.0e-5"))
ERROR: MethodError: no method matching roots(::typeof(f), ::Interval{BigFloat}, ::Type{Newton}, ::BigFloat)
Closest candidates are:
  roots(::Any, ::Interval{T}, ::Union{Type{Krawczyk}, Type{Newton}}) where T at /Users/benet/.julia/dev/IntervalRootFinding/src/roots.jl:153
  roots(::Any, ::Interval{T}, ::Union{Type{Krawczyk}, Type{Newton}}, ::Float64) where T at /Users/benet/.julia/dev/IntervalRootFinding/src/roots.jl:153
  roots(::F<:Function, ::F<:Function, ::Any) where F<:Function at /Users/benet/.julia/dev/IntervalRootFinding/src/roots.jl:226
  ...
Stacktrace:
 [1] top-level scope at none:0

I think it makes sense to allow tol in the roots methods to be <:AbstractFloat?

dpsanders commented 5 years ago

Sure. I think it can be any real number in fact.