Extract num and den in symbolic expression.

19 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2019-7-24
Use the sym2poly funciton:
syms a b c s
num = 1*s^2 + 2*s + 3;
n = sym2poly(num)
n =
1 2 3
  3 个评论
Star Strider
Star Strider 2019-7-24
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 2019-7-25
Star Strider is correct, MATLAB transfer functions, tf() and ss(), cannot support symbolic expressions.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2019-7-24

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by