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

Commit 59c9f4c

Browse files
Merge pull request #72 from DaniGlez/main
Fix ITP for problems with flipped sign
2 parents 8717ca6 + fe74b25 commit 59c9f4c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/itp.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::ITP,
113113

114114
## Update ##
115115
yp = f(xp)
116-
if yp > 0
116+
yps = yp * sign(fr)
117+
if yps > 0
117118
right = xp
118119
fr = yp
119-
elseif yp < 0
120+
elseif yps < 0
120121
left = xp
121122
fl = yp
122123
else

test/basictests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,3 +539,19 @@ for alg in (SimpleNewtonRaphson(), SimpleTrustRegion())
539539
sol = solve(probN, alg)
540540
@test abs.(sol.u) sqrt.(p)
541541
end
542+
543+
# Flipped signs test
544+
f1(u, p) = u * u - p
545+
f2(u, p) = p - u * u
546+
547+
for Alg in (Alefeld, Bisection, Falsi, Brent, ITP, Ridder)
548+
alg = Alg()
549+
for p 1:4
550+
inp1 = IntervalNonlinearProblem(f1, (1.0, 2.0), p)
551+
inp2 = IntervalNonlinearProblem(f2, (1.0, 2.0), p)
552+
sol = solve(inp1, alg)
553+
@test abs.(sol.u) sqrt.(p)
554+
sol = solve(inp2, alg)
555+
@test abs.(sol.u) sqrt.(p)
556+
end
557+
end

0 commit comments

Comments
 (0)