Effacer les filtres
Effacer les filtres

Extract num and den in symbolic expression.

19 vues (au cours des 30 derniers jours)
Bruce Taylor
Bruce Taylor le 24 Juil 2019
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

Réponse acceptée

Star Strider
Star Strider le 24 Juil 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 commentaires
Star Strider
Star Strider le 24 Juil 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 le 25 Juil 2019
Star Strider is correct, MATLAB transfer functions, tf() and ss(), cannot support symbolic expressions.

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 24 Juil 2019

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by