|
1 | 1 | # Poly type manipulations
|
2 | 2 |
|
3 |
| -VERSION < v"0.7.0-beta2.199" && __precompile__() |
4 |
| - |
5 | 3 | module Polynomials
|
6 | 4 | #todo: sparse polynomials?
|
7 | 5 |
|
8 |
| -using Compat |
9 |
| - |
10 | 6 | export Poly, poly
|
11 | 7 | export degree, coeffs, variable, printpoly
|
12 | 8 | export polyval, polyint, polyder, roots, polyfit
|
13 | 9 | export Pade, padeval
|
14 | 10 |
|
15 |
| -import Compat.lastindex |
16 |
| - |
17 |
| -import Base: length, size, eltype, collect, eachindex |
| 11 | +import Base: length, size, eltype, collect, eachindex, lastindex |
18 | 12 | import Base: getindex, setindex!, copy, zero, one, convert, gcd
|
19 | 13 | import Base: show, print, *, /, //, -, +, ==, isapprox, divrem, div, rem, eltype
|
20 | 14 | import Base: promote_rule, truncate, chop, conj, transpose, hash
|
21 | 15 | import Base: isequal
|
22 |
| -import Compat.LinearAlgebra: norm, dot, eigvals, diagm, vecnorm, qrfact |
| 16 | +import LinearAlgebra: norm, dot, eigvals, diagm |
23 | 17 |
|
24 | 18 | const SymbolLike = Union{AbstractString,Char,Symbol}
|
25 | 19 |
|
@@ -145,16 +139,9 @@ eltype(::Type{Poly{T}}) where {T} = Poly{T}
|
145 | 139 | length(p::Poly) = length(coeffs(p))
|
146 | 140 | lastindex(p::Poly) = length(p) - 1
|
147 | 141 |
|
148 |
| -if VERSION < v"0.7.0-DEV.5126" |
149 |
| - import Base: start, next, done |
150 |
| - start(p::Poly) = start(coeffs(p)) - 1 |
151 |
| - next(p::Poly, state) = (temp = fill!(similar(coeffs(p)), 0); temp[state+1] = p[state]; (Poly(temp), state+1)) |
152 |
| - done(p::Poly, state) = state > degree(p) |
153 |
| -else |
154 |
| - import Base: iterate |
155 |
| - Base.iterate(p::Poly) = (p[0] * one(p), 1) |
156 |
| - Base.iterate(p::Poly, state) = state <= degree(p) ? (p[state]*variable(p)^(state), state+1) : nothing |
157 |
| -end |
| 142 | +import Base: iterate |
| 143 | +Base.iterate(p::Poly) = (p[0] * one(p), 1) |
| 144 | +Base.iterate(p::Poly, state) = state <= degree(p) ? (p[state]*variable(p)^(state), state+1) : nothing |
158 | 145 |
|
159 | 146 | # shortcut for collect(eltype, collection)
|
160 | 147 | collect(p::Poly{T}) where {T} = collect(Poly{T}, p)
|
@@ -405,14 +392,14 @@ rem(num::Poly, den::Poly) = divrem(num, den)[2]
|
405 | 392 | ==(n::Number, p1::Poly) = (p1 == n)
|
406 | 393 |
|
407 | 394 | """
|
408 |
| - isapprox{T,S}(p1::Poly{T}, p2::Poly{S}; rtol::Real = Base.rtoldefault(T,S, 0), atol::Real = 0, norm::Function = vecnorm) |
| 395 | + isapprox{T,S}(p1::Poly{T}, p2::Poly{S}; rtol::Real = Base.rtoldefault(T,S, 0), atol::Real = 0, norm::Function = norm) |
409 | 396 |
|
410 | 397 | Truncate polynomials `p1` and `p2`, and compare the coefficient vectors using the
|
411 | 398 | given `norm` function. The tolerances `rtol` and `atol` are passed to both
|
412 | 399 | `truncate` and `isapprox`.
|
413 | 400 | """
|
414 | 401 | function isapprox(p1::Poly{T}, p2::Poly{S};
|
415 |
| - rtol::Real = (Base.rtoldefault(T,S, 0)), atol::Real = 0, norm::Function = vecnorm) where {T,S} |
| 402 | + rtol::Real = (Base.rtoldefault(T,S, 0)), atol::Real = 0, norm::Function = norm) where {T,S} |
416 | 403 | p1.var == p2.var || error("Polynomials must have same variable")
|
417 | 404 | p1t = truncate(p1; rtol = rtol, atol = atol)
|
418 | 405 | p2t = truncate(p2; rtol = rtol, atol = atol)
|
@@ -697,7 +684,7 @@ argument can be used to specify the symbol for the returned polynomial.
|
697 | 684 | # Examples
|
698 | 685 |
|
699 | 686 | ```julia
|
700 |
| -julia> xs = linspace(0, pi, 5); |
| 687 | +julia> xs = range(0, stop=pi, length=5); |
701 | 688 |
|
702 | 689 | julia> ys = map(sin, xs);
|
703 | 690 |
|
|
0 commit comments