Jupyter_Cubic_1


January 10, 2019
In [1]: F(x) = 9*x^3 - 71*x^2 - 3833*x - 425
In [2]: S = solve(F(x) == 0, x, to_poly_solve=True)
In [3]: latex(S)
Out[3]: \left[x = \left(-\frac{1}{9}\right), x = \left(-17\right), x = 25\right]

x = 1 9 ,x = 17,x = 25

Hmmm… What manner of magic is this?

In [4]: G(x) = expand((x - 3) * (x - sqrt(2)) * (x + sqrt(2)))
In [5]: G(x)
Out[5]: x^3 - 3*x^2 - 2*x + 6
In [6]: S = solve(G(x) == 0, x, to_poly_solve=True)
In [7]: latex(S)
Out[7]: \left[x = -\sqrt{2}, x = \sqrt{2}, x = 3\right]

x = 2,x = 2,x = 3

Oh, I see. All the factors of the 4th term, positive or negative, could potentially be roots. If they are, then sage succeeds, because Factor Theorem next allows Sage to derive a quadratic.

In [8]: var(a, b, c)
Out[8]: (a, b, c)
In [9]: H(x) = a*x^2 + b*x + c
In [10]: S = solve(H(x) == 0, x, to_poly_solve=True)
In [11]: latex(S)
Out[11]: \left[x = -\frac{b + \sqrt{b^{2} - 4 \, a c}}{2 \, a}, x = -\frac{b - \sqrt{b^{2} - 4 \, a c}}{2 \, a}\right]

x = b+b2 4ac 2a ,x = bb2 4ac 2a

Let’s try a cubic, that has no such rational solutions…

In [12]: F1(x) = x^3 - 3*x^2 - 2*x + 5
In [13]: S = solve(F1(x) == 0, x, to_poly_solve=True)
In [14]: latex(S)
Out[14]: \left[x = -\frac{1}{2} \, {\left(\frac{1}{18} i \, \sqrt{473} \sqrt{3} - \frac{1}{2}\right)}^{\frac{1}{3}} {\left(i \, \sqrt{3} + 1\right)} - \frac{-5 i \, \sqrt{3} + 5}{6 \, {\left(\frac{1}{18} i \, \sqrt{473} \sqrt{3} - \frac{1}{2}\right)}^{\frac{1}{3}}} + 1, x = -\frac{1}{2} \, {\left(\frac{1}{18} i \, \sqrt{473} \sqrt{3} - \frac{1}{2}\right)}^{\frac{1}{3}} {\left(-i \, \sqrt{3} + 1\right)} - \frac{5 i \, \sqrt{3} + 5}{6 \, {\left(\frac{1}{18} i \, \sqrt{473} \sqrt{3} - \frac{1}{2}\right)}^{\frac{1}{3}}} + 1, x = {\left(\frac{1}{18} i \, \sqrt{473} \sqrt{3} - \frac{1}{2}\right)}^{\frac{1}{3}} + \frac{5}{3 \, {\left(\frac{1}{18} i \, \sqrt{473} \sqrt{3} - \frac{1}{2}\right)}^{\frac{1}{3}}} + 1\right]

x = 1 2 1 18i4733 1 21 3 i3 + 1 5i3+5 6 1 18i47331 21 3 + 1,x = 1 2 1 18i4733 1 21 3 i3 + 1 5i3+5 6 1 18i47331 21 3 + 1,x = 1 18i4733 1 21 3 + 5 3 1 18i47331 21 3 + 1

Aha, gotcha! I know this cubic has 3 real roots, which can be approximated, according to much of the same methodology: First, successively-approximate a root, then, factor down to an n-1 degree poly, then repeat…

In [15]: F1(x).roots(x, ring=CC, multiplicities=False)
Out[15]: [-1.33005873956798, 1.20163967572340, 3.12841906384458]
In [ ]: