diff --git a/src/DerivativeFree/muller.jl b/src/DerivativeFree/muller.jl index 506f1a77..43b7acdc 100644 --- a/src/DerivativeFree/muller.jl +++ b/src/DerivativeFree/muller.jl @@ -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) @@ -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 @@ -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 Δ = √Δ @@ -94,7 +92,7 @@ function update_state( return o, true end - x = c - inc + x = c - inc fx = first(F(x)) # check for oddity? @@ -107,6 +105,5 @@ function update_state( @reset o.fxn1 = fc @reset o.fxn2 = fx - return (o, false) end diff --git a/src/deprecated/alternative_interfaces.jl b/src/deprecated/alternative_interfaces.jl index ded1ab07..4275d62f 100644 --- a/src/deprecated/alternative_interfaces.jl +++ b/src/deprecated/alternative_interfaces.jl @@ -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 @@ -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 @@ -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 @@ -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...) @@ -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...) @@ -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 @@ -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) @@ -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...) diff --git a/test/test_alternatives.jl b/test/test_alternatives.jl index 77ba4f80..0db41a05 100644 --- a/test/test_alternatives.jl +++ b/test/test_alternatives.jl @@ -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 diff --git a/test/test_find_zero.jl b/test/test_find_zero.jl index 491a6a08..1b989d8e 100644 --- a/test/test_find_zero.jl +++ b/test/test_find_zero.jl @@ -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)) diff --git a/test/test_fzero.jl b/test/test_fzero.jl index bdbd2360..2a9c008d 100644 --- a/test/test_fzero.jl +++ b/test/test_fzero.jl @@ -71,5 +71,4 @@ import Roots.fzero ## issue #178 passing through method @test fzero(sin, 3, 4, Roots.Brent()) ≈ π - end diff --git a/test/test_newton.jl b/test/test_newton.jl index 00f22d14..fa631cf4 100644 --- a/test/test_newton.jl +++ b/test/test_newton.jl @@ -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