Skip to content

Commit

Permalink
Merge pull request #97 from jverzani/v0.6-7
Browse files Browse the repository at this point in the history
V0.6 7
  • Loading branch information
jverzani authored Jan 11, 2018
2 parents ac6f8b5 + d70cb30 commit 2bff0e5
Show file tree
Hide file tree
Showing 15 changed files with 387 additions and 429 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ os:
- osx
- linux
julia:
- 0.5
- 0.6
- nightly
matrix:
Expand Down
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[![Roots](http://pkg.julialang.org/badges/Roots_0.5.svg)](http://pkg.julialang.org/?pkg=Roots&ver=0.5)
[![Roots](http://pkg.julialang.org/badges/Roots_0.6.svg)](http://pkg.julialang.org/?pkg=Roots&ver=0.6)
Linux: [![Build Status](https://travis-ci.org/JuliaMath/Roots.jl.svg?branch=master)](https://travis-ci.org/JuliaMath/Roots.jl)
Windows: [![Build status](https://ci.appveyor.com/api/projects/status/goteuptn5kypafyl?svg=true)](https://ci.appveyor.com/project/jverzani/roots-jl)
Expand Down Expand Up @@ -115,10 +114,26 @@ end
fzero(D(m), 0, 1) - median(as) # 0.0
```

Some additional documentation can be read [here](http://nbviewer.ipython.org/url/github.com/JuliaLang/Roots.jl/blob/master/doc/roots.ipynb?create=1).

## Alternate interface

As an alternative interface to the MATLAB-inherited one through
`fzero`, the function `find_zero` can be used. For this, a type is
used to specify the method. For example,

```
find_zero(sin, 3.0, Order0())
find_zero(x -> x^5 - x- 1, 1.0, Order1()) # also Order2(), Order5(), Order8(), Order16()
```

## Polynomials
And bracketing methods:

Special methods for finding roots of polynomials have been moved to
the `PolynomialZeros` package and its `poly_roots(f, domain)` function.
```
find_zero(sin, (3, 4), Bisection())
find_zero(x -> x^5 - x - 1, (1,2), FalsePosition())
```


----

Some additional documentation can be read [here](http://nbviewer.ipython.org/url/github.com/JuliaLang/Roots.jl/blob/master/doc/roots.ipynb?create=1).
7 changes: 4 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
julia 0.5
ForwardDiff 0.2.0
Compat 0.17.0
julia 0.6.0
ForwardDiff 0.6.0
Compat 0.33.0
Missings 0.2.0
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
matrix:
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
Expand Down
83 changes: 25 additions & 58 deletions src/Roots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ __precompile__(true)
module Roots


import Base: *

if VERSION >= v"0.7-"
using Printf
else
using Missings
end

using ForwardDiff
using Compat
using Compat: @nospecialize


export fzero,
fzeros,
newton, halley,
secant_method, steffensen,
newton, halley, # deprecate these 4?
secant_method, steffensen,
D
export multroot, D2 # deprecated

export find_zero,
Order0, Order1, Order2, Order5, Order8, Order16
export Bisection, FalsePosition
# export Bisection, Secant, Steffensen, Newton, Halley

## load in files
include("adiff.jl")
Expand Down Expand Up @@ -60,6 +62,8 @@ function fzero(f, x0::Real; kwargs...)
derivative_free(f, x; kwargs...)
end



"""
Find zero of a function within a bracket
Expand Down Expand Up @@ -90,29 +94,28 @@ Example:
`fzero(sin, [big(3), 4]) find pi with more digits
"""
function fzero(f, a::Real, b::Real; kwargs...)
a,b = sort([a,b])
a,b = promote(float(a), b)
(a == -Inf) && (a = nextfloat(a))
(b == Inf) && (b = prevfloat(b))
(isinf(a) | isinf(b)) && throw(ConvergenceFailed("A bracketing interval must be bounded"))
find_zero(f, [a,b], Bisection(); kwargs...)
bracket = adjust_bracket((a, b))
a0, b0 = a < b ? promote(float(a), b) : promote(float(b), a)
(a0 == -Inf) && (a0 = nextfloat(a0))
(b0 == Inf) && (b0 = prevfloat(b0))
find_zero(f, bracket, Bisection(); kwargs...)
end

"""
Find a zero with bracket specified via `[a,b]`, as `fzero(sin, [3,4])`.
"""
function fzero{T <: Real}(f, bracket::Vector{T}; kwargs...)
function fzero(f, bracket::Vector{T}; kwargs...) where {T <: Real}
fzero(f, float(bracket[1]), float(bracket[2]); kwargs...)
end


"""
Find a zero within a bracket with an initial guess to *possibly* speed things along.
"""
function fzero{T <: Real}(f, x0::Real, bracket::Vector{T}; kwargs...)
a,b = sort(map(float,bracket))
(a == -Inf) && (a = nextfloat(a))
(b == Inf) && (b = prevfloat(b))
(isinf(a) | isinf(b)) && throw(ConvergenceFailed("A bracketing interval must be bounded"))
function fzero(f, x0::Real, bracket::Vector{T}; kwargs...) where {T <: Real}

a, b = adjust_bracket(bracket)

try
ex = a42a(f, a, b, float(x0); kwargs...)
catch ex
Expand Down Expand Up @@ -153,44 +156,8 @@ graphically, if possible.
function fzeros(f, a::Real, b::Real; kwargs...)
find_zeros(f, float(a), float(b); kwargs...)
end
fzeros{T <: Real}(f, bracket::Vector{T}; kwargs...) = fzeros(f, a, b; kwargs...)


## deprecate Polynomial calls

## Don't want to load `Polynomials` to do this...
# @deprecate roots(p) fzeros(p, a, b)

@deprecate D2(f) D(f,2)
fzeros(p) = Base.depwarn("""
Calling fzeros with just a polynomial is deprecated.
Either:
* Specify an interval to search over: fzeros(p, a, b).
* Use the `poly_roots(p, Over.R)` call from `PolynomialZeros`
* Use `Polynomials` or `PolynomialRoots` and filter. For example,
```
using Polynomials
x=variable()
filter(isreal, roots(f(x)))
```
""",:fzeros)

multroot(p) = Base.depwarn("The multroot function has moved to the PolynomialZeros package.",:multroot)

polyfactor(p) = Base.depwarn("""
The polyfactor function is in the PolynomialFactors package:
* if `p` is of type `Poly`: `PolynomialFactors.factor(p)`.
* if `p` is a function, try:
```
using PolynomialFactors, Polynomials
x = variable(Int)
PolynomialFactors.factor(p(x))
```
""",:polyfactor)
fzeros(f, bracket::Vector{T}; kwargs...) where {T <: Real} = fzeros(f, a, b; kwargs...)



end
Loading

0 comments on commit 2bff0e5

Please sign in to comment.