@@ -78,9 +78,9 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::ITP,
78
78
k1 = alg. k1
79
79
k2 = alg. k2
80
80
n0 = alg. n0
81
- n_h = ceil (log2 ((right - left) / (2 * ϵ)))
81
+ n_h = ceil (log2 (abs (right - left) / (2 * ϵ)))
82
82
mid = (left + right) / 2
83
- x_f = (fr * left - fl * right) / (fr - fl )
83
+ x_f = left + (right - left) * (fl / (fl - fr) )
84
84
xt = left
85
85
xp = left
86
86
r = zero (left) # minmax radius
@@ -89,12 +89,12 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::ITP,
89
89
ϵ_s = ϵ * 2 ^ (n_h + n0)
90
90
i = 0 # iteration
91
91
while i <= maxiters
92
- # mid = (left + right) / 2
93
- r = ϵ_s - ((right - left) / 2 )
94
- δ = k1 * ((right - left) ^ k2)
92
+ span = abs ( right - left)
93
+ r = ϵ_s - (span / 2 )
94
+ δ = k1 * (span ^ k2)
95
95
96
96
# # Interpolation step ##
97
- x_f = (fr * left - fl * right) / (fr - fl )
97
+ x_f = left + (right - left) * (fl / (fl - fr) )
98
98
99
99
# # Truncation step ##
100
100
σ = sign (mid - x_f)
@@ -112,6 +112,9 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::ITP,
112
112
end
113
113
114
114
# # Update ##
115
+ tmin, tmax = minmax (left, right)
116
+ xp >= tmax && (xp = prevfloat (tmax))
117
+ xp <= tmin && (xp = nextfloat (tmin))
115
118
yp = f (xp)
116
119
yps = yp * sign (fr)
117
120
if yps > 0
@@ -121,16 +124,17 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::ITP,
121
124
left = xp
122
125
fl = yp
123
126
else
124
- left = xp
125
- right = xp
127
+ return SciMLBase. build_solution (prob, alg, xp, yps;
128
+ retcode = ReturnCode. Success, left = xp,
129
+ right = xp)
126
130
end
127
131
i += 1
128
132
mid = (left + right) / 2
129
133
ϵ_s /= 2
130
134
131
- if (right - left < 2 * ϵ)
132
- return SciMLBase. build_solution (prob, alg, mid, f (mid) ;
133
- retcode = ReturnCode. Success , left = left,
135
+ if nextfloat_tdir ( left, prob . tspan ... ) == right
136
+ return SciMLBase. build_solution (prob, alg, left, fl ;
137
+ retcode = ReturnCode. FloatingPointLimit , left = left,
134
138
right = right)
135
139
end
136
140
end
0 commit comments