www.pudn.com > Closid30.rar > Cltpc.m, change:1997-06-07,size:1953b


function [sc,nsc]=cltpc(s,ks,ns,nks); 
% [sn,nsc]=cltpc(s,ks,ns,nks); 
% 
% Construct the closed-loop transfer function T(P,C)  
% for a plant [s,ns] and a controller [ks,nks]. 
% 
% inputs   [S,NS]      system description 
%          [KS,NKS]    applied controller  
% optional inputs: ns, nks (default=1). 
% 
% outputs  [SC,NSC]    resulting closed loop     
%      
% 
% T(P,C) = | P |       -1  
%          | I | (I+CP)   [C I] 
% 
 
% Functions called: clsplit 
 
% 24-10-1990 (originally named tpc.m written by Peter Bongers 
% and revised 01-11-1996). 
% (c) Peter Bongers, Paul Van den Hof 
% Mechanical Engineering Systems and Control Group 
% Delft University of Technology 
% Last update: 07-06-1997. 
 
%ERROR CHECKS 
if nargin==0, 
  error('No input arguments present; type help cltpc for info!'); 
elseif ((nargin<2)|(nargin>4)), 
  error('Number of input arguments in cltpc is not correct'); 
end 
 
[ns1,ns2]=size(s); 
[nks1,nks2]=size(ks); 
if nargin==2, 
  if ((ns1~=ns2)|(nks1~=nks2)), 
   error('The dimensions of plant and/or controller have to be specified'); 
  end; 
  ns=ns1-1; 
  nks=nks1-1; 
elseif nargin==3, 
  if nks1~=nks2, 
   error('The controller dimension has to be specified'); 
  elseif ((ns>=min(ns1,ns2))|(ns<=0)), 
   error('The plant dimension is not correct'); 
  else 
   nks=nks1-1; 
  end; 
elseif nargin==4, 
  if ((ns>=min(ns1,ns2))|(ns<=0)|(nks>=min(nks1,nks2))|(nks<=0)), 
    error('The dimensions of plant and/or controller are not correct'); 
  end; 
end; 
 
[a,b,c,d]=clsplit(s,ns); 
[e,f,g,h]=clsplit(ks,nks); 
[nout,ninp]=size(d); 
l=inv(eye(ninp)+h*d); 
k=inv(eye(nout)+d*h); 
sc=[a-b*l*h*c    b*l*g       b*l*h       b*l;... 
   -f*k*c        e-f*k*d*g   f-f*k*d*h  -f*k*d;... 
    k*c          k*d*g       k*d*h       k*d;... 
   -l*h*c        l*g         l*h         l]; 
nsc=ns(1,1)+nks(1,1); 
 
ew=max(abs(eig(sc(1:nsc,1:nsc)))); 
if (ew > 1), 
  disp('WARNING CLOSED LOOP UNSTABLE'); 
end