How can I incorporate the "s" symbolic variable in multiplication?

114 ビュー (過去 30 日間)
Brian Kalinowski
Brian Kalinowski 2016 年 12 月 3 日
編集済み: Walter Roberson 2021 年 12 月 21 日
Okay so this is a simple code for a simple closed loop control system:
sys=tf(1,[1 2 2]);
syms s
ctr=4+(3/s);
e_cl=feedback(1,sys*ctr);
u_cl=feedback(ctr,sys);
y_cl=feedback(sys*ctr,1);
step(e_cl,'b',u_cl, 'r',y_cl, 'g')
[num,den]=tfdata(y_cl,'v');
roots(den);
stepinfo(y_cl);
When I run it, it gives me an error for the e_cl equation saying: "Invalid operand. Variables of type "sym" cannot be combined with other models."
This makes sense to me, since "s" is symbolic you cannot multiply numbers. Any idea how I can make this work? s is the laplace variable so making it a vector wouldn't work with finding the step responses. I need to somehow make "ctr=4+3/s" into a function where I can multiply it by sys. Thanks!

回答 (3 件)

Andrei Bobrov
Andrei Bobrov 2016 年 12 月 4 日
sys=tf(1,[1 2 2]);
s = tf('s');
ctr=4+(3/s);
e_cl=feedback(1,sys*ctr)

bio lim
bio lim 2016 年 12 月 3 日
編集済み: bio lim 2016 年 12 月 3 日
Defining a symbolic variable s is different than the s = jw in your transfer function. I believe, if you write a transfer function with syms s, MATLAB doesn't assume it's a transfer function.
Now you might ask, since the transfer function is a ratio of the input and the output, why it shouldn't work? the built-in function tf contains more information that can be used in different control system commands in MATLAB. It has other properties associated with it, not only just the ratio.
To solve your problem, simply write the transfer function of your controller as:
ctr = tf([4 3], [1 0]);
and it should give you your results.

Walter Roberson
Walter Roberson 2016 年 12 月 4 日
編集済み: Walter Roberson 2021 年 12 月 21 日

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by