ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 16 Apr 2013 04:22:06 -0500A combination of commands partial_fraction(x) and coefficient(x,n)https://ask.sagemath.org/question/10016/a-combination-of-commands-partial_fractionx-and-coefficientxn/I have asked this question over [here](http://stackoverflow.com/questions/15962495/a-combination-of-commands-partial-fractionx-and-coefficientx-n) but I got no answer.
I am trying to do some iterative calculations where each time SAGE constructs a fraction and lists the coefficients in the partial fraction decomposition of that fraction. I realized that doing everything symbolically, SAGE wants to keep everything as integer as possible. So what it does is to simplify fractions like `1/(x-3/2)` as `2/(2x-3)` and then when I ask for
> f.coefficient(x-3/2,-1)
it returns `0`, while I expect it to return `1`.
I have tried to solve things numerically, but there are two problems:
1. The errors get really big after each iteration
2. It takes much much longer to calculate it
Any suggestions to get SAGE to solve this is greatly appreciated.Fri, 12 Apr 2013 12:00:11 -0500https://ask.sagemath.org/question/10016/a-combination-of-commands-partial_fractionx-and-coefficientxn/Answer by ppurka for <p>I have asked this question over <a href="http://stackoverflow.com/questions/15962495/a-combination-of-commands-partial-fractionx-and-coefficientx-n">here</a> but I got no answer. </p>
<p>I am trying to do some iterative calculations where each time SAGE constructs a fraction and lists the coefficients in the partial fraction decomposition of that fraction. I realized that doing everything symbolically, SAGE wants to keep everything as integer as possible. So what it does is to simplify fractions like <code>1/(x-3/2)</code> as <code>2/(2x-3)</code> and then when I ask for </p>
<blockquote>
<p>f.coefficient(x-3/2,-1) </p>
</blockquote>
<p>it returns <code>0</code>, while I expect it to return <code>1</code>. </p>
<p>I have tried to solve things numerically, but there are two problems:</p>
<ol>
<li>The errors get really big after each iteration</li>
<li>It takes much much longer to calculate it</li>
</ol>
<p>Any suggestions to get SAGE to solve this is greatly appreciated.</p>
https://ask.sagemath.org/question/10016/a-combination-of-commands-partial_fractionx-and-coefficientxn/?answer=14775#post-id-14775You can do something like this
sage: f = 1/(x-3/2)
sage: g = f.denominator()
sage: f.coeff(f.denominator(), -1) / g.leading_coeff(x)
1Fri, 12 Apr 2013 17:30:23 -0500https://ask.sagemath.org/question/10016/a-combination-of-commands-partial_fractionx-and-coefficientxn/?answer=14775#post-id-14775Comment by k1 for <p>You can do something like this</p>
<pre><code>sage: f = 1/(x-3/2)
sage: g = f.denominator()
sage: f.coeff(f.denominator(), -1) / g.leading_coeff(x)
1
</code></pre>
https://ask.sagemath.org/question/10016/a-combination-of-commands-partial_fractionx-and-coefficientxn/?comment=17885#post-id-17885Thanks, but the problem is that after partial fraction decomposition I have a bunch of fractions added to each other.Tue, 16 Apr 2013 04:22:06 -0500https://ask.sagemath.org/question/10016/a-combination-of-commands-partial_fractionx-and-coefficientxn/?comment=17885#post-id-17885