Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return InitialFailure from bracketing methods if not enclosing interval #158

Merged
merged 1 commit into from
Sep 24, 2024
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: 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
Loading