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

Wrong roots with multroot

Open Goysa2 opened this issue 7 years ago • 3 comments

Hi!

I've had issues with the multroot function. I have the function f(x)=1.7273219441449328e-6+257.8444185695129x+111.17574047075945x^2

the roots for this polynomial function should be: -2.31925 and -6.699e-9 but if I do : using Roots f(x)=1.7273219441449328e-6+2*128.92220928475646*x+3*37.05858015691982*x^2 roots(f) multroot(f)

I get the following results: 2-element Array{Float64,1}: -2.31925 0.0 and: ([-2.31925,0.0],[1,1])

I know 0 is "almost the same thing" as -6.699e-9, but in what I am trying to do it makes a difference. Any idea why I get this problems?

(also if I compute the roots with the classic formula for 2nd order polynomial with Julia I get the right answers)

Goysa2 avatar May 01 '17 14:05 Goysa2

For such a small order polynomial, we should use a quadratic equation formula. But in general, multroot can introduce errors when it computes an approximate gcd. It can do better when there really are multiple roots, but otherwise there is some adjustment to the polynomial done under the assumption the coefficients are approximate.

jverzani avatar May 01 '17 20:05 jverzani

seems that multroot does not exist anymore?. i tested the same function on Julia 1.8.3, Roots 2.0.8, this time with find_zeros (with some reasonable bounds) and i get:

 using Roots
f(x)=1.7273219441449328e-6+2*128.92220928475646*x+3*37.05858015691982*x^2
julia> find_zeros(f,(-5,5))
2-element Vector{Float64}:
 -2.319250735213706
 -6.699086056301727e-9

that seems the correct result, but you need additional information

longemen3000 avatar Dec 18 '22 00:12 longemen3000

Yes, that functionality was moved out of Polynomials and into Roots, as it was polynomial specific. Here is how it can be used, though this polynomial doesn't have multiplicities, so roots would be a better choice.

julia> f1(x)=1.7273219441449328e-6+2*128.92220928475646*x+3*37.05858015691982*x^2
f1 (generic function with 1 method)

julia> x = variable()
f1(x)Polynomial(x)

julia> f1(x)
Polynomial(1.7273219441449328e-6 + 257.8444185695129*x + 111.17574047075945*x^2)

julia> Polynomials.Multroot.multroot(f1(x))
(values = [-2.319250735213706, -6.699086056301728e-9], multiplicities = [1, 1], κ = 257.8447798246725, ϵ = 0.0)

jverzani avatar Dec 18 '22 22:12 jverzani