Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 0441067

Browse files
committed
tol fix for itp
1 parent aa6ddec commit 0441067

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/brent.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Brent, args...;
1313
a, b = prob.tspan
1414
fa, fb = f(a), f(b)
1515
ϵ = eps(convert(typeof(fa), 1.0))
16-
atol = abstol !== nothing ? abstol : min(eps(left), eps(right))
16+
atol = abstol !== nothing ? abstol : min(eps(a), eps(b))
1717

1818
if iszero(fa)
1919
return SciMLBase.build_solution(prob, alg, a, fa;

src/itp.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ struct ITP{T} <: AbstractBracketingAlgorithm
5959
end
6060

6161
function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::ITP,
62-
args...; abstol = 1.0e-15,
62+
args...; abstol = nothing,
6363
maxiters = 1000, kwargs...)
6464
f = Base.Fix2(prob.f, prob.p)
6565
left, right = prob.tspan # a and b
6666
fl, fr = f(left), f(right)
67-
ϵ = abstol
67+
ϵ = abstol !== nothing ? abstol : min(eps(left), eps(right))
6868
if iszero(fl)
6969
return SciMLBase.build_solution(prob, alg, left, fl;
7070
retcode = ReturnCode.ExactSolutionLeft, left = left,
@@ -111,6 +111,12 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::ITP,
111111
xp = mid -* r)
112112
end
113113

114+
if abs((left - right) / 2) < ϵ
115+
return SciMLBase.build_solution(prob, alg, mid, f(mid);
116+
retcode = ReturnCode.Success,
117+
left = left, right = right)
118+
end
119+
114120
## Update ##
115121
tmin, tmax = minmax(left, right)
116122
xp >= tmax && (xp = prevfloat(tmax))

0 commit comments

Comments
 (0)