Skip to content

Commit 65b481f

Browse files
authored
add separate assess method; add docs on AlefeldPotra methods (#459)
* add separate assess method; add docs on AlefeldPotra methods * version bump
1 parent 5cce567 commit 65b481f

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Roots"
22
uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
3-
version = "2.2.3"
3+
version = "2.2.4"
44

55
[deps]
66
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"

src/Bracketing/alefeld_potra_shi.jl

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ An abstract type for Alefeld-Potra-Shi type bracketing problems, as discussed in
1616
The `update_step` method calls a `calculateΔ` method that can be customized to turn an algorithm based on interpolation into a bracketed algorithm. See [`Roots.BracketedHalley`](@ref) for an example.
1717
1818
This implementation deviates slightly from the printed algorithm, as it may use an initial call to `_middle` rather than a secant step, depending on the signs of ``a`` and ``b``.
19+
20+
!!! note
21+
These algorithms do not check the size of `f` for convergence, so the `atol` or `rtol` are not utilized.
1922
"""
2023
=#
2124
abstract type AbstractAlefeldPotraShi <: AbstractBracketingMethod end

src/convergence.jl

+11
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,17 @@ function assess_convergence(M::Any, state::AbstractUnivariateZeroState, options)
278278
return (:not_converged, false)
279279
end
280280

281+
function assess_convergence(M::AbstractBisection, state::AbstractUnivariateZeroState, options::O) where {O <: Union{ExactOptions, XExactOptions}}
282+
# return convergence_flag, boolean
283+
# no check if f == ∞
284+
is_exact_zero_f(M, state, options) && return (:exact_zero, true)
285+
isnan_f(M, state) && return (:nan, true)
286+
is_approx_zero_f(M, state, options) && return (:f_converged, true)
287+
iszero_Δx(M, state, options) && return (:x_converged, true)
288+
return (:not_converged, false)
289+
end
290+
291+
281292
# speeds up exact f values by just a bit (2% or so) over the above, so guess this is worth it.
282293
function assess_convergence(
283294
M::AbstractBracketingMethod,

test/test_find_zero.jl

+10
Original file line numberDiff line numberDiff line change
@@ -583,3 +583,13 @@ end
583583
@test ForwardDiff.gradient(H, [1.0, 2])[1] -0.4416107917053284
584584
end
585585
end
586+
587+
@testset "bracketing_atol" begin
588+
## issue $457
589+
f(x) = x^2 - 4
590+
@test find_zero(f, (0,Inf)) 2 # 2.0 correct
591+
@test find_zero(f, (0,Inf), atol=1) 1.9997558593749998
592+
@test find_zero(f, (0,Inf),atol=1e-5) 1.9999998807907102
593+
@test find_zero(f, (0,8), atol=1) 1.99609375
594+
@test find_zero(f, (0,8), atol=1e-3) 2.0000152587890625
595+
end

0 commit comments

Comments
 (0)