0

Lets say I have an expression like this in SymPy:

s = sp.symbols('s')
Y = s**3 + 3*s**2 + 2*s
Y

enter image description here

Now I would like to get a "list of orders" of that expression. here is an example of what I want to achieve: I would like to create a tf() object. Where tf() is a function like in Matlab that takes two lists, a denominator, and a numerator, and creates a transfer function out of them:

tf([1], [1, 3, 2, 0])

I would like to extract those two lists from my SymPy expression to use them like in that tf() function. How can I do that?

John
  • 871
  • 2
  • 9
  • 20

1 Answers1

2

After transforming an expression into a polynomial all_coeffs() does the job:

sp.Poly(s**3 + 3*s**2 + 2*s, s).all_coeffs()
[1, 3, 2, 0]
John
  • 871
  • 2
  • 9
  • 20