Reputation: 2329
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?
Upvotes: 2
Views: 706
Reputation: 19077
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))
Upvotes: 3