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
6 changes: 3 additions & 3 deletions src/internal_itp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem{IP, Tuple{T, T}}, alg::I
args...;
maxiters = 1000, kwargs...) where {IP, T}
f = Base.Fix2(prob.f, prob.p)
left, right = prob.tspan # a and b
left, right = minmax(prob.tspan...) # a and b
fl, fr = f(left), f(right)
ϵ = eps(T)
if iszero(fl)
Expand All @@ -40,7 +40,7 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem{IP, Tuple{T, T}}, alg::I
return SciMLBase.build_solution(prob, alg, right, fr;
retcode = ReturnCode.ExactSolutionRight, left, right)
end
span = abs(right - left)
span = right - left
k1 = T(alg.scaled_k1) / span
n0 = T(alg.n0)
n_h = exponent(span / (2 * ϵ))
Expand All @@ -49,7 +49,7 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem{IP, Tuple{T, T}}, alg::I

i = 1
while i ≤ maxiters
span = abs(right - left)
span = right - left
mid = (left + right) / 2
r = ϵ_s - (span / 2)

Expand Down
10 changes: 10 additions & 0 deletions test/internal_rootfinder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@ for Rootfinder in (InternalITP,)
@test abs.(solve(inp3, rf).u) ≈ sqrt.(p)
@test abs.(solve(inp4, rf).u) ≈ sqrt.(p)
end

# https://github.com/SciML/DifferentialEquations.jl/issues/1087
# Test with normal and reversed tspan.
# The expected zero is -acos(p), but there is another zero at acos(p) just outside tspan
f(u, p) = cos(u) - p
p = 0.9
inp1 = IntervalNonlinearProblem(f, (-1.1 * acos(p), 0.9 * acos(p)), p)
inp2 = IntervalNonlinearProblem(f, (0.9 * acos(p), -1.1 * acos(p)), p)
@test solve(inp1, rf).u ≈ -acos(p)
@test solve(inp2, rf).u ≈ -acos(p)
end
Loading