function[Kc]=Kc_error(g,k) %Kc=Kc_error(g,k) %Assume that: %If tf have no ideal integral, k=Kp %If tf have 1 ideal integral, k=Kv %If tf have 2 ideal integral, k=Ka %-------------------------------------------------------|% %|(C)2005 Bui Trung Hieu |% %|Website: www.khvt.com |% %|Email: matlab@khvt.com |% %-------------------------------------------------------|% if (nargin==2) if(length(k)==1) sw=length(find(pole(g)==0)); if (sw==0) %This code to find Kc from Kp a=dcgain(g); Kc=double(k/a); elseif (sw==1) %This code to find Kc from Kv s=tf('s'); a=dcgain(minreal(s*g)); Kc=double(k/a); elseif (sw==2) %This code to find Kc from Ka s=tf('s'); a=dcgain(minreal(s^2*g)); Kc=double(k/a); end else Kc=[]; error('???Ban nhap sai so chieu cua k!!!'); end else Kc=[]; error('???Xem help de co them thong tin!!!'); end