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

Root finding fails for functions with complex numbers #147

Open dpsanders opened 4 years ago

dpsanders commented 4 years ago
julia> g(x) = x^3 + x^2 + 3x + im

julia> roots(g, Complex(-5..5, -5..5))
promotion of types IntervalRootFinding.Compl{Interval{Float64}} and Complex{Int64} failed to change any arguments
dpsanders commented 4 years ago
julia> IntervalRootFinding.roots(z->z^3 + z^2 + 3z + 1, Complex(-5..5, -5..5))
TypeError: non-boolean (Interval{Float64}) used in boolean context
hongchengni commented 4 years ago

Support. It would be great if complex root finding is supported.

dpsanders commented 4 years ago

Since we can extract the Jacobian matrix of the pair of real functions (realpart, imagpart) from the complex derivative, it should be enough to provide the complex derivative, or calculate that using automatic differentiation if possible.

dpsanders commented 4 years ago

From Slack (Mason Protter): AD for complex functions works using ForwardDiff2.jl:

julia> using ForwardDiff2: DI

julia> f(z) = z^2 / (2z + 1)
f (generic function with 1 method)

julia> z = 1 + im
1 + 1im

julia> DI(f)(z) ≈ 2z*(z+1) / (2z + 1)^2
true