function [ParMa,VarMa]=zust_aup1(T,Tel,VTM,VTF,VTL)
%ZUST_AUP1 state control structure 1; 3 coefficients; parameter variation; 
%          [ParMa(,VarMa)] =zust_aup1(T,Tel(,VTM,VTF,VTL))
% calculation of the coefficients of a discontinuous state control structure,
% example by Brandenburg: at 35(1987)7, pp. 275/83; using BOD;  T=sampling time;
% *** quod vide: variation of motor, spring and load time constant: TM, TF, TL ***
% (,VTM,VTF,VTL):  optionally external vectorial definition >>>parameter ranges<<<
%                  regarding these three time constants; when indicated single
%                  elements and >>>n o n - l i n e a r<<< definition possible!
% ParMa:       parameter matrix containing calculated feed back coefficientes
%              1. row: Kd;    2. row: Km;    3. row: Kn;
% (,VarMa):    matrix of variables containing associated time constants
%              1. row: TM;  2. row: TF;  3. row: TL  - for diagrams
% Hint: In case of menu driven input of a parameter range set minimum==maximum
%       to >>>a v o i d<<< parameter variation if indicated.

% KEY WORDS: Discontinuous Magnitude Optimum, BOD; state control structure;
%		     parameter variation; motor, spring, load time constant

%  ***** preconditions: existence of functions zust_au1.m, zust_aug1.m ****

%  Copyright (c) 1997-2023. All Rights Reserved.
%                     Dr. Gert-Helge Geitner, TU Dresden,
%                     https://wwwpub.zih.tu-dresden.de/~geitner/ae_1_0e.htm
%  Reference regarding Discontinuous Magnitude Optimum: Geitner, G.-H.:
%                     Entwurf digitaler Regler fuer elektrische Antriebe.
%                     publisher: VDE-Verlag GmbH Berlin und Offenbach 1995
%                     ISBN 3-8007-1847-2

if nargin~=2&nargin~=5 error('Incorrect number of input arguments!'); end;
if length(T)~=1|length(Tel)~=1
   error('Incorrect dimension regarding first two input values!'); end
if nargin==5  %loop counter calculations
   SZM=length(VTM); SZF=length(VTF); SZL=length(VTL);
else
   VTM=input('Motor time constant / ms [minimum maximum]=');
   VTF=input('Spring time constant / ms [minimum maximum]=');
   VTL=input('Load time constant / ms  [minimum maximum]=');
   if length(VTL)~=2|length(VTF)~=2|length(VTM)~=2
             error('Number of values incorrect!'); end;
   if VTM(1)>VTM(2)|VTF(1)>VTF(2)|VTL(1)>VTL(2) error('min/max interchanged!');end;
   if VTM(1)<0|VTM(2)<0|VTF(1)<0|VTF(2)<0|VTL(1)<0|VTL(2)<0
				error('Illegal negative values detected!'); end;
   if VTM(1)==VTM(2) SZM=1; VTM=VTM*[1 0]';
   else
      ans=input('Step size of TM: standard 50% (any) / input(0) ? =');
      if isempty(ans)|ans~=0 swM=50; 
      else swM=input('Input step size of TM in % =');
	        if isempty(swM)|swM<=0|swM>100 error('Incorrect value!'); end
      end
      SZM=ceil(100/swM)+1;          %loop counter
      dTM=(VTM(2)-VTM(1))*swM/100;  %range of definition
      for i=1:SZM-1 VTM(i+1)=VTM(1)+i*dTM; end
   end
   if VTF(1)==VTF(2) SZF=1; VTF=VTF*[1 0]';
   else
      ans=input('Step size of  TF: standard 50% (any) / input(0) ? =');
      if isempty(ans)|ans~=0 swF=50;
      else swF=input('Input step size of TF in % =');
	        if isempty(swF)|swF<=0|swF>100 error('Incorrect value!'); end
      end
      SZF=ceil(100/swF)+1;          %loop counter
      dTF=(VTF(2)-VTF(1))*swF/100;  %range of definition
      for i=1:SZF-1 VTF(i+1)=VTF(1)+i*dTF; end
   end
   if VTL(1)==VTL(2) SZL=1; VTL=VTL*[1 0]';
   else
      ans=input('Step size of  TL: standard 50% (any) / input(0) ? =');
      if isempty(ans)|ans~=0 swL=50;
      else swL=input('Input step size of TL in % =');
	        if isempty(swL)|swL<=0|swL>100 error('Incorrect value!'); end
      end
      SZL=ceil(100/swL)+1;          %loop counter
      dTL=(VTL(2)-VTL(1))*swL/100;  %range of definition
      for i=1:SZL-1 VTL(i+1)=VTL(1)+i*dTL; end
   end
end
disp('Number of parameter combinations to be computed ='); disp(SZM*SZF*SZL);
ans=input('Start (any) / function abort (0) ? =');
if isempty(ans)|ans~=0 else error('Function aborted!'); end
ii=0;
for i=1:SZM
    for j=1:SZF
	     for k=1:SZL
            ii=ii+1; disp(['Calculation number: ' num2str(ii)])
	         erg=zust_au1(T,Tel,VTM(i),VTF(j),VTL(k));
	         ParMa(1,ii)=erg(1); ParMa(2,ii)=erg(2); ParMa(3,ii)=erg(3);
	         VarMa(1,ii)=VTM(i); VarMa(2,ii)=VTF(j); VarMa(3,ii)=VTL(k);
	     end
    end
end
