Skip to content

Commit dd38b6e

Browse files
authored
Non-shrinking ModAB iteration (#861)
1 parent 46aeaf3 commit dd38b6e

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/BracketingNonlinearSolve/src/modAB.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function SciMLBase.__solve(
6666
end
6767
else # Anderson-Bjork method is used
6868
x3 = (x1 * y2 - y1 * x2) / (y2 - y1)
69+
x3 = clamp(x3, nextfloat(x1), prevfloat(x2))
6970
y3 = f(x3)
7071
threshold /= 2
7172
end

lib/BracketingNonlinearSolve/test/rootfind_tests.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,20 @@ end
152152
end
153153
end
154154

155+
@testitem "ModAB non-shrinking iteration" tags = [:core] begin
156+
# Issue #860
157+
a, b, c = 0.28299683548569865, 0.23110561490429102, -0.04293615418571393
158+
f = (x, _) -> a * x^2 + b * x + c
159+
tspan = (-18.26561304888476, -0.8216404439033063)
160+
161+
prob = IntervalNonlinearProblem{false}(f, tspan)
162+
sol = solve(prob, ModAB(); abstol = 0.0, reltol = 0.0)
163+
164+
@test sol.retcode == ReturnCode.FloatingPointLimit
165+
@test sol.left == -0.9726263117443217
166+
@test sol.right == -0.9726263117443216
167+
end
168+
155169
@testitem "Flipped Signs and Reversed Tspan" setup = [RootfindingTestSnippet] tags = [:core] begin
156170
@testset for alg in (
157171
Alefeld(), Bisection(), Brent(), Falsi(), ITP(), Muller(), Ridder(), ModAB(), nothing,

0 commit comments

Comments
 (0)