Skip to content

Commit 597d610

Browse files
authored
Move complexroots (#332)
1 parent ad12fb6 commit 597d610

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.7.53"
3+
version = "0.7.54"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/specialfunctions.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,30 @@ end
587587
extrema(f::Fun{PiecewiseSpace{<:Any,<:UnionDomain,<:Real},<:Real}) =
588588
mapreduce(extrema,(x,y)->extrema([x...;y...]),components(f))
589589

590+
function companion_matrix(c::Vector{T}) where T
591+
n=length(c)-1
592+
593+
A=zeros(T,n,n)
594+
595+
for k=1:n
596+
A[k,end]=-c[k]/c[end]
597+
end
598+
599+
for k=2:n
600+
A[k,k-1]=one(T)
601+
end
602+
603+
return A
604+
end
605+
590606
function complexroots end
591607

608+
complexroots(cfs::Vector{<:Union{Float64,ComplexF64}}) =
609+
hesseneigvals(companion_matrix(chop(cfs,10eps())))
610+
611+
complexroots(neg::Vector, pos::Vector) =
612+
complexroots([reverse(chop(neg,10eps()), dims=1); pos])
613+
592614
function roots(f::Fun{<:PiecewiseSpace})
593615
rts=mapreduce(roots,vcat,components(f))
594616
k=1

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,13 @@ end
431431
λ2 = eigvals(B)
432432
@test λ1 λ2
433433
end
434+
435+
@testset "complexroots" begin
436+
cfs = [1.0, 1.0]
437+
r = complexroots(cfs)
438+
@test r == [-1.0]
439+
@test complexroots([0.0], cfs) == [-1.0]
440+
end
434441
end
435442

436443
@testset "Special functions" begin

0 commit comments

Comments
 (0)