Why won't the tf command work for my function?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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)
0 commentaires
Réponses (1)
Walter Roberson
le 4 Déc 2022
Modifié(e) : Walter Roberson
le 4 Déc 2022
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)]
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( double(subs(num2s,s,1)), double(subs(den2s,s,1)))
3 commentaires
Walter Roberson
le 4 Déc 2022
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))
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!