Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "IntervalRootFinding"
uuid = "d2bf35a9-74e0-55ec-b149-d360ff49b807"
version = "0.7.1"
version = "0.7.2"

[deps]
BranchAndPrune = "d3bc4f2e-91e6-11e9-365e-cd067da536ce"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ julia> using IntervalArithmetic.Symbols # to use `..`
julia> f(x) = sin(x) - 0.1*x^2 + 1
f (generic function with 1 method)

julia> roots(f, -10..10)
julia> roots(f, -10 .. 10)
4-element Vector{Root{Interval{Float64}}}:
Root([-4.42654, -4.42653]_com_NG, :unique)
Root([-3.10682, -3.10681]_com_NG, :unique)
Expand Down
10 changes: 5 additions & 5 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ To do so, it uses methods from interval analysis, using interval arithmetic from

To begin, we need a standard Julia function and an interval in which to search roots of that function. Intervals use the `Interval` type provided by the `IntervalArithmetic.jl` package
Intervals are generally constructed using the `..` syntax (from the `IntervalArithmetic.Symbols` submodule),
`a..b` representing the closed interval $[a, b]$.
`a .. b` representing the closed interval $[a, b]$.

When provided with this information, the `roots` function will return a vector of all roots of the function in the given interval.

Expand All @@ -26,7 +26,7 @@ Example:
```jldoctest
julia> using IntervalArithmetic, IntervalArithmetic.Symbols, IntervalRootFinding

julia> rts = roots(x -> x^2 - 2x, 0..10)
julia> rts = roots(x -> x^2 - 2x, 0 .. 10)
2-element Vector{Root{Interval{Float64}}}:
Root([0.0, 3.73951e-8]_com_NG, :unknown)
Root([1.99999, 2.00001]_com_NG, :unique)
Expand Down Expand Up @@ -67,7 +67,7 @@ For example:
julia> g(x) = (x^2 - 2)^2 * (x^2 - 3)
g (generic function with 1 method)

julia> roots(g, -10..10)
julia> roots(g, -10 .. 10)
4-element Vector{Root{Interval{Float64}}}:
Root([-1.73206, -1.73205]_com_NG, :unique)
Root([-1.41422, -1.41421]_com_NG, :unknown)
Expand Down Expand Up @@ -96,7 +96,7 @@ julia> function g( (x1, x2, x3) )
end
g (generic function with 1 method)

julia> X = -5..5
julia> X = -5 .. 5
[-5.0, 5.0]_com

julia> rts = roots(g, [X, X, X])
Expand All @@ -117,7 +117,7 @@ julia> using StaticArrays
julia> h((x, y)) = SVector(x^2 - 4, y^2 - 16)
h (generic function with 1 method)

julia> X = -5..5
julia> X = -5 .. 5
[-5.0, 5.0]_com

julia> roots(h, SVector(X, X))
Expand Down
28 changes: 14 additions & 14 deletions docs/src/roots.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Both the Newton and Krawczyk methods can determine if a root is unique in an int
The method used is given using the `contractor` keyword argument:

```jldoctest
julia> roots(log, -2..2 ; contractor = Newton)
julia> roots(log, -2 .. 2 ; contractor = Newton)
1-element Vector{Root{Interval{Float64}}}:
Root([0.999999, 1.00001]_com, :unique)

julia> roots(log, -2..2 ; contractor = Krawczyk)
julia> roots(log, -2 .. 2 ; contractor = Krawczyk)
1-element Vector{Root{Interval{Float64}}}:
Root([0.999999, 1.00001]_com, :unique)

julia> roots(log, -2..2 ; contractor = Bisection)
julia> roots(log, -2 .. 2 ; contractor = Bisection)
1-element Vector{Root{Interval{Float64}}}:
Root([0.999999, 1.00001]_com, :unknown)
```
Expand All @@ -37,11 +37,11 @@ Note that as shown in the example, the `log` function does not complain about be
Newton and Krawczyk methods require the function to be differentiable, but the derivative is usually computed automatically using forward-mode automatic differentiation, provided by the `ForwardDiff.jl` package. It is however possible to provide the derivative explicitly using the `derivative` keyword argument:

```jldoctest
julia> roots(log, -2..2 ; contractor = Newton, derivative = x -> 1/x)
julia> roots(log, -2 .. 2 ; contractor = Newton, derivative = x -> 1/x)
1-element Vector{Root{Interval{Float64}}}:
Root([0.999999, 1.00001]_com_NG, :unique)

julia> roots(log, -2..2 ; contractor = Krawczyk, derivative = x -> 1/x)
julia> roots(log, -2 .. 2 ; contractor = Krawczyk, derivative = x -> 1/x)
1-element Vector{Root{Interval{Float64}}}:
Root([0.999999, 1.00001]_com_NG, :unique)
```
Expand All @@ -51,12 +51,12 @@ When providing the derivative explicitly, the computation is expected to be slig
```julia-repl
julia> using BenchmarkTools

julia> @btime roots(log, -2..2 ; derivative = x -> 1/x)
julia> @btime roots(log, -2 .. 2 ; derivative = x -> 1/x)
7.050 μs (129 allocations: 9.33 KiB)
1-element Vector{Root{Interval{Float64}}}:
Root([1.0, 1.0]_com_NG, :unique)

julia> @btime roots(log, -2..2)
julia> @btime roots(log, -2 .. 2)
7.743 μs (129 allocations: 9.33 KiB)
1-element Vector{Root{Interval{Float64}}}:
Root([1.0, 1.0]_com, :unique)
Expand All @@ -73,7 +73,7 @@ f (generic function with 1 method)
julia> df( (x, y) ) = [cos(x) 0 ; 0 -sin(y)]
df (generic function with 1 method)

julia> roots(f, [-3..3, -3..3] ; derivative = df)
julia> roots(f, [-3 .. 3, -3 .. 3] ; derivative = df)
2-element Vector{Root{Vector{Interval{Float64}}}}:
Root(Interval{Float64}[[-3.93242e-20, 3.93242e-20]_com_NG, [-1.5708, -1.57079]_com_NG], :unique)
Root(Interval{Float64}[[-3.93242e-20, 3.93242e-20]_com_NG, [1.57079, 1.5708]_com_NG], :unique)
Expand All @@ -87,12 +87,12 @@ An absolute tolerance for the search may be specified as the `abstol` keyword ar
julia> g(x) = sin(exp(x))
g (generic function with 1 method)

julia> roots(g, 0..2)
julia> roots(g, 0 .. 2)
2-element Vector{Root{Interval{Float64}}}:
Root([1.14472, 1.14473]_com, :unique)
Root([1.83787, 1.83788]_com, :unique)

julia> roots(g, 0..2 ; abstol = 1e-1)
julia> roots(g, 0 .. 2 ; abstol = 1e-1)
2-element Vector{Root{Interval{Float64}}}:
Root([1.12049, 1.16994]_com, :unique)
Root([1.82369, 1.85206]_com, :unique)
Expand All @@ -104,7 +104,7 @@ A lower tolerance may greatly reduce the computation time, at the cost of an inc
julia> h(x) = cos(x) * sin(1 / x)
h (generic function with 1 method)

julia> @btime roots(h, 0.05..1)
julia> @btime roots(h, 0.05 .. 1)
484.488 μs (12218 allocations: 590.76 KiB)
6-element Vector{Root{Interval{Float64}}}:
Root([0.0530516, 0.0530517]_com_NG, :unique)
Expand All @@ -114,7 +114,7 @@ julia> @btime roots(h, 0.05..1)
Root([0.159155, 0.159155]_com_NG, :unique)
Root([0.31831, 0.31831]_com_NG, :unique)

julia> @btime roots(h, 0.05..1 ; abstol = 1e-2)
julia> @btime roots(h, 0.05 .. 1 ; abstol = 1e-2)
249.720 μs (6141 allocations: 297.80 KiB)
6-element Vector{Root{Interval{Float64}}}:
Root([0.0514446, 0.0531086]_com_NG, :unique)
Expand All @@ -128,7 +128,7 @@ julia> @btime roots(h, 0.05..1 ; abstol = 1e-2)
Not converged: region size smaller than the tolerance
Root([0.317161, 0.319318]_com_NG, :unique)

julia> @btime roots(h, 0.05..1 ; abstol = 1e-1)
julia> @btime roots(h, 0.05 .. 1 ; abstol = 1e-1)
66.330 μs (1402 allocations: 69.10 KiB)
3-element Vector{Root{Interval{Float64}}}:
Root([0.05, 0.107541]_com, :unknown)
Expand Down Expand Up @@ -178,7 +178,7 @@ so that the process is interrupted as soon as an error is encountered.
This is useful while debugging your code.

```julia-repl
julia> roots(f, -10..10, ; ignored_errors = [])
julia> roots(f, -10 .. 10, ; ignored_errors = [])
ERROR: InconclusiveBooleanOperation: The operation `[2.0, 2.0]_com_NG < [-10.0, 10.0]_com` cannot be determined unambiguously. See the documentation for more information. See also `strictprecedes`.
Stacktrace: [..]
```
12 changes: 6 additions & 6 deletions examples/roots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ using IntervalArithmetic.Symbols
using IntervalRootFinding

# Find roots of a function in a search region with defaul parameters
rts = roots(sin, -5..5)
rts = roots(sin, -5..6 ; contractor = Bisection, abstol = 1e-1)
rts = roots(sin, -5 .. 5)
rts = roots(sin, -5 .. 6 ; contractor = Bisection, abstol = 1e-1)

# Refine roots with different options
rts = vcat(roots.(sin, rts ; contractor = Krawczyk)...)
Expand All @@ -13,12 +13,12 @@ rts = vcat(roots.(sin, rts ; contractor = Krawczyk)...)
f(x, y) = [x^2 + y^2 - 1, y - x]
f(X) = f(X...) # Function must take a single vector as input

rts = roots(f, [-5..5, -5..5])
rts = roots(f, [-5 .. 5, -5 .. 5])

# When defining function mixing numbers and intervals use @exact to avoid the NG interval flag
@exact fe(x, y) = [x^2 + y^2 - 1, y - x]
fe(X) = fe(X...) # Function must take a single vector as input
rts = roots(fe, [-5..5, -5..5])
rts = roots(fe, [-5 .. 5, -5 .. 5])


# From R docs:
Expand All @@ -34,7 +34,7 @@ function g(x)
)
end

X = (-5..5)
X = (-5 .. 5)
rts = roots(g, SVector(X, X, X))

h(xv) = ((x,y) = xv; SVector(2*x - y - exp(-x), -x + 2*y - exp(-y)))
Expand All @@ -53,7 +53,7 @@ rts = roots(h, SVector(X, X))
## MINPACK benchmarks: https://github.com/JuliaNLSolvers/NLsolve.jl/blob/master/test/minpack.jl

rosenbrock(xx) = ( (x, y) = xx; SVector( 1 - x, 1000 * (y - x^2) ) )
X = SVector(-1e5..1e5, -1e5..1e5)
X = SVector(-1e5 .. 1e5, -1e5 .. 1e5)

rts = roots(rosenbrock, X)

Expand Down
2 changes: 1 addition & 1 deletion src/linear_eq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ end
function gauss_elimination_interval1(A::AbstractMatrix, b::AbstractArray; precondition=true)

n = size(A, 1)
x = fill(-1e16..1e16, n)
x = fill(-1e16 .. 1e16, n)

x = gauss_elimination_interval1!(x, A, b, precondition=precondition)

Expand Down
6 changes: 3 additions & 3 deletions test/linear_eq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ end

@testset "Linear Equations" begin

As = [[2..3 0..1; 1..2 2..3], ]
bs = [[0..120, 60..240], ]
xs = [[-120..90, -60..240], ]
As = [[2 .. 3 0 .. 1; 1 .. 2 2 .. 3], ]
bs = [[0 .. 120, 60 .. 240], ]
xs = [[-120 .. 90, -60 .. 240], ]

for i in 1:10
rand_A = rand_mat(i)[1]
Expand Down
Loading