Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
1

Numerical approximation of coefficients in fractions

asked 6 years ago

Isamu gravatar image

updated 6 years ago

I am aware that for expressions in the type eq=c0+c1x+c2x2... 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=c0+c1xc2+c3x or in any form where it is impossible to express as c0+c1xn 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=c0+c1xc2+c3x where c0,c1,c2,c3 becomes some decimals? I am aware that c0+c1xc2+c3x is not a polynomial however I do not know what it is.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 6 years ago

rburing gravatar image

updated 6 years ago

The 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)
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 6 years ago

Seen: 592 times

Last updated: Jul 26 '18