Skip to content

Commit f0381ed

Browse files
committed
more clean up
1 parent fa9e7c5 commit f0381ed

File tree

6 files changed

+135
-89
lines changed

6 files changed

+135
-89
lines changed

Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ version = "3.1.4"
77
[deps]
88
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
99
MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
10-
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1110
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1211

1312
[compat]

src/polynomials/multroot.jl

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,47 +101,67 @@ function multroot(p::Polynomials.StandardBasisPolynomial{T}; verbose=false,
101101

102102
end
103103

104-
# The multiplicity structure, `l`, gives rise to a pejorative manifold `Πₗ = {Gₗ(z) | z∈ Cᵐ}`.
105-
function pejorative_manifold(p::Polynomials.StandardBasisPolynomial{T};
104+
# The multiplicity structure, `l`, gives rise to a pejorative manifold
105+
# `Πₗ = {Gₗ(z) | z ∈ Cᵐ}`. This first finds the approximate roots, then
106+
# finds the multiplicity structure
107+
function pejorative_manifold(p::Polynomials.StandardBasisPolynomial{T,X};
106108
θ = 1e-8, # zero singular-value threshold
107109
ρ = 1e-10, # initial residual tolerance
108110
ϕ = 100 # residual growth factor
109-
) where {T}
110-
p₂ = norm(p, 2)
111-
u, v, w, ρⱼ, κ = Polynomials.ngcd(p, derivative(p);
112-
satol = θ * p₂, srtol = zero(real(T)),
113-
atol = ρ * p₂, rtol = zero(real(T))
114-
)
111+
) where {T,X}
112+
113+
S = float(T)
114+
u = Polynomials.PnPolynomial{S,X}(S.(coeffs(p)))
115+
116+
nu₂ = norm(u, 2)
117+
θ′, ρ′ = θ * nu₂, ρ * nu₂
118+
119+
u, v, w, ρⱼ, κ = Polynomials.ngcd(u, derivative(u);
120+
satol = θ′, srtol = zero(real(T)),
121+
atol = ρ′, rtol = zero(real(T))
122+
)
123+
ρⱼ /= nu₂
115124

116125
zs = roots(v)
126+
ls = pejorative_manifold_multiplicities(u,
127+
zs, ρⱼ,
128+
θ, ρ, ϕ)
129+
zs, ls
130+
end
131+
132+
133+
134+
function pejorative_manifold_multiplicities(u::Polynomials.PnPolynomial{T},
135+
zs, ρⱼ,
136+
θ, ρ, ϕ) where {T}
117137
nrts = length(zs)
118138
ls = ones(Int, nrts)
119-
λ = ϕ
139+
120140
while !Polynomials.isconstant(u)
121141

122142
nu₂ = norm(u,2)
123-
θ′ = θ * nu₂
124-
ρ′ = max(ρ, ϕ * ρⱼ) # paper uses just latter
143+
θ = θ * nu₂
144+
ρ = max(ρ, ϕ * ρⱼ)
145+
ρ′ = ρ * nu₂
125146
u, v, w, ρⱼ, κ = Polynomials.ngcd(u, derivative(u),
126-
satol = θ,
127-
atol = ρ′,
128-
minⱼ = degree(u) - nrts
147+
satol = θ, srtol = zero(real(T)),
148+
atol = ρ′, rtol = zero(real(T)),
149+
minⱼ = degree(u) - nrts
129150
)
130-
131-
rts = roots(v)
132-
nrts = length(rts)
133-
134-
for z in rts
135-
tmp, ind = findmin(abs.(zs .- z))
151+
ρⱼ /= nu₂
152+
nrts = degree(v)
153+
for z roots(v)
154+
_, ind = findmin(abs.(zs .- z))
136155
ls[ind] += 1
137156
end
138157

139158
end
140159

141-
zs, ls # estimate for roots, multiplicities
160+
ls
142161

143162
end
144163

164+
145165
"""
146166
pejorative_root(p, zs, ls; kwargs...)
147167
@@ -266,10 +286,10 @@ cond_zl(p::AbstractPolynomial, zs::Vector{S}, ls) where {S} = cond_zl(reverse(c
266286

267287
function cond_zl(p, zs::Vector{S}, ls) where {S}
268288
J = zeros(S, sum(ls), length(zs))
269-
W = diagm(0 => [min(1, 1/abs(aᵢ)) for aᵢ in p[2:end]])
270289
evalJ!(J, zs, ls)
271-
_,R = qr(W*J)
272-
σ = Polynomials.NGCD.smallest_singular_value(UpperTriangular(R))
290+
W = diagm(0 => [min(1, 1/abs(aᵢ)) for aᵢ in p[2:end]])
291+
292+
σ = Polynomials.NGCD.smallest_singular_value(W*J)
273293
1 / σ
274294
end
275295

0 commit comments

Comments
 (0)