# How to solve a 5-order equation in sage?

I have tried to solve the following equation:

pp^5 + 4.61469389524440*pp^4 + (-12795.2676889452)*pp^3 + (-22752.9358658338)*pp^2 + 4.19349202517816e7*pp - 8.10593457285525e7


where pp is the independent variable. the command ' solve' don't work.

edit retag close merge delete

Sort by ยป oldest newest most voted

You can turn your symbolic expression into a polynomial over a well-defined ring. Given the coefficients, i presume that they are floating-point numbers. Given the precision, the best "field" for that is RDF (if they had more digits of precision, you shoud have a look at RealField or RealBallField).

sage: e = pp^5 + 4.61469389524440*pp^4 - 12795.2676889452*pp^3 - 22752.9358658338*pp^2 + 4.19349202517816e7*pp - 8.10593457285525e7
sage: e.parent()
Symbolic Ring

sage: e.plot(-100,100)
Launched png viewer for Graphics object consisting of 1 graphics primitive

sage: P = e.polynomial(RDF)
sage: P
pp^5 + 4.6146938952444*pp^4 - 12795.2676889452*pp^3 - 22752.9358658338*pp^2 + 41934920.2517816*pp - 81059345.7285525
sage: P.parent()
Univariate Polynomial Ring in pp over Real Double Field

sage: P.roots()
[(1.9372319190989842, 1)]
sage: P.roots(multiplicities=False)
[1.9372319190989842]

sage: e.plot(1,2)


Just in case, if the coefficients could be described as rational or algebraic numbers, i would suggest to use them as coefficients within the correct polynomial ring so that you will get exact solutions.

more

Here is a possibility:

sage: var( 'pp' );
sage: P = pp^5 + 4.61469389524440*pp^4 + (-12795.2676889452)*pp^3 + (-22752.9358658338)*pp^2 + 4.19349202517816e7*pp - 8.10593457285525e7
sage: P.polynomial(CC).roots( multiplicities=0 )
[1.93723191909898,
-81.8605754469774 - 7.33458961900103*I,
-81.8605754469774 + 7.33458961900103*I,
78.5846125398057 - 4.34280791632376*I,
78.5846125398057 + 4.34280791632376*I]


If precision is an issue, than a "better numerical field" is needed, e.g.

sage: C140 = ComplexField( prec=140 )
sage: C140(pi)
3.1415926535897932384626433832795028841972
sage: P.polynomial(C140).roots( multiplicities=0 )
[1.9372319190989844155691265074104706449442,
-81.860575446977365410019154805611554643630 - 7.3345896190010263397542664141658440115400*I,
-81.860575446977365410019154805611554643630 + 7.3345896190010263397542664141658440115400*I,
78.584612539805673040502993351629825294974 - 4.3428079163237635275011276669093668277717*I,
78.584612539805673040502993351629825294974 + 4.3428079163237635275011276669093668277717*I]


One can also use other libraries to get the (complex) roots, e.g.

sage: import numpy as np
sage: np.roots( P.coefficients(sparse=0)[::-1] )
array([-81.86057545+7.33458962j, -81.86057545-7.33458962j,
78.58461254+4.34280792j,  78.58461254-4.34280792j,
1.93723192+0.j        ])


but this may be interesting only when further working with that package and the collected data, here numpy.

more