Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong roots with multroot #69

Open
Goysa2 opened this issue May 1, 2017 · 3 comments
Open

Wrong roots with multroot #69

Goysa2 opened this issue May 1, 2017 · 3 comments

Comments

@Goysa2
Copy link

Goysa2 commented May 1, 2017

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)

@jverzani
Copy link
Member

jverzani commented May 1, 2017

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.

@longemen3000
Copy link
Contributor

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

@jverzani
Copy link
Member

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants