Clear Filters
Clear Filters

Extract num and den in symbolic expression.

19 views (last 30 days)
The 'tf' function in Control Systems needs numerator and denometer in a vector of decreasing powers of s.
For example a numerator of a*s^2 + b*s + c needs to be num= [a b c];. I have been cutting and pasting the necessary coefficients
but to do this I have to pause my program. Is there a way to extract the appropriate vector(s) programatically?
Thanks,
Bruce Taylor

Accepted Answer

Star Strider
Star Strider on 24 Jul 2019
Use the sym2poly funciton:
syms a b c s
num = 1*s^2 + 2*s + 3;
n = sym2poly(num)
n =
1 2 3
  3 Comments
Star Strider
Star Strider on 24 Jul 2019
I thought you had already isolated the numerator and denominator.
Try this:
syms a b c d e f g s
sys=(a*s^2+b*s+c)/(d*s^3+e*s^2+f*s+g)
sys = subs(sys,{a,b,c,d,e,f,g},{3,6,8,1,2,9,5})
[np,dp] = numden(sys)
n = sym2poly(np)
d = sym2poly(dp)
producing:
sys =
(a*s^2 + b*s + c)/(d*s^3 + e*s^2 + f*s + g)
sys =
(3*s^2 + 6*s + 8)/(s^3 + 2*s^2 + 9*s + 5)
np =
3*s^2 + 6*s + 8
dp =
s^3 + 2*s^2 + 9*s + 5
n =
3 6 8
d =
1 2 9 5
Note that this will only work with numeric coefficients. It will error with symbolic coefficients.
Walter Roberson
Walter Roberson on 25 Jul 2019
Star Strider is correct, MATLAB transfer functions, tf() and ss(), cannot support symbolic expressions.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 24 Jul 2019

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!