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

조회 수: 14 (최근 30일)
Cassie Thompson
Cassie Thompson 2022년 12월 4일
댓글: Walter Roberson 2022년 12월 4일
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일
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일
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))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by