..+ 314069483520)*sqrt(3) - 80295755776*x + 4831838208)/(1953125*x^63
- 73828125*x^61...
All I would really like is to see these displayed with approximate
coefficients, and to compute their roots.
First attempt: loop through each term and try to n() the coefficient.
Madness.
Second attempt: leave SR and work in `Polynomial`s over RR. This works
for display purposes, but once I have an MPolynomial_polydict object, I
can't figure out how to get the roots (potentially in either variable).
I can go back to SR, take the roots, and then.. go back to Polynomials?
Is there a better way to go about it? I feel like I'm reinventing the wheel.
Based on a suggestion Mike Hansen once gave me --
http://ask.sagemath.org/question/411/substituting-expressions-for-numbers
-- I tend to use subclasses of Converter when I need to do something
like this, so as not to get lost in the madness. :^) Something like:
from sage.symbolic.expression_conversions import Converter
class Evaluator(Converter):
def arithmetic(self, ex, operator):
return reduce(operator, map(self, ex.operands()))
def pyobject(self, ex, obj):
return ex.n()
sage: E = Evaluator()
sage: var("u x")
(u, x)
sage: q = ((314069483520)*sqrt(3/(sin(u+2)))*u - 80295755776*x +
4831838208)/(1953125*x^63)
sage: q
33554432/1953125*(9360*sqrt(3)*u*sqrt(1/sin(u + 2)) - 2393*x + 144)/x^63
sage: E(q)
17.179869183999998*(16211.99555884469*u*(1/sin(u + 2.0))^0.5 -
2393.0*x + 144.0)/x^63.0
Doug
This is neat, thanks. It should work for other transformations, too, not
just numerical approximation.