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

Fix ITP for problems with flipped sign #72

Merged
merged 1 commit into from
Jul 21, 2023
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
5 changes: 3 additions & 2 deletions src/itp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::ITP,

## Update ##
yp = f(xp)
if yp > 0
yps = yp * sign(fr)
if yps > 0
right = xp
fr = yp
elseif yp < 0
elseif yps < 0
left = xp
fl = yp
else
Expand Down
16 changes: 16 additions & 0 deletions test/basictests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -539,3 +539,19 @@ for alg in (SimpleNewtonRaphson(), SimpleTrustRegion())
sol = solve(probN, alg)
@test abs.(sol.u) ≈ sqrt.(p)
end

# Flipped signs test
f1(u, p) = u * u - p
f2(u, p) = p - u * u

for Alg in (Alefeld, Bisection, Falsi, Brent, ITP, Ridder)
alg = Alg()
for p ∈ 1:4
inp1 = IntervalNonlinearProblem(f1, (1.0, 2.0), p)
inp2 = IntervalNonlinearProblem(f2, (1.0, 2.0), p)
sol = solve(inp1, alg)
@test abs.(sol.u) ≈ sqrt.(p)
sol = solve(inp2, alg)
@test abs.(sol.u) ≈ sqrt.(p)
end
end