www.pudn.com > Closid30.rar > CLMKFZ.M, change:1997-06-03,size:4718b


function [F,nf,MC,nm] = clmkfz(Gx,C,nx,nc,option) 
 
% [F,nf,MC,nm] = clmkfz(Gx,C,nx,nc,option) 
% 
% Given a (multivariable) plant model Gx and a controller C that 
% stabilizes Gx, a filter F is constructed according to  
%                              -1 
%              F = [Dc + Gx*Nc]  * [I  -Gx],    
% where (Nc,Dc) is a right coprime factorization (RCF) of C, being 
% read from the input or constructed by the function itself. 
% 
% INPUTS: 
% Gx     : system representation of plant model that is stabilized by C. 
% C      : system representation of controller C, either in system-format 
%          of C itself (default), or in system-format of a RCF col(Dc,Nc) 
%          (option = 'R'). 
% OPTIONAL INPUTS: 
% nx     : state-space dimension of representation of Gx. 
%          Default the SISO situation applies: nx=size(Gx)-1, provided 
%          that Gx is square; 
% nc     : state-space dimension of representation of C. 
%          Default the SISO situation applies: nc=size(C)-1, provided 
%          that C is square; 
% option : use option = 'R' to compute F using the RCF (Nc,Dc) of C which 
%          is specified in C using the DN-format. Default, a normalized 
%          RCF (Nc,Dc) is being computed. 
% OUTPUTS: 
% F      : system representation of filter F 
% nf     : state-space dimension of representation of F (= nc+nx) 
% MC     : RCF of C that is used in construction of F; (in DN-format) 
% nm     : state-space dimension of representation of MC (= nc) 
 
%************************************************************************** 
% 
% (c) P.M.J. Van den Hof, november 1996. 
% Mechanical Engineering Systems and Control Group 
% Delft University of Technology 
 
% file         : clmkfz.m 
% info         : This file is based on the routine makefz.m written by 
%                R.A. de Callafon, june 1996. 
% functions    : clsplit, cldncf 
% last update  : 20 november 1996 
 
%**************************************************************************** 
 
%ERROR CHECKS 
if nargin==0, 
  error('No input arguments present; type help clmkfz for info!'); 
elseif ((nargin<2)|(nargin>5)), 
  error('Number of input arguments is not correct'); 
end 
 
[nx1,nx2]=size(Gx); 
[nc1,nc2]=size(C); 
if nargin==2, 
  if ((nx1~=nx2)|(nc1~=nc2)), 
   error('The dimensions of Gx and/or C have to be specified'); 
  end; 
  nx=nx1-1; 
  nc=nc1-1; 
elseif nargin==3, 
  if nc1~=nc2, 
   error('The dimension of C has to be specified'); 
  elseif ((nx>=min(nx1,nx2))|(nx<=0)), 
   error('The dimension of Gx is not correct'); 
  else 
   nc=nc1-1; 
  end; 
elseif nargin>=4, 
  if ((nx>=min(nx1,nx2))|(nx<=0)|(nc>=min(nc1,nc2))|(nc<=0)), 
    error('The dimension of Gx and/or C is not correct'); 
  end; 
end; 
 
if nargin<5, 
    option=' '; 
end; 
if length(option)==0, 
    option=' '; 
end; 
 
if ~isstr(option), 
    error('Incorrect option: should be the character ''R'''); 
end 
 
if ((option=='r')|(option=='R')), 
    pre_sp=1; 
else 
    if option~=' ', 
        error('Illegal option, should be ''R'''); 
    end 
    pre_sp=0; 
end; 
 
[Am,Bm,Cm,Dm]=clsplit(Gx,nx); 
[nom,nim]=size(Dm); 
 
[a,b,c,d]=clsplit(C,nc); 
if pre_sp==1, 
    [n1,n2]=size(d); 
    nik=n2; 
    nok=n1-nik; 
    if nok<=0, 
        error('Incorrect dimensions, probably C is not a RCF'); 
    end 
else 
    [nok,nik]=size(d); 
end; 
 
 
if (nik~=nom)|(nok~=nim), 
    if pre_sp==0, 
        error('dimensions of controller C and model Gx do not match'); 
    else 
        error('dimensions of RCF C and model Gx do not match'); 
    end 
end 
 
 
if pre_sp==0, 
    disp([' Computing nrcf of controller.']); 
    [MC,nm]=cldncf(C,nc,'R'); 
else 
    disp([' Using specified RCF of controller.']) 
    MC=C; 
    nm=nc; 
end 
 
[a,b,c,d]=clsplit(MC,nm); 
[n1,n2]=size(d); 
ni=n2; 
no=n1-ni; 
if no<=0, 
    error('Incorrect dimensions: illegal RCF'); 
end 
 
Ad=a; 
Bd=b; 
Cd=c(1:ni,:); 
Dd=d(1:ni,:); 
An=a; 
Bn=b; 
Cn=c(ni+1:n1,:); 
Dn=d(ni+1:n1,:); 
 
% Construction of F: 
S=svd(Dd+Dm*Dn); 
if min(S)<=10*eps, 
 disp('Closed loop feedthrough matrix Dd+Dm*Dn cannot be inverted.'); 
 Dd,Dm,Dn 
 error('Cannot compute closed loop matrix for filter F.'); 
end 
Di=inv(Dd+Dm*Dn); 
Af=[Ad-Bd*Di*[Cd+Dm*Cn]         Bd*Di*Cm 
    -Bm*Cn+Bm*Dn*Di*[Cd+Dm*Cn]   Am-Bm*Dn*Di*Cm]; 
n=size(Dn*Di*Dm); 
Bf=[Bd*Di                        -Bd*Di*Dm 
    -Bm*Dn*Di  -Bm*[eye(nim,nim)-Dn*Di*Dm]]; 
Cf=[-Di*[Dm*Cn+Cd] Di*Cm]; 
Df=[Di -Di*Dm]; 
F=[Af Bf;Cf Df];    %F=grp(Af,Bf,Cf,Df,'fz'); 
nf=nm+nx; 
% 
% Check on stability of F: 
index=[]; 
ew=eig(Af); 
index=find(abs(ew)>1); 
if length(index)>=1 
    disp([' WARNING: filter F INTERNALLY unstable!']); 
else 
    disp([' OK, filter F is stable.']); 
end