Filter löschen
Filter löschen

Extract num and den in symbolic expression.

19 Ansichten (letzte 30 Tage)
Bruce Taylor
Bruce Taylor am 24 Jul. 2019
Bearbeitet: Walter Roberson am 26 Jul. 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

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 24 Jul. 2019

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by