Getting the denominator and numerator

173 views
Skip to first unread message

Peter Stahlecker

unread,
Mar 20, 2022, 10:46:39 PM3/20/22
to sympy
I get an expression in sympy which looks like f(x) / g(x) when I print it.
Is there any way to get f(x) and g(x) explicitly?
Thanks for any help!

Qijia Liu

unread,
Mar 21, 2022, 12:34:12 AM3/21/22
to sympy
f,g=expr.as_numer_denom()

Peter Stahlecker

unread,
Mar 21, 2022, 3:07:53 AM3/21/22
to sy...@googlegroups.com
Dear Liu,

Thanks for your prompt reply!
I tried as you suggested, where speedx is the expression, whose numerator and denominator I want to get.
I got the error below.
If I do it without ‚sm.‘, I get the error message expr not known.

Thanks for your further help!

AttributeError                            Traceback (most recent call last)
Input In [7], in <module>
     83 print(speedx)
     84 print(speedy)
---> 85 f, g = sm.expr.as_numer_denom(speedx)
     86 print(r, g)
     88 q = [q1, q2, q3]

AttributeError: module 'sympy' has no attribute 'expr'


On Mon 21. Mar 2022 at 10:34 Qijia Liu <liu...@pku.edu.cn> wrote:
f,g=expr.as_numer_denom()

--
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 sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/78730755-ed5c-4490-b4d2-1aa5d72e84f0n%40googlegroups.com.
--
Best regards,

Peter Stahlecker

Peter Stahlecker

unread,
Mar 21, 2022, 5:07:23 AM3/21/22
to sy...@googlegroups.com
I managed to get it.
Thanks a lot for your help!!
Reply all
Reply to author
Forward
0 new messages