1 | initial version |
Let us use exact arithmetics (first), instead of numerics. (Using an inaccurate f
below also works, when we only needs roots in ring=CC
, which uses a given precision, usually a sufficient one.)
alpha0 = 1/4 # 0.25
alpha1 = -5/2 # -2.5
alpha2 = 69282 / 10000 # 6.9282
alpha3 = -55/10 # -5.5
alpha4 = 1/2 # 0.5
alpha5 = -1/2 # -0.5
x = var('x')
f = alpha1 + alpha2*x + alpha3*x**2 + x**4 + alpha4/(x**2 - alpha0) + alpha5*x**2/(x**2 - alpha0)
g = f.factor().numerator()
print "g = %s" % g
I have only invented g
.
Then one of the following is the solution:
g.roots( ring=QQbar, multiplicities=False )
g.roots( ring=CC , multiplicities=False )
For instance:
print "g = %s" % g
print "The roots of g are as follows:"
g.roots( ring=QQbar, multiplicities=False )
Results:
g = 20000*x^6 - 115000*x^4 + 138564*x^3 - 32500*x^2 - 34641*x + 22500
The roots of g are as follows:
[-2.875215523839503?,
-0.5433030528116862?,
0.9541487172225938?,
1.408897521688209?,
0.5277361688701930? - 0.5071712949223566?*I,
0.5277361688701930? + 0.5071712949223566?*I]