function q=zust_bran_2gl(x,a,b,c,d,erg,BRF,RFV,TAZ,iS)
%ZUST_BRAN_2GL supporting file zust_bran_2.m - structure in z-domain
%        q=zust_bran_2gl(x,a,b,c,d,erg,BRF,RFV,TAZ,iS)
% **** ATTENTION: calling by zust_bran_2 only ==> automated bran_2;
% ****          fsolve optimization equations on the basis of an example
% ****          according Brandenburg, BUT HERE 4 state feed backs

% KEY WORD: supporting file

%  Copyright (c) 1997-2009. All Rights Reserved.
%                     Dr. Gert-Helge Geitner; TU Dresden, Fak. ET,
%                     Elektrotechnisches Institut (ETI); Mommsenstr. 13;
%                     D-01062 Dresden, Germany;
%                     http://eeiwzg.et.tu-dresden.de/ae2_files/ae_1.htm

BME=[9 9 9 ; 9 9 9 ; 9 0 9 ; 0 0 9];
BMA=[1 1 1 ; 2 4 2 ; 4 0 3 ; 0 0 4];     % columns !!!
% definition of blocks for controller coefficients
  q=zeros(TAZ,1); % preparation of q(ii) calculation using fsolve
knr=length(erg);  % number of results already available
KZV=erg;	  % coefficients combined as numerator vector
KZV(4)=0;	  % set remaining coefficients zero
for i=1:TAZ
    knr=knr+1; KZV(knr)=x(i); % storage of fsolve extensions
end
n002=KZV(RFV(1)); d002=1;     % K1
n003=KZV(RFV(2)); d003=1;     % K2
n004=KZV(RFV(3)); d004=1;     % K3
n005=KZV(RFV(4)); d005=1;     % K4
n006=1          ; d006=1;     % mixing point
% since blkbuild not applicable, nblocks dispensable
% define an unconnected diagonal system
	   s0n=abs('n000'); s0d=abs('d000');
for t=2:6  HUS=fix(t/100); ZEV=fix(t/10); sk=[0 HUS ZEV-HUS*10 t-ZEV*10];
           s1=char(s0n+sk); s2=char(s0d+sk);
           [at,bt,ct,dt]=tf2ss(eval(s1),eval(s2));
           [a,b,c,d]=append(a,b,c,d,at,bt,ct,dt);
end;       %  !!!Thus algorithm prepared for three ASCII positions (0...9)!!!
qq=[1  9  0  0  0
    2  9  0  0  0
    3  9  0  0  0
    4  9  0  0  0
    5  1  0  0  0
    6  2  0  0  0
    7  3  0  0  0
    8  4  0  0  0
    9 -5 -6 -7 -8];
 [ac,bc,cc,dc]=connect(a,b,c,d,qq,BME(iS,BRF),BMA(iS,BRF));
 [acm,bcm,ccm,dcm]=minreal(ac,bc,cc,dc);  %implicitly necessary !!!
 [a,b]=ss2tf(acm,bcm,ccm,dcm);
%check of computability
  oz=length(a); on=length(b);   % order of numerator and denominator
  o=max(oz,on);			% protect in case of denominator polynomial approximations
  if oz>on b(oz)=0; elseif on>oz a(on)=0; end
  Z=TAZ;			% K Matrix: number of rows
  S=o-1;			% K Matrix: number of columns
  if TAZ>=o disp('Warning: order<number_of_unknown_quantities!')
     a(TAZ+1)=0; b(TAZ+1)=0; o=TAZ+1;
  end
%K Matrix calculation of columns=S and rows=Z
for i=1:Z
 for j=1:S
  if     i==1         K(i,j)=j^2;
  else   if j==1      K(i,j)=0;
	 elseif  j==2 K(i,j)=K(i,j-1)+K(i-1,j-1);
	 elseif  j==3 K(i,j)=K(i,j-1)+K(i,j-2)+K(i-1,j-1)+K(i-1,j-2);
	 else         K(i,j)=K(i,j-1)+K(i,j-2)-K(i,j-3)+K(i-1,j-1)+K(i-1,j-2);
end; end; end; end
for ii=1:TAZ
    for i=ii:(o-1), x=0;
        for j=1:(o-i)
            x = x + a(j) * a(j+i) - b(j) * b(j+i);  end
        q(ii) = q(ii) + x * K(ii,i);  end; end
