If you replace the coefficients with floating point numbers, you can use full=True and get an answer with floats (although they aren't fully simplified for some reason, so you may want to use apart_list() instead). I'm not sure if it is possible to get an answer with just the real roots, so that there are no complex numbers added.
Aaron Meurer On Mon, Aug 10, 2020 at 1:53 PM Mikhael Myara <[email protected]> wrote: > Thanks a lot Aaron. > However : for my usage, an approximate root would be sufficient. Is there > a way to allow this in Sympy ? > Thanks again, > Mikhaël > > Le lundi 10 août 2020 20:48:04 UTC+2, Aaron Meurer a écrit : >> >> The roots are the key difference. The second polynomial has a rational >> root, -1, meaning it can be split out in a partial fraction decomposition. >> If you don't call evalf() on the roots you can also see that the roots of >> the first polynomial are more complicated, because they are coming from the >> general cubic formula. You can also see the difference in the two if you >> call factor(). >> >> >>> factor(s**3+s**2+5*s+4) >> s**3 + s**2 + 5*s + 4 >> >>> factor(s**3+2*s**2+5*s+4) >> (s + 1)*(s**2 + s + 4) >> >> The first polynomial is irreducible over rationals, but the second >> factors. So if you do a partial fraction decomposition, it will not split >> because apart() only decomposes over rational numbers by default. If you >> want a full decomposition over all the roots, you can use something like >> apart(1/(s**3+s**2+5*s+4), full=True).doit(). >> >> Note that it's not uncommon for polynomials to work like this, where if >> you change a coefficient it changes the behavior of it. That's because it's >> easy for a polynomial to have a rational root with one coefficient but not >> with another close coefficient, like in this case. >> >> Aaron Meurer >> >> On Mon, Aug 10, 2020 at 2:29 AM Mikhael Myara <[email protected]> >> wrote: >> >>> Dear all, >>> >>> I don't know if my problem is with the knowledge of fractionnal >>> decomposition itself or with symPy's implementation. >>> >>> I start with the following code : >>> >>> import sympy as sp >>> sp.var('s') >>> >>> >>> Hstab = 1/(s**3+s**2+5*s+4) >>> Hstab = sp.apart(Hstab) >>> display(Hstab) >>> >>> >>> The result is : >>> >>> [image: Capture d’écran 2020-08-10 à 10.18.18.png] >>> Now I check another similar expression : >>> >>> Hstab2 = 1/(s**3 + 2*s**2 + 5*s + 4) >>> Hstab2 = sp.apart(Hstab2,s) >>> display(Hstab2) >>> >>> and I get : >>> >>> [image: Capture d’écran 2020-08-10 à 10.21.14.png] >>> >>> >>> >>> >>> If now I check for the roots of the denominator for each case : >>> >>> >>> print("\n\nFirst case :") >>> P1=(1/Hstab).simplify() >>> display(P1) >>> for sol in sp.solve(P1,s): >>> display(sol.evalf()) >>> >>> >>> print("\n\nSecond case :") >>> P2=(1/Hstab2).simplify() >>> display(P2) >>> for sol in sp.solve(P2,s): >>> display(sol.evalf()) >>> >>> I get : >>> >>> [image: Capture d’écran 2020-08-10 à 10.26.18.png] >>> Which is very similar except that the real root of the first case is not >>> ass simple as the one of the second case. So I do not understand as I can't >>> see any mathematical impossibility, the two cases are very close. >>> Is there a way to reach the fractional decomposition for the first case ? >>> >>> Thanks a lot, >>> Mike >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "sympy" 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/sympy/4ccc519f-8a28-4478-bc2e-adbc302a9647o%40googlegroups.com >>> <https://groups.google.com/d/msgid/sympy/4ccc519f-8a28-4478-bc2e-adbc302a9647o%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- > You received this message because you are subscribed to the Google Groups > "sympy" 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/sympy/b4c883c0-0840-4cd2-b964-cb32a27c8aaao%40googlegroups.com > <https://groups.google.com/d/msgid/sympy/b4c883c0-0840-4cd2-b964-cb32a27c8aaao%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "sympy" 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/sympy/CAKgW%3D6%2BUHNEV-VZ9XonfZxwq8TBuobL%3Dak0maRbP2aWqBQFtow%40mail.gmail.com.
