JuliaIntervals / IntervalRootFinding.jl

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

Fix bug with interval going outside the domain of a function #93

Closed Kolaru closed 5 years ago

Kolaru commented 6 years ago

Fix #90. The strategy is simple:

Edit: I thought I had errors, but one of my packages was not up to date.

codecov-io commented 6 years ago

Codecov Report

Merging #93 into master will decrease coverage by 34.68%. The diff coverage is 96.77%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #93       +/-   ##
===========================================
- Coverage   93.17%   58.48%   -34.69%     
===========================================
  Files           9       11        +2     
  Lines         337      542      +205     
===========================================
+ Hits          314      317        +3     
- Misses         23      225      +202
Impacted Files Coverage Δ
src/contractors.jl 97.5% <96.77%> (-2.5%) :arrow_down:
src/IntervalRootFinding.jl 5.55% <0%> (-94.45%) :arrow_down:
src/root_object.jl 14.28% <0%> (-85.72%) :arrow_down:
src/linear_eq.jl 66.21% <0%> (-31.79%) :arrow_down:
src/roots.jl 81.03% <0%> (-18.97%) :arrow_down:
src/newton1d.jl 70.9% <0%> (-16.74%) :arrow_down:
src/complex.jl 72.22% <0%> (-14.45%) :arrow_down:
src/slopes.jl 76.19% <0%> (-12.7%) :arrow_down:
src/quadratic.jl 88.88% <0%> (-7.12%) :arrow_down:
src/newton.jl 0% <0%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 873aa00...44d80cc. Read the comment docs.

dpsanders commented 5 years ago

Sorry for the delay. Is this ready?

Kolaru commented 5 years ago

Yes.

dpsanders commented 5 years ago

With this PR, I get the following for the test case in #90:

julia> f(xx) = ( (x, y) = xx; SVector( log(y/x) + 3x, y -2x) )
f (generic function with 1 method)

julia> X = IntervalBox(-100..100, 2)
[-100, 100] × [-100, 100]

julia> roots(f, X)
8-element Array{Root{IntervalBox{2,Float64}},1}:
 Root([1.16965e-16, 8.42871e-16] × [1.16965e-16, 8.42871e-16], :unknown)
 Root([-5.97685e-16, 1.16966e-16] × [1.16965e-16, 8.42871e-16], :unknown)
 Root([-5.97685e-16, 1.16966e-16] × [-5.97685e-16, 1.16966e-16], :unknown)
 Root([-5.97685e-16, 1.16966e-16] × [-1.31234e-15, -5.97684e-16], :unknown)
 Root([-1.31234e-15, -5.97684e-16] × [-1.31234e-15, -5.97684e-16], :unknown)
 Root([-1.31234e-15, -5.97684e-16] × [-2.01591e-15, -1.31233e-15], :unknown)
 Root([-2.01591e-15, -1.31233e-15] × [-2.74181e-15, -2.0159e-15], :unknown)
 Root([-0.23105, -0.231049] × [-0.462099, -0.462098], :unique)

julia> roots(f, X, Krawczyk)
0-element Array{Root{IntervalBox{2,Float64}},1}

So Newton seems to be working now (maybe there is a double root at (0, 0)?) But Krawczyk isn't.

dpsanders commented 5 years ago

Hmm, in fact obviously the function does not even make sense at (0, 0).

Kolaru commented 5 years ago

So in order to fix #90 and #104 I ended up cleaning the whole contractors.jl file. The differences do not affect the Bisection methods and are as follow:

The last point was implemented to allow to test cases where exact 0 at the middle of an interval cause problem and thus to have a good and tested implementation of a safeguard mechanism for these cases. However, I was not able to find any example that fail at exact 0 with the current implementation so it is not currently used.

Kolaru commented 5 years ago

@dpsanders Will you have time to review it soon ? This PR contains some unrelated fixes for tests that fail due to recent change in IntervalArithmetic.jl, so if you don't have time I may put them in a separated hotfix (mainly so I can rebase my other PR and have them pass all tests).

dpsanders commented 5 years ago

I hope to get to get to this soon, sorry.