Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions src/DerivativeFree/muller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,24 @@ struct MullerState{T,S} <: AbstractUnivariateZeroState{T,S}
fxn0::S
end



function _muller_bootstrap(f::Callable_Function, x::Number)
a, b = x₀x₁(float(x))
fa, fb = f.((a,b))
a, b = x₀x₁(float(x))
fa, fb = f.((a, b))
c = b - fb * (b-a)/(fb-fa)
fc = f(c)
(a,b,c,fa,fb,fc)
(a, b, c, fa, fb, fc)
end
function _muller_bootstrap(f::Callable_Function, x1::Number, x2::Number)
a, b = x₀x₁((float(x1), float(x2)))
fa, fb = f.((a,b))
a, b = x₀x₁((float(x1), float(x2)))
fa, fb = f.((a, b))
c = b - fb * (b-a)/(fb-fa)
fc = f(c)
(a,b,c,fa,fb,fc)
(a, b, c, fa, fb, fc)
end
function _muller_bootstrap(f::Callable_Function, x1::Number, x2::Number, x3)
a, b, c = float.((x1, x2, x3))
fa, fb, fc = f(a), f(b), f(c)
(a,b,c,fa,fb,fc)
(a, b, c, fa, fb, fc)
end

function init_state(M::Muller, F::Callable_Function, x)
Expand All @@ -61,7 +59,6 @@ function update_state(
options,
l=NullTracks(),
) where {T,S}

a, b, c = o.xn0, o.xn1, o.xn2
fa, fb, fc = o.fxn0, o.fxn1, o.fxn2

Expand All @@ -74,13 +71,14 @@ function update_state(
C = q1 * fc

Δ = B^2 - 4A * C
if typeof(Δ) <: Real && Δ < 0 &&
throw(
DomainError(
Δ,
"Discriminant is negative and the function most likely has complex roots. You might use the `Roots.Muller()` method with complex input.",
),
)
if typeof(Δ) <: Real &&
Δ < 0 &&
throw(
DomainError(
Δ,
"Discriminant is negative and the function most likely has complex roots. You might use the `Roots.Muller()` method with complex input.",
),
)
end

Δ = √Δ
Expand All @@ -94,7 +92,7 @@ function update_state(
return o, true
end

x = c - inc
x = c - inc
fx = first(F(x))

# check for oddity?
Expand All @@ -107,6 +105,5 @@ function update_state(
@reset o.fxn1 = fc
@reset o.fxn2 = fx


return (o, false)
end
51 changes: 40 additions & 11 deletions src/deprecated/alternative_interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ See also `Roots.newton((f,fp), x0)` and `Roots.newton(fΔf, x0)` for simpler imp

"""
function newton(f, fp, x0; kwargs...)
Base.depwarn("`newton(f, fp, x0)` is deprecated; use `find_zero((f,fp), x0, Roots.Newton())` instead.", :newton)
Base.depwarn(
"`newton(f, fp, x0)` is deprecated; use `find_zero((f,fp), x0, Roots.Newton())` instead.",
:newton,
)
find_zero((f, fp), x0, Newton(); kwargs...)
end

Expand Down Expand Up @@ -54,7 +57,10 @@ Keyword arguments are passed to `find_zero` using the `Roots.Halley()` method.
"""
=#
function halley(f, fp, fpp, x0; kwargs...)
Base.depwarn("`halley(f, fp, fpp, x0)` is deprecated; use `find_zero((f,fp, fpp), x0, Roots.Halley())` instead.", :halley)
Base.depwarn(
"`halley(f, fp, fpp, x0)` is deprecated; use `find_zero((f,fp, fpp), x0, Roots.Halley())` instead.",
:halley,
)
find_zero((f, fp, fpp), x0, Halley(); kwargs...)
end

Expand Down Expand Up @@ -83,19 +89,28 @@ Keyword arguments are passed to `find_zero` using the `Roots.QuadraticInverse()`
"""
=#
function quadratic_inverse(f, fp, fpp, x0; kwargs...)
Base.depwarn("`quadratic_inverse(f, fp, fpp, x0)` is deprecated; use `find_zero((f,fp, fpp), x0, Roots.QuadraticInverse())` instead.", :quadratic_inverse)
Base.depwarn(
"`quadratic_inverse(f, fp, fpp, x0)` is deprecated; use `find_zero((f,fp, fpp), x0, Roots.QuadraticInverse())` instead.",
:quadratic_inverse,
)

find_zero((f, fp, fpp), x0, QuadraticInverse(); kwargs...)
end

function superhalley(f, fp, fpp, x0; kwargs...)
Base.depwarn("`superhalley(f, fp, fpp, x0)` is deprecated; use `find_zero((f,fp, fpp), x0, Roots.SuperHalley())` instead.", :superhalley)
Base.depwarn(
"`superhalley(f, fp, fpp, x0)` is deprecated; use `find_zero((f,fp, fpp), x0, Roots.SuperHalley())` instead.",
:superhalley,
)

find_zero((f, fp, fpp), x0, SuperHalley(); kwargs...)
end

function chebyshev_like(f, fp, fpp, x0; kwargs...)
Base.depwarn("`chebyshev_like(f, fp, fpp, x0)` is deprecated; use `find_zero((f,fp, fpp), x0, Roots.ChebyshevLike())` instead.", :chebyshev_like)
Base.depwarn(
"`chebyshev_like(f, fp, fpp, x0)` is deprecated; use `find_zero((f,fp, fpp), x0, Roots.ChebyshevLike())` instead.",
:chebyshev_like,
)

find_zero((f, fp, fpp), x0, ChebyshevLike(); kwargs...)
end
Expand Down Expand Up @@ -186,7 +201,10 @@ function fzero(
tracks=NullTracks(),
kwargs...,
)
Base.depwarn("`fzero(f, x0, M)` is deprecated; use `find_zero(f, x0, M)` instead.", :fzero)
Base.depwarn(
"`fzero(f, x0, M)` is deprecated; use `find_zero(f, x0, M)` instead.",
:fzero,
)

tracks = (verbose && isa(tracks, NullTracks)) ? Tracks() : tracks
α = find_zero(FnWrapper(f), x0, M; tracks, kwargs...)
Expand All @@ -203,7 +221,10 @@ function fzero(
tracks=NullTracks(),
kwargs...,
)
Base.depwarn("`fzero(f, x0, M, N)` is deprecated; use `find_zero(f, x0, M, N)` instead.", :fzero)
Base.depwarn(
"`fzero(f, x0, M, N)` is deprecated; use `find_zero(f, x0, M, N)` instead.",
:fzero,
)

tracks = (verbose && isa(tracks, NullTracks)) ? Tracks() : tracks
a = find_zero(FnWrapper(f), x0, M, N; tracks, kwargs...)
Expand All @@ -218,8 +239,10 @@ function fzero(
tracks=NullTracks(),
kwargs...,
) where {T<:Number,S<:Number}
Base.depwarn("`fzero(f, (a,b))` is deprecated; use `find_zero(f, (a,b))` instead.", :fzero)

Base.depwarn(
"`fzero(f, (a,b))` is deprecated; use `find_zero(f, (a,b))` instead.",
:fzero,
)

d = Dict(kwargs...)
tracks = (verbose && isa(tracks, NullTracks)) ? Tracks() : tracks
Expand Down Expand Up @@ -250,7 +273,10 @@ function fzero(
tracks=NullTracks(),
kwargs...,
)
Base.depwarn("`fzero(f, fp, x0)` is deprecated; use `find_zero((f,fp), x0)` instead.", :fzero)
Base.depwarn(
"`fzero(f, fp, x0)` is deprecated; use `find_zero((f,fp), x0)` instead.",
:fzero,
)
tracks = (verbose && isa(tracks, NullTracks)) ? Tracks() : tracks
α = find_zero((f, fp), x0, Newton(); tracks, kwargs...)
verbose && display(tracks)
Expand Down Expand Up @@ -336,7 +362,10 @@ Compatibility interface for [`find_zeros`](@ref).

"""
function fzeros(f, a::Number, b::Number; kwargs...)
Base.depwarn("`fzeros(f, a,b)` is deprecated; use `find_zeros(f, a, b)` instead.", :fzeros)
Base.depwarn(
"`fzeros(f, a,b)` is deprecated; use `find_zeros(f, a, b)` instead.",
:fzeros,
)
find_zeros(FnWrapper(f), float(a), float(b); kwargs...)
end
fzeros(f, ab; kwargs...) = fzeros(f, _extrema(ab)...; kwargs...)
1 change: 0 additions & 1 deletion test/test_alternatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ import Roots.newton,
## Issue #143 test with new interface
Roots.newton(sin, cos, 3.0) ≈ π # uses find_zero
Roots.newton((sin, cos), 3.0) ≈ π # uses simple

end
1 change: 0 additions & 1 deletion test/test_find_zero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ end
@test @inferred(find_zero(x -> x + 1, (-1, 1))) == -1
end


## issue #188 with A42
f = let a = 0.18
x -> x * (1 - x^2) / ((x^2 + a^2) * (1 + a^2 * x^2))
Expand Down
1 change: 0 additions & 1 deletion test/test_fzero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,4 @@ import Roots.fzero

## issue #178 passing through method
@test fzero(sin, 3, 4, Roots.Brent()) ≈ π

end
3 changes: 1 addition & 2 deletions test/test_newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import Roots.newton,
2.414213562373095

## test with Complex input
@test real(find_zero((x -> x^3 - 1, x -> 3x^2), 1 + im, Roots.Newton())) ≈ 1.0
@test real(find_zero((x -> x^3 - 1, x -> 3x^2), 1 + im, Roots.Newton())) ≈ 1.0
@test real(find_zero((x -> x^3 - 1, x -> 3x^2), 1 + 10im, Roots.Newton())) ≈ (-1 / 2)


fdf = x -> (sin(x), sin(x) / cos(x)) # (f, f/f')
@test Roots.find_zero(fdf, 3.0, Roots.Newton()) ≈ π # uses find_zero
Roots.newton(fdf, 3.0) ≈ π # uses simple
Expand Down