Skip to content

Commit f18e746

Browse files
committed
Corrected the new roots() function for Laurent polynomials so that it works for cases with only strictly positive powers. Increased version to 1.1.5.
1 parent 81037dc commit f18e746

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "Polynomials"
22
uuid = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
33
license = "MIT"
44
author = "JuliaMath"
5-
version = "1.1.4"
5+
version = "1.1.5"
66

77
[deps]
88
Intervals = "d8418881-c3e1-53bb-8760-2df7ec849ed5"

src/polynomials/LaurentPolynomial.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ end
503503
504504
Compute the roots of the Laurent polynomial `p`.
505505
506-
The roots of a function (Laurent polynomial in this case) `a(z)` are the values of `z` for which the function vanishes. A Laurent polynomial ``a(z) = a_m z^m + a_{m+1} z^{m+1} + ... + a_{-1} z^{-1} + a_0 + a_1 z + ... + a_{n-1} z^{n-1} + a_n z^n`` can equivalently be viewed as a rational function with a multiple singularity (pole) at the origin. The roots are then the roots of the numerator polynomial. For example, ``a(z) = 1/z + 2 + z`` can be written as ``a(z) = (1+2z+z^2) / z`` and the roots of `a` are the roots of ``1+2z+z^2``.
506+
The roots of a function (Laurent polynomial in this case) `a(z)` are the values of `z` for which the function vanishes. A Laurent polynomial ``a(z) = a_m z^m + a_{m+1} z^{m+1} + ... + a_{-1} z^{-1} + a_0 + a_1 z + ... + a_{n-1} z^{n-1} + a_n z^n`` can equivalently be viewed as a rational function with a multiple singularity (pole) at the origin. The roots are then the roots of the numerator polynomial. For example, ``a(z) = 1/z + 2 + z`` can be written as ``a(z) = (1+2z+z^2) / z`` and the roots of `a` are the roots of ``1+2z+z^2``.
507507
508508
# Example
509509
@@ -521,7 +521,11 @@ julia> roots(a)
521521
"""
522522
function roots(p::P; kwargs...) where {T, P <: LaurentPolynomial{T}}
523523
c = coeffs(p)
524-
a = Polynomial(c,p.var)
524+
r = range(p)
525+
d = r[end]-min(0,r[1])+1 # Length of the coefficient vector, taking into consideration the case when the lower degree is strictly positive (like p=3z^2).
526+
z = zeros(T,d) # Reserves space for the coefficient vector.
527+
z[max(0,r[1])+1:end] = c # Leaves the coeffs of the lower powers as zeros.
528+
a = Polynomial(z,p.var) # The root is then the root of the numerator polynomial.
525529
return roots(a; kwargs...)
526530
end
527531

0 commit comments

Comments
 (0)