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
9 changes: 1 addition & 8 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,4 @@ InteractiveUtils = "1.10.0"
IntervalArithmetic = "1.0.3"
Reexport = "1"
StaticArrays = "1"
julia = "1"

[extras]
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Polynomials"]
julia = "1"
22 changes: 22 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[deps]
BranchAndPrune = "d3bc4f2e-91e6-11e9-365e-cd067da536ce"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
IntervalRootFinding = "d2bf35a9-74e0-55ec-b149-d360ff49b807"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
BranchAndPrune = "0.2.1"
ForwardDiff = "0.10, 1"
InteractiveUtils = "1.10.0"
IntervalArithmetic = "1.0.3"
Reexport = "1"
StaticArrays = "1"
Suppressor = "0.2.8"
julia = "1"
171 changes: 0 additions & 171 deletions test/findroots.jl

This file was deleted.

74 changes: 74 additions & 0 deletions test/multidimensional.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@testset "2D roots" begin
f(x, y) = [x^2 + y^2 - 1, y - 2x]
f(X) = f(X...)
X = [interval(-6, 6), interval(-6, 6)]

# Bisection
rts = roots(f, X ; contractor = Bisection, abstol = 1e-3)
exact_sol = [sqrt(1/5), 2sqrt(1/5)]
@test in_solution_set(exact_sol, root_region.(rts))
@test in_solution_set(-exact_sol, root_region.(rts))

for contractor in newtonlike_methods
deriv = xx -> ForwardDiff.jacobian(f, xx)
test_newtonlike(f, deriv, X, contractor, 2)
rts = roots(f, X ; contractor)
@test in_solution_set(exact_sol, root_region.(rts))
@test in_solution_set(-exact_sol, root_region.(rts))
end

# Infinite interval
X = [interval(-Inf, Inf), interval(-Inf, Inf)]
@suppress rts = roots(f, X ; contractor = Newton)
@test length(rts) == 2
end


# From R docs:
# https://www.rdocumentation.org/packages/pracma/versions/1.9.9/topics/broyden

@testset "3D roots" begin
function g(x)
(x1, x2, x3) = x
SVector( x1^2 + x2^2 + x3^2 - 1,
x1^2 + x3^2 - 0.25,
x1^2 + x2^2 - 4x3
)
end
dg = xx -> ForwardDiff.jacobian(g, xx)

X = interval(-5, 5)
XX = [X, X, X]

for contractor in newtonlike_methods
rts = roots(g, XX ; contractor)
@test length(rts) == 4
@test all(isunique, rts)
@test all(rts .== roots(g, XX ; contractor, derivative = dg))
end
end

@testset "10D roots" begin
include("../examples/10_dimensional.jl")

for contractor in newtonlike_methods
rts = roots(f10d, X10d_large ; contractor, max_iteration = 50_000)
@test any(X -> all(in_interval.(sol10d, X.region)), rts)

rts = roots(f10d, X10d_close ; contractor, max_iteration = 1_000_000)
@test length(rts) == 1
@test isunique(rts[1])
end
end

@testset "Dimension mismatch" begin
f21(xy) = [xy[1]^2 - 2]
f23(xy) = [xy[1]^2 - 2, xy[2]^2 - 3, xy[1] + xy[2]]

X = [interval(0, 5), interval(0, 5)]

for contractor in newtonlike_methods
@test_throws DimensionMismatch roots(f21, X ; contractor)
@test_throws DimensionMismatch roots(f23, X ; contractor)
end
end
86 changes: 0 additions & 86 deletions test/newton1d.jl

This file was deleted.

21 changes: 0 additions & 21 deletions test/quadratic.jl

This file was deleted.

Loading
Loading