ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 26 Jul 2018 09:56:33 +0200Numerical approximation of coefficients in fractionshttps://ask.sagemath.org/question/43158/numerical-approximation-of-coefficients-in-fractions/I am aware that for expressions in the type
$$eq = c_0 + c_1x + c_2x^2...$$
the coefficients of x can be expressed as decimals by doing
eq.polinomial(RR)
however, I noticed that if it is in the form
$$eq = \dfrac{c_0 + c_1x}{c_2 + c_3x}$$
or in any form where it is impossible to express as $c_0 + c_1x^n$ where n is some power of x, the eq.polinomial(RR) only returns an error giving TypeError: fraction must have unit denominator.
How can I approximate $eq = \dfrac{c_0 + c_1x}{c_2 + c_3x}$ where $c_0, c_1, c_2, c_3$ becomes some decimals?
I am aware that $\dfrac{c_0 + c_1x}{c_2 + c_3x}$ is not a polynomial however I do not know what it is.Thu, 26 Jul 2018 03:49:12 +0200https://ask.sagemath.org/question/43158/numerical-approximation-of-coefficients-in-fractions/Answer by rburing for <p>I am aware that for expressions in the type
$$eq = c_0 + c_1x + c_2x^2...$$
the coefficients of x can be expressed as decimals by doing
eq.polinomial(RR)
however, I noticed that if it is in the form
$$eq = \dfrac{c_0 + c_1x}{c_2 + c_3x}$$
or in any form where it is impossible to express as $c_0 + c_1x^n$ where n is some power of x, the eq.polinomial(RR) only returns an error giving TypeError: fraction must have unit denominator.
How can I approximate $eq = \dfrac{c_0 + c_1x}{c_2 + c_3x}$ where $c_0, c_1, c_2, c_3$ becomes some decimals?
I am aware that $\dfrac{c_0 + c_1x}{c_2 + c_3x}$ is not a polynomial however I do not know what it is.</p>
https://ask.sagemath.org/question/43158/numerical-approximation-of-coefficients-in-fractions/?answer=43159#post-id-43159The result of `expr.polynomial(RR)` is a polynomial ring element. Dividing two polynomials gives an element of the fraction field of the polynomial ring (which are called rational functions). You can do e.g.
sage: expr = (pi + e*x)/(e + pi*x)
sage: expr.numerator().polynomial(RR) / expr.denominator().polynomial(RR)
(2.71828182845905*x + 3.14159265358979)/(3.14159265358979*x + 2.71828182845905)
Better yet, you can construct the fraction field yourself so you can use conversion:
sage: K = FractionField(PolynomialRing(RR, 'x'))
sage: K(expr)
(2.71828182845905*x + 3.14159265358979)/(3.14159265358979*x + 2.71828182845905)Thu, 26 Jul 2018 09:56:33 +0200https://ask.sagemath.org/question/43158/numerical-approximation-of-coefficients-in-fractions/?answer=43159#post-id-43159