Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bisection root-finder #262

Closed
wants to merge 10 commits into from
Prev Previous commit
Modify type of empty vector of Roots
dpsanders committed Mar 21, 2017
commit e42821e1c5e75f709a1f789f12a879b7250c4c42
2 changes: 1 addition & 1 deletion src/root_finding/bisection.jl
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ function bisection{T<:Union{Interval,IntervalBox}}(f, X::T; tolerance=1e-3, debu
debug && @show X, image

if !(zero(X) ⊆ image)
return Root{T}[]
return Root{typeof(X)}[]
end

if diam(X) < tolerance
4 changes: 2 additions & 2 deletions src/root_finding/krawczyk.jl
Original file line number Diff line number Diff line change
@@ -66,10 +66,10 @@ function krawczyk{T}(f::Function, f_prime::Function, x::Interval{T}, level::Int=
# Maximum level of bisection
level >= maxlevel && return [Root(x, :unknown)]

isempty(x) && return Root{T}[] # [(x, :none)]
isempty(x) && return Root{typeof(x)}[] # [(x, :none)]
Kx = K(f, f_prime, x) ∩ x

isempty(Kx ∩ x) && return Root{T}[] # [(x, :none)]
isempty(Kx ∩ x) && return Root{typeof(x)}[] # [(x, :none)]

if Kx ⪽ x # isinterior
debug && (print("Refining "); @show(x))
4 changes: 2 additions & 2 deletions src/root_finding/newton.jl
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ function newton{T}(f::Function, f_prime::Function, x::Interval{T}, level::Int=0;

debug && (print("Entering newton:"); @show(level); @show(x))

isempty(x) && return Root{T}[] #[(x, :none)]
isempty(x) && return Root{typeof(x)}[] #[(x, :none)]

z = zero(x.lo)
tolerance = abs(tolerance)
@@ -79,7 +79,7 @@ function newton{T}(f::Function, f_prime::Function, x::Interval{T}, level::Int=0;
Nx = N(f, x, deriv)
debug && @show(Nx, Nx ⊆ x, Nx ∩ x)

isempty(Nx ∩ x) && return Root{T}[]
isempty(Nx ∩ x) && return Root{typeof(x)}[]

if Nx ⊆ x
debug && (print("Refining "); @show(x))