One way is to use polynomials
sage: x = polygen(QQ)
sage: (x^4 - 2*x - 1).roots(RealField(32), multiplicities=False)
[-0.474626618, 1.39533699]
sage: (x^4 - 2*x - 1).roots(ComplexField(128), multiplicities=False)
[-0.47462661756260555032941320989493141267,
1.3953369944670730187931436130710553428,
-0.46035518845223373423186520158806196509 -
1.1393176803019225636193089912568155343*I,
-0.46035518845223373423186520158806196509 +
1.1393176803019225636193089912568155343*I]
The method "roots" has an optional ring argument that can be used
to control what kind of solution you are looking for (rational, real,
complex, tuning precision of the answer, ...). In my example above
I used "RealField(32)" and "ComplexField(128)" which correspond
respectively to floating point numbers with precision respectively
32 and 128 bits.
You can also use SR (symbolic ring) if you want the symbolic version
sage: (x^4 - 2*x - 1).roots(SR, multiplicities=False)
[-1/2*sqrt(1/3)*sqrt((3*(2/9*sqrt(43)*sqrt(3) + 2)^(2/3) - 4...]
Vincent
Le 14/09/2020 à 23:23, Fernando Gouvea a écrit :
I still don't know my way around the Sage documentation... Sorry for the
elementary question.
I just tried to use the *solve* command to find the roots of a
polynomial of degree 4 with real coefficients. The result is a list of
solutions expressed in (complicated) symbolic form. When I attempted to
find the numerical value of the solutions, I got an error:
TypeError: cannot evaluate symbolic expression numerically
There must be a way to do this, analogous to the "solve" command in gp.
(I tried gp.solve(t=10,30,P(t)==0), but that gives an error too.)
Fernando
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sage-support/ee7fd546-606a-8e9d-6e75-4d9598ba8e57%40gmail.com.