简体   繁体   中英

Sympy expression as ratio of polynomials

What is the best way to get sympy to rewrite an expression as a ratio of polynomials?

I'm working out the transfer function for a circuit, and would like to determine its poles and zeros which will require factoring the numerator and denominator of the transfer function. As I calculate, I'd like to keep the intermediate results expressed as a ratio of polynomials rather than the 1/1/1/1/1/x form that is naturally the result of parallel impedances.

I could write a function that keeps taking as_numer_denom() at each step and returns the ratio, but that seems cumbersome.

Is there a natural way to do this?

Perhaps you can use normal at each step?

>>> (1/1/1/1/x + 2/(1+1/x)).normal()
(2*x**2 + x + 1)/(x*(x + 1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM