@@ -20,17 +20,21 @@ function Bisection(; exact_left = false, exact_right = false)
20
20
end
21
21
22
22
function SciMLBase. solve (prob:: IntervalNonlinearProblem , alg:: Bisection , args... ;
23
- maxiters = 1000 ,
23
+ maxiters = 1000 , abstol = min ( eps (prob . tspan[ 1 ]), eps (prob . tspan[ 2 ])),
24
24
kwargs... )
25
25
f = Base. Fix2 (prob. f, prob. p)
26
26
left, right = prob. tspan
27
27
fl, fr = f (left), f (right)
28
-
29
28
if iszero (fl)
30
29
return SciMLBase. build_solution (prob, alg, left, fl;
31
30
retcode = ReturnCode. ExactSolutionLeft, left = left,
32
31
right = right)
33
32
end
33
+ if iszero (fr)
34
+ return SciMLBase. build_solution (prob, alg, right, fr;
35
+ retcode = ReturnCode. ExactSolutionRight, left = left,
36
+ right = right)
37
+ end
34
38
35
39
i = 1
36
40
if ! iszero (fr)
@@ -41,6 +45,11 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Bisection, args...
41
45
retcode = ReturnCode. FloatingPointLimit,
42
46
left = left, right = right)
43
47
fm = f (mid)
48
+ if abs ((right - left) / 2 ) < abstol
49
+ return SciMLBase. build_solution (prob, alg, mid, fm;
50
+ retcode = ReturnCode. Success,
51
+ left = left, right = right)
52
+ end
44
53
if iszero (fm)
45
54
right = mid
46
55
break
@@ -63,6 +72,11 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Bisection, args...
63
72
retcode = ReturnCode. FloatingPointLimit,
64
73
left = left, right = right)
65
74
fm = f (mid)
75
+ if abs ((right - left) / 2 ) < abstol
76
+ return SciMLBase. build_solution (prob, alg, mid, fm;
77
+ retcode = ReturnCode. Success,
78
+ left = left, right = right)
79
+ end
66
80
if iszero (fm)
67
81
right = mid
68
82
fr = fm
0 commit comments