20
20
simpler dependencies.
21
21
"""
22
22
struct InternalITP
23
- k1:: Float64
24
- k2:: Float64
23
+ scaled_k1:: Float64
25
24
n0:: Int
26
25
end
27
26
28
- InternalITP () = InternalITP (0.007 , 1.5 , 10 )
27
+ InternalITP () = InternalITP (0.2 , 10 )
29
28
30
29
function SciMLBase. solve (prob:: IntervalNonlinearProblem{IP, Tuple{T, T}} , alg:: InternalITP ,
31
30
args... ;
@@ -36,78 +35,56 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem{IP, Tuple{T, T}}, alg::I
36
35
ϵ = eps (T)
37
36
if iszero (fl)
38
37
return SciMLBase. build_solution (prob, alg, left, fl;
39
- retcode = ReturnCode. ExactSolutionLeft, left = left,
40
- right = right)
38
+ retcode = ReturnCode. ExactSolutionLeft, left, right)
41
39
elseif iszero (fr)
42
40
return SciMLBase. build_solution (prob, alg, right, fr;
43
- retcode = ReturnCode. ExactSolutionRight, left = left,
44
- right = right)
41
+ retcode = ReturnCode. ExactSolutionRight, left, right)
45
42
end
46
- # defining variables/cache
47
- k1 = T (alg. k1)
48
- k2 = T (alg. k2)
43
+ span = abs (right - left)
44
+ k1 = T (alg. scaled_k1)/ span
49
45
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
46
+ n_h = exponent (span / (2 * ϵ))
47
+ ϵ_s = ϵ * exp2 (n_h + n0)
48
+ T0 = zero (fl)
49
+
50
+ i = 1
51
+ while i ≤ maxiters
62
52
span = abs (right - left)
53
+ mid = (left + right) / 2
63
54
r = ϵ_s - (span / 2 )
64
- δ = k1 * (span^ k2)
65
55
66
- # # Interpolation step ##
67
- x_f = left + (right - left) * (fl / (fl - fr))
56
+ x_f = left + span * (fl / (fl - fr)) # Interpolation Step
68
57
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
58
+ δ = max (k1 * span^ 2 , eps (x_f))
59
+ diff = mid - x_f
76
60
77
- # # Projection step ##
78
- if abs (xt - mid) <= r
79
- xp = xt
80
- else
81
- xp = mid - (σ * r)
82
- end
61
+ xt = ifelse (δ ≤ abs (diff), x_f + copysign (δ, diff), mid) # Truncation Step
83
62
84
- # # Update ##
85
- tmin, tmax = minmax (left, right)
86
- xp >= tmax && (xp = prevfloat (tmax))
87
- xp <= tmin && (xp = nextfloat (tmin))
63
+ xp = ifelse (abs (xt - mid) ≤ r, xt, mid - copysign (r, diff)) # Projection Step
64
+ if span < 2 ϵ
65
+ return SciMLBase. build_solution (
66
+ prob, alg, xt, f (xt); retcode = ReturnCode. Success, left, right
67
+ )
68
+ end
88
69
yp = f (xp)
89
70
yps = yp * sign (fr)
90
- if yps > 0
91
- right = xp
92
- fr = yp
93
- elseif yps < 0
94
- left = xp
95
- fl = yp
71
+ if yps > T0
72
+ right, fr = xp, yp
73
+ elseif yps < T0
74
+ left, fl = xp, yp
96
75
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)
76
+ return SciMLBase. build_solution (
77
+ prob, alg, xp, yps; retcode = ReturnCode. Success, left, right
78
+ )
102
79
end
80
+
103
81
i += 1
104
- mid = (left + right) / 2
105
82
ϵ_s /= 2
106
83
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 )
84
+ if nextfloat_tdir (left, left, right ) == right
85
+ return SciMLBase. build_solution (
86
+ prob, alg, right, fr; retcode = ReturnCode. FloatingPointLimit, left, right
87
+ )
111
88
end
112
89
end
113
90
return SciMLBase. build_solution (prob, alg, left, fl; retcode = ReturnCode. MaxIters,
0 commit comments