@@ -36,78 +36,59 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem{IP, Tuple{T, T}}, alg::I
36
36
ϵ = eps (T)
37
37
if iszero (fl)
38
38
return SciMLBase. build_solution (prob, alg, left, fl;
39
- retcode = ReturnCode. ExactSolutionLeft, left = left,
40
- right = right)
39
+ retcode = ReturnCode. ExactSolutionLeft, left, right)
41
40
elseif iszero (fr)
42
41
return SciMLBase. build_solution (prob, alg, right, fr;
43
- retcode = ReturnCode. ExactSolutionRight, left = left,
44
- right = right)
42
+ retcode = ReturnCode. ExactSolutionRight, left, right)
45
43
end
46
- # defining variables/cache
47
- k1 = T (alg. k1)
48
44
k2 = T (alg. k2)
45
+ span = abs (right - left)
46
+ k1 = T (alg. alg_k1)
49
47
n0 = T (alg. n0)
50
- n_h = ceil (log2 (abs (right - left) / (2 * ϵ)))
51
- mid = (left + right) / 2
52
- x_f = (fr * left - fl * right) / (fr - fl)
53
- xt = left
54
- xp = left
55
- r = zero (left) # minmax radius
56
- δ = zero (left) # truncation error
57
- σ = 1.0
58
- ϵ_s = ϵ * 2 ^ (n_h + n0)
59
- i = 0 # iteration
60
- while i <= maxiters
61
- # mid = (left + right) / 2
48
+ n_h = exponent (span / (2 * ϵ))
49
+ ϵ_s = ϵ * exp2 (n_h + n0)
50
+ T0 = zero (fl)
51
+
52
+ i = 1
53
+ while i ≤ maxiters
54
+ stats. nsteps += 1
62
55
span = abs (right - left)
56
+ mid = (left + right) / 2
63
57
r = ϵ_s - (span / 2 )
64
- δ = k1 * (span^ k2)
65
58
66
- # # Interpolation step ##
67
- x_f = left + (right - left) * (fl / (fl - fr))
59
+ x_f = left + span * (fl / (fl - fr)) # Interpolation Step
68
60
69
- # # Truncation step ##
70
- σ = sign (mid - x_f)
71
- if δ <= abs (mid - x_f)
72
- xt = x_f + (σ * δ)
73
- else
74
- xt = mid
75
- end
61
+ δ = max (k1 * span^ k2, eps (x_f))
62
+ diff = mid - x_f
76
63
77
- # # Projection step ##
78
- if abs (xt - mid) <= r
79
- xp = xt
80
- else
81
- xp = mid - (σ * r)
82
- end
64
+ xt = ifelse (δ ≤ abs (diff), x_f + copysign (δ, diff), mid) # Truncation Step
83
65
84
- # # Update ##
85
- tmin, tmax = minmax (left, right)
86
- xp >= tmax && (xp = prevfloat (tmax))
87
- xp <= tmin && (xp = nextfloat (tmin))
66
+ xp = ifelse (abs (xt - mid) ≤ r, xt, mid - copysign (r, diff)) # Projection Step
67
+ if span < 2 ϵ
68
+ return SciMLBase. build_solution (
69
+ prob, alg, xt, f (xt); retcode = ReturnCode. Success, left, right
70
+ )
71
+ end
88
72
yp = f (xp)
73
+ stats. nf += 1
89
74
yps = yp * sign (fr)
90
- if yps > 0
91
- right = xp
92
- fr = yp
93
- elseif yps < 0
94
- left = xp
95
- fl = yp
75
+ if yps > T0
76
+ right, fr = xp, yp
77
+ elseif yps < T0
78
+ left, fl = xp, yp
96
79
else
97
- left = prevfloat_tdir (xp, prob. tspan... )
98
- right = xp
99
- return SciMLBase. build_solution (prob, alg, left, f (left);
100
- retcode = ReturnCode. Success, left = left,
101
- right = right)
80
+ return SciMLBase. build_solution (
81
+ prob, alg, xp, yps; retcode = ReturnCode. Success, left, right
82
+ )
102
83
end
84
+
103
85
i += 1
104
- mid = (left + right) / 2
105
86
ϵ_s /= 2
106
87
107
- if nextfloat_tdir (left, prob . tspan ... ) == right
108
- return SciMLBase. build_solution (prob, alg, left, fl;
109
- retcode = ReturnCode. FloatingPointLimit, left = left,
110
- right = right )
88
+ if nextfloat_tdir (left, left, right ) == right
89
+ return SciMLBase. build_solution (
90
+ prob, alg, right, fr; retcode = ReturnCode. FloatingPointLimit, left, right
91
+ )
111
92
end
112
93
end
113
94
return SciMLBase. build_solution (prob, alg, left, fl; retcode = ReturnCode. MaxIters,
0 commit comments