PolynomialRoots.jl icon indicating copy to clipboard operation
PolynomialRoots.jl copied to clipboard

sometimes returns bogus duplicate roots

Open stevengj opened this issue 1 year ago • 2 comments

As noted on discourse, the roots function seems to return bogus roots, which are all nearly identical, for some polynomials. It happens pretty often for me if you just randomly try different polynomials of degree 6. Here is one example:

c = [0.1767237967771577 - 0.8611076733845967im, 0.00017422934461020398 - 9.453901157858016e-6im, 2.8796166645520005e-5 - 6.235942236501559e-5im, 0.00011096228622067326 + 6.305229743814886e-5im, -4.383872407211953e-5 - 3.677479055394419e-5im, -5.464453142543401e-6 + 6.577470932911938e-5im, 1.0 + 0.0im]
r = roots(c, polish=true)

returns 6 nearly duplicate "roots"

6-element Vector{ComplexF64}:
 1.0126353489009172 + 7.1699666737369805im
  1.012635472445031 + 7.169966573453136im
 1.0126355118156847 + 7.169966616995025im
 1.0126353647489426 + 7.169966609253118im
 1.0126354389431256 + 7.169966613009901im
  1.012635426566087 + 7.169966602733274im

which are not roots at all:

julia> evalpoly.(r, Ref(c))
6-element Vector{ComplexF64}:
 -96023.81180290483 + 107521.12470406065im
  -96023.7931286698 + 107521.12824563321im
 -96023.79406644785 + 107521.13519457991im
 -96023.80469749296 + 107521.12117898901im
 -96023.79932061117 + 107521.12823827742im
 -96023.79933709523 + 107521.12631673364im

The correct roots are returned by Polynomials.roots, and they are completely different from the values returned above:

julia> import Polynomials

julia> r2 = Polynomials.roots(Polynomials.Polynomial(c))
6-element Vector{ComplexF64}:
   -0.936358238274595 - 0.28505582219111214im
   -0.714980912681819 + 0.6683037772456318im
 -0.22129525444596665 - 0.9534008044046407im
  0.22128062807035184 + 0.9533676310467337im
   0.7150642724349877 - 0.6683776196201094im
   0.9362949693501847 + 0.2850970632141694im

julia> evalpoly.(r2, Ref(c))
6-element Vector{ComplexF64}:
   8.881784197001252e-16 + 1.4432899320127035e-15im
   5.218048215738236e-15 - 3.3306690738754696e-15im
 -2.7755575615628914e-17 - 4.9960036108132044e-15im
  -2.248201624865942e-15 + 2.9976021664879227e-15im
  1.7763568394002505e-15 - 2.55351295663786e-15im
   4.440892098500626e-16 + 2.55351295663786e-15im

stevengj avatar Dec 13 '22 23:12 stevengj