@@ -119,7 +119,8 @@ IntervalLike{T} = Union{Interval{T}, IntervalBox{T}}
119
119
NewtonLike = Union{Type{Newton}, Type{Krawczyk}}
120
120
121
121
"""
122
- roots(f, X, contractor, tol=1e-3 ; deriv=nothing)
122
+ roots(f, X, contractor, tol=1e-3)
123
+ roots(f, deriv, X, contractor, tol=1e-3)
123
124
124
125
Uses a generic branch and prune routine to find in principle all isolated roots of a function
125
126
`f:R^n → R^n` in a box `X`, or a vector of boxes.
@@ -134,36 +135,45 @@ Inputs:
134
135
135
136
"""
136
137
# Contractor specific `roots` functions
137
- function roots (f, X:: IntervalLike{T} , :: Type{Bisection} , tol:: Float64 = 1e-3 ; deriv = nothing ) where {T}
138
+ function roots (f, X:: IntervalLike{T} , :: Type{Bisection} , tol:: Float64 = 1e-3 ) where {T}
138
139
branch_and_prune (X, Bisection (f), tol)
139
140
end
140
141
141
- function roots (f, X:: Interval{T} , C:: NewtonLike , tol:: Float64 = 1e-3 ; deriv = nothing ) where {T}
142
+ function roots (f, X:: Interval{T} , C:: NewtonLike , tol:: Float64 = 1e-3 ) where {T}
142
143
143
- if deriv == nothing
144
- deriv = x -> ForwardDiff. derivative (f, x)
145
- end
144
+ deriv = x -> ForwardDiff. derivative (f, x)
145
+
146
+ roots (f, deriv, X, C, tol)
147
+ end
146
148
149
+ function roots (f, deriv, X:: Interval{T} , C:: NewtonLike , tol:: Float64 = 1e-3 ) where {T}
147
150
branch_and_prune (X, C (f, deriv), tol)
148
151
end
149
152
150
- function roots (f, X:: IntervalBox{T} , C:: NewtonLike , tol:: Float64 = 1e-3 ; deriv = nothing ) where {T}
153
+ function roots (f, X:: IntervalBox{T} , C:: NewtonLike , tol:: Float64 = 1e-3 ) where {T}
151
154
152
- if deriv == nothing
153
- deriv = x -> ForwardDiff. jacobian (f, x)
154
- end
155
+ deriv = x -> ForwardDiff. jacobian (f, x)
155
156
157
+ roots (f, deriv, X, C, tol)
158
+ end
159
+
160
+ function roots (f, deriv, X:: IntervalBox{T} , C:: NewtonLike , tol:: Float64 = 1e-3 ) where {T}
156
161
branch_and_prune (X, C (f, deriv), tol)
157
162
end
158
163
159
- roots (f, r:: Root , contractor:: Type{C} , tol:: Float64 = 1e-3 ; deriv = nothing ) where {C<: Contractor } = roots (f, r. interval, contractor, tol; deriv = deriv)
164
+ roots (f, r:: Root , contractor:: Type{C} , tol:: Float64 = 1e-3 ) where {C<: Contractor } =
165
+ roots (f, r. interval, contractor, tol)
166
+ roots (f, deriv, r:: Root , contractor:: Type{C} , tol:: Float64 = 1e-3 ) where {C<: Contractor } =
167
+ roots (f, deriv, r. interval, contractor, tol)
160
168
161
169
162
170
# Acting on a Vector:
163
171
164
172
# TODO : Use previous status information about roots:
165
- roots (f, V:: Vector{Root{T}} , contractor:: Type{C} , tol:: Float64 = 1e-3 ;
166
- deriv = nothing ) where {T, C<: Contractor } = vcat (roots .(f, V, contractor, tol; deriv = deriv)... )
173
+ roots (f, V:: Vector{Root{T}} , contractor:: Type{C} , tol:: Float64 = 1e-3 ) where {T, C<: Contractor } =
174
+ vcat (roots .(f, V, contractor, tol)... )
175
+ roots (f, deriv, V:: Vector{Root{T}} , contractor:: Type{C} , tol:: Float64 = 1e-3 ) where {T, C<: Contractor } =
176
+ vcat (roots .(f, deriv, V, contractor, tol)... )
167
177
168
178
169
179
@@ -179,22 +189,30 @@ function roots(f, Xc::Complex{Interval{T}}, contractor::Type{C},
179
189
return [Root (Complex (root. interval... ), root. status) for root in rts]
180
190
end
181
191
182
- function roots (f, Xc:: Complex{Interval{T}} , C:: NewtonLike , tol:: Float64 = 1e-3 ;
183
- deriv = nothing ) where {T}
192
+ function roots (f, Xc:: Complex{Interval{T}} , C:: NewtonLike , tol:: Float64 = 1e-3 ) where {T}
184
193
185
194
g = realify (f)
186
195
187
- if deriv == nothing
188
- g_prime = x -> ForwardDiff. jacobian (g, x)
189
- else
190
- g_prime = realify_derivative (deriv)
191
- end
196
+ g_prime = x -> ForwardDiff. jacobian (g, x)
197
+
198
+ Y = IntervalBox (reim (Xc))
199
+ rts = roots (g, g_prime, Y, C, tol)
200
+
201
+ return [Root (Complex (root. interval... ), root. status) for root in rts]
202
+ end
203
+
204
+ function roots (f, deriv, Xc:: Complex{Interval{T}} , C:: NewtonLike , tol:: Float64 = 1e-3 ) where {T}
205
+
206
+ g = realify (f)
207
+
208
+ g_prime = realify_derivative (deriv)
192
209
193
210
Y = IntervalBox (reim (Xc))
194
- rts = roots (g, Y, C, tol; deriv = g_prime )
211
+ rts = roots (g, g_prime, Y, C, tol)
195
212
196
213
return [Root (Complex (root. interval... ), root. status) for root in rts]
197
214
end
198
215
199
216
# Default
200
- roots (f, X, tol:: Float64 = 1e-15 ; deriv = nothing ) = roots (f, X, Newton, tol; deriv = deriv)
217
+ roots (f:: F , deriv:: F , X, tol:: Float64 = 1e-15 ) where {F<: Function } = roots (f, deriv, X, Newton, tol)
218
+ roots (f:: F , X, tol:: Float64 = 1e-15 ) where {F<: Function } = roots (f, X, Newton, tol)
0 commit comments