Why won't the tf command work for my function?

I'm currently trying to make a transfer function which should look something like this when completed:
and I have been given these parameters
k=kl=(2*pi*nf)^2 (where nf=1 or 1000) mp=3.5 m=1.25*mp and Ig=1 l=0.6
However, the tf command will not allow me to put zeros at the end to make my last term in the den s^2. Everytime I run it, it will get to the line where I try to use the tf command and run forever. Here is my code:
fnl=1; kl=(2*pi*fnl)^2;
num2=[(-2*l*mp*m^2-2*l*mp^2*m)*s^2 0*s -2*l*mp*(m*k+mp*k-k)]
den2=[m*(m+mp)^2*(4*Ig+l^2*mp)*s^4 0*s^3 k*(m+mp)^2*(4*Ig+l^2*mp)*s^2 0*s 0]
num2s=subs(num2,[k mp m Ig l],[kl 3.5 1.25*3.5 1 0.6])
den2s=subs(den2,[k mp m Ig l],[kl 3.5 1.25*3.5 1 0.6])
TF_theta=tf(num2s,den2s)

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 12 月 4 日
編集済み: Walter Roberson 2022 年 12 月 4 日

1 投票

tf() can never accept symbolic values.
Also the arrays you constructed included s to powers, but tf expects just vectors of numeric coefficients.
syms k mp m Ig l s
nf = 1;
kl = (2*pi*nf)^2;
%mp = 3.5;
%m = 1.25 * mp;
%Ig = 1;
%l=0.6;
syms s
fnl=1; kl=(2*pi*fnl)^2;
num2=[(-2*l*mp*m^2-2*l*mp^2*m)*s^2 0*s -2*l*mp*(m*k+mp*k-k)]
num2 = 
den2=[m*(m+mp)^2*(4*Ig+l^2*mp)*s^4 0*s^3 k*(m+mp)^2*(4*Ig+l^2*mp)*s^2 0*s 0]
den2 = 
num2s=subs(num2,[k mp m Ig l],[kl 3.5 1.25*3.5 1 0.6])
num2s = 
den2s=subs(den2,[k mp m Ig l],[kl 3.5 1.25*3.5 1 0.6])
den2s = 
TF_theta = tf( double(subs(num2s,s,1)), double(subs(den2s,s,1)))
TF_theta = -144.7 s^2 - 1140 ----------------------- 1427 s^4 + 1.288e04 s^2 Continuous-time transfer function.

3 件のコメント

Cassie Thompson
Cassie Thompson 2022 年 12 月 4 日
編集済み: Cassie Thompson 2022 年 12 月 4 日
Thank you so much for the speedy answer, what are you doing with the double and subs functions which are embedded in the tf? does that convert the symbolic to numeric?
Also, what does the ",s,1" at the end tell it?
Cassie Thompson
Cassie Thompson 2022 年 12 月 4 日
I'm sorry, I just realized whats going on with all that, Thank you again so much for the help.
Walter Roberson
Walter Roberson 2022 年 12 月 4 日
For other people who might be reading:
if you have an expression involving constant times a variable to a power, and you want to extract the constant without the variable, then one of the easiest ways is to substitute 1 for the variable -- 1 to any power gives 1, so effectively the variable vanishes. Then you double() the result because tf() needs double.
In the restricted case that the expression is a scalar, you could use double(coeffs(num2s)) instead of double(subs(num2s),s,1) . However that will not work for vectors of values, so you would need to use somethng like arrayfun(@(X) double(coeffs(X)), num2s) which is longer than just double(subs(num2s,s,1))

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

リリース

R2022b

質問済み:

2022 年 12 月 4 日

コメント済み:

2022 年 12 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by