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

132 visualizaciones (últimos 30 días)
Brian Kalinowski
Brian Kalinowski el 3 de Dic. de 2016
Editada: Walter Roberson el 21 de Dic. de 2021
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!

Respuestas (3)

Andrei Bobrov
Andrei Bobrov el 4 de Dic. de 2016
sys=tf(1,[1 2 2]);
s = tf('s');
ctr=4+(3/s);
e_cl=feedback(1,sys*ctr)

bio lim
bio lim el 3 de Dic. de 2016
Editada: bio lim el 3 de Dic. de 2016
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 el 4 de Dic. de 2016
Editada: Walter Roberson el 21 de Dic. de 2021

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by