ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 15 Jul 2015 15:45:45 +0200About roots of a certain polynomial equationhttps://ask.sagemath.org/question/25579/about-roots-of-a-certain-polynomial-equation/Why is Sage hanging up trying to find roots of this equation?
0 = (x^2 - 6.00000000000000)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1
Tue, 20 Jan 2015 21:55:47 +0100https://ask.sagemath.org/question/25579/about-roots-of-a-certain-polynomial-equation/Answer by rws for <p>Why is Sage hanging up trying to find roots of this equation?</p>
<pre><code>0 = (x^2 - 6.00000000000000)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1
</code></pre>
https://ask.sagemath.org/question/25579/about-roots-of-a-certain-polynomial-equation/?answer=27385#post-id-27385Actually, Sage can solve your form symbolically as soon as you replace `6.0` with 6 and apply `simplify_rectform`:
sage: ((x^2 - 6)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1).simplify_rectform()
(x^2 - 6)*x^2 - 2*x*(sqrt(5) - 1) + 1/2*sqrt(5) - 1/2
sage: solve(_,x)
[x == -1/2*sqrt(-2*sqrt(5) + 10) - 1, x == 1/2*sqrt(-2*sqrt(5) + 10) - 1, x == -1/2*sqrt(2*sqrt(5) + 6) + 1, x == 1/2*sqrt(2*sqrt(5) + 6) + 1]
Wed, 15 Jul 2015 15:45:45 +0200https://ask.sagemath.org/question/25579/about-roots-of-a-certain-polynomial-equation/?answer=27385#post-id-27385Answer by tmonteil for <p>Why is Sage hanging up trying to find roots of this equation?</p>
<pre><code>0 = (x^2 - 6.00000000000000)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1
</code></pre>
https://ask.sagemath.org/question/25579/about-roots-of-a-certain-polynomial-equation/?answer=25590#post-id-25590The answer is somehow similar to [that one](http://ask.sagemath.org/question/25587/how-to-stop-sage-from-finding-erroneous-complex-roots/?answer=25589#post-id-25589). It is important to know where your objects are living and define them into the right place. As for mathematics, Sage will not be able to handle ill-defined expressions consistently.
First, when you write `6.00000000000000` you define a numerical (floating-point, i.e. approximated) number:
sage: 6.00000000000000.parent()
Real Field with 53 bits of precision
While, when you write `e^(-2/5*I*pi)`, you define a symbolic expression:
sage: (e^(-2/5*I*pi)).parent()
Symbolic Ring
So, if you want something exact, you have to replace `6.00000000000000` by `6`, which is an exact integer:
sage: 6.parent()
Integer Ring
Also, `e^(-2/5*I*pi)` is not any complex number, but an algebraic one, so you should take the benefit of this.
Then, your function is not a genuine polynomial but a symbolic expression (you could also have `cos(log(x))` in such expression for example):
sage: p = (x^2 - 6)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1
sage: p.parent()
Symbolic Ring
So, let us transform it into a genuine polynomial defined on the field of (complex) algebraic numbers:
sage: P = p.polynomial(QQbar)
sage: P.parent()
Univariate Polynomial Ring in x over Algebraic Field
The `Univariate Polynomial Ring in x over Algebraic Field` makes more sense than a mysterious `Symbolic Ring`, isn't it ?
In this safer place, you can have a look at its roots:
sage: P.roots()
[(-2.175570504584946? + 0.?e-17*I, 1),
(-0.618033988749895? + 0.?e-17*I, 1),
(0.1755705045849463? + 0.?e-18*I, 1),
(2.618033988749895? + 0.?e-17*I, 1)]
Wed, 21 Jan 2015 10:23:43 +0100https://ask.sagemath.org/question/25579/about-roots-of-a-certain-polynomial-equation/?answer=25590#post-id-25590Answer by Rolandb for <p>Why is Sage hanging up trying to find roots of this equation?</p>
<pre><code>0 = (x^2 - 6.00000000000000)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1
</code></pre>
https://ask.sagemath.org/question/25579/about-roots-of-a-certain-polynomial-equation/?answer=25580#post-id-25580 I assume you are wondering why Sage is not recognizing that $(x^2 - 6)x^2 - 4x*(e^{\frac{2}{5}i\pi} + e^{\frac{-2}{5}i\pi}) - e^{\frac{4}{5}i\pi} - e^{\frac{-4}{5}i\pi} - 1=(x^2 - 6)x^2 - 8x*cos(\frac{2}{5}\pi) - 2*cos(\frac{4}{5}\pi) - 1$, and thereafter doesn't find the four real roots: $x=-2.1755705045849463, -0.618033988749891, 0.17557050458494627, 2.618033988749895$.
Mixing the world of solving algebraic equations - which are exact - with the world of finding roots - which are approximations - is seldom a good idea. If you would split both worlds, it goes fluently.
var('x')
f(x)=(x^2 - 6)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1
g(x)=real_part(f(x)).simplify()
print g
x |--> x^4 - 6*x^2 - 2*sqrt(5)*x + 2*x + 1/2*sqrt(5) - 1/2
print [find_root(g,-3,-2), find_root(g,-1,0), find_root(g,0,1), find_root(g,2,3)]
[-2.1755705045849463, -0.6180339887498911, 0.17557050458494627, 2.618033988749895]
Stated differently, always simplify your function (= exact) before going into a numerical process such as root finding. Any system - thus also Sage - hangs up because it is impossible to determine the simplification numerically.
Tue, 20 Jan 2015 23:57:21 +0100https://ask.sagemath.org/question/25579/about-roots-of-a-certain-polynomial-equation/?answer=25580#post-id-25580Comment by Phoenix for <p>I assume you are wondering why Sage is not recognizing that $(x^2 - 6)x^2 - 4x<em>(e^{\frac{2}{5}i\pi} + e^{\frac{-2}{5}i\pi}) - e^{\frac{4}{5}i\pi} - e^{\frac{-4}{5}i\pi} - 1=(x^2 - 6)x^2 - 8x</em>cos(\frac{2}{5}\pi) - 2*cos(\frac{4}{5}\pi) - 1$, and thereafter doesn't find the four real roots: $x=-2.1755705045849463, -0.618033988749891, 0.17557050458494627, 2.618033988749895$.</p>
<p>Mixing the world of solving algebraic equations - which are exact - with the world of finding roots - which are approximations - is seldom a good idea. If you would split both worlds, it goes fluently.</p>
<pre><code>var('x')
f(x)=(x^2 - 6)*x^2 - 4*x*(e^(2/5*I*pi) + e^(-2/5*I*pi)) - e^(4/5*I*pi) - e^(-4/5*I*pi) - 1
g(x)=real_part(f(x)).simplify()
print g
x |--> x^4 - 6*x^2 - 2*sqrt(5)*x + 2*x + 1/2*sqrt(5) - 1/2
print [find_root(g,-3,-2), find_root(g,-1,0), find_root(g,0,1), find_root(g,2,3)]
[-2.1755705045849463, -0.6180339887498911, 0.17557050458494627, 2.618033988749895]
</code></pre>
<p>Stated differently, always simplify your function (= exact) before going into a numerical process such as root finding. Any system - thus also Sage - hangs up because it is impossible to determine the simplification numerically.</p>
https://ask.sagemath.org/question/25579/about-roots-of-a-certain-polynomial-equation/?comment=25581#post-id-25581@Rolandb Why did you remove the imaginary part of the function? And since this is a quartic equation, shouldn't it be able to tell me the exact roots in terms of square-roots?Wed, 21 Jan 2015 01:02:54 +0100https://ask.sagemath.org/question/25579/about-roots-of-a-certain-polynomial-equation/?comment=25581#post-id-25581