Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #158 from TomRottier/main
Browse files Browse the repository at this point in the history
Return InitialFailure from bracketing methods if not enclosing interval
  • Loading branch information
ChrisRackauckas authored Sep 24, 2024
2 parents ae4f888 + 3f416ee commit b8239bd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/bracketing/bisection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Bisection,
prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, left, right)
end

if sign(fl) == sign(fr)
@warn "The interval is not an enclosing interval, opposite signs at the boundaries are required."
return build_solution(
prob, alg, left, fl; retcode = ReturnCode.InitialFailure, left, right)
end

i = 1
if !iszero(fr)
while i < maxiters
Expand Down
6 changes: 6 additions & 0 deletions src/bracketing/brent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Brent, args...;
prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, left, right)
end

if sign(fl) == sign(fr)
@warn "The interval is not an enclosing interval, opposite signs at the boundaries are required."
return build_solution(
prob, alg, left, fl; retcode = ReturnCode.InitialFailure, left, right)
end

if abs(fl) < abs(fr)
c = right
right = left
Expand Down
6 changes: 6 additions & 0 deletions src/bracketing/falsi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Falsi, args...;
prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, left, right)
end

if sign(fl) == sign(fr)
@warn "The interval is not an enclosing interval, opposite signs at the boundaries are required."
return build_solution(
prob, alg, left, fl; retcode = ReturnCode.InitialFailure, left, right)
end

# Regula Falsi Steps
i = 0
if !iszero(fr)
Expand Down
7 changes: 7 additions & 0 deletions src/bracketing/itp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::ITP, args...;
return build_solution(
prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, left, right)
end

if sign(fl) == sign(fr)
@warn "The interval is not an enclosing interval, opposite signs at the boundaries are required."
return build_solution(
prob, alg, left, fl; retcode = ReturnCode.InitialFailure, left, right)
end

ϵ = abstol
#defining variables/cache
k2 = alg.k2
Expand Down
6 changes: 6 additions & 0 deletions src/bracketing/ridder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Ridder, args...;
prob, alg, right, fr; retcode = ReturnCode.ExactSolutionRight, left, right)
end

if sign(fl) == sign(fr)
@warn "The interval is not an enclosing interval, opposite signs at the boundaries are required."
return build_solution(
prob, alg, left, fl; retcode = ReturnCode.InitialFailure, left, right)
end

xo = oftype(left, Inf)
i = 1
if !iszero(fr)
Expand Down

0 comments on commit b8239bd

Please sign in to comment.