Extracting a symbolic variable (rearranging symbolic equation)
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to extract a variable (a gain in this case) from a symbolic expression.
The code for generating the symbolic expression is:
%Misc Intializations
syms K2 K1 s
%Plant characteristics
T=.1;
Wn=2.5;
z=.3;
%Controller
C=K2*expand((s+2)^2)/expand((s+10)*(s+100));
%Actuator
A=10/(s+10);
%Plant
P=K1*(T*s+1)/(s^2+2*Wn*z*s+Wn^2);
%Closed Loop TF
YcY=C*A*P/(1+C*A*P);
%Characteristic
KLs=expand(C*A*P);
Where the expression I want to work with is KLs, which in its current form is:
4*K1*K2*s^3 + 56*K1*K2*s^2 + 176*K1*K2*s + 160*K1*K2
----------------------------------------------------------
4*s^5 + 486*s^4 + 9145*s^3 + 55600*s^2 + 112500*s + 250000
I want to bring K1 and K2 outside the expression (make them into gains for the transfer function). In this case it is relatively simple to do so using coeffs however I need a method that will work when K1,K2...Kn can be in the numerator or the denominator.
Not sure if what I am asking is clear but thank you in advance for help!
1 个评论
Mech Princess
2012-7-20
Did you find a solution for this? I am trying to do something similar for another application. I am trying to have K1 on one side of equation and have all variables on the other side. is that possible? Thanks
回答(2 个)
Aider
2020-10-13
编辑:Aider
2020-10-13
Try this, create a dummy variable "x" so you can use the collect command. Then substitute x by K1*K2
%Misc Intializations
syms K2 K1 s x
%Plant characteristics
T=.1;
Wn=2.5;
z=.3;
%Controller
C=K2*expand((s+2)^2)/expand((s+10)*(s+100));
%Actuator
A=10/(s+10);
%Plant
P=K1*(T*s+1)/(s^2+2*Wn*z*s+Wn^2);
%Closed Loop TF
YcY=C*A*P/(1+C*A*P);
%Characteristic
KLs=expand(C*A*P);
subs(collect(subs(KLs,K1*K2,x),x),x,K1*K2)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!