Code covered by the BSD License

# Optimal reduced-order discrete-time LQG design

### Gerard Van Willigenburg (view profile)

16 May 2008 (Updated )

Solution of the SDOPE by repeated forward and backward iteration

[osc,endc,conver,bb,nocon,tps,tpst,b,iti]=rocochk...
```% ROCOCHK: Check reduced-order algorithm convergence
%
%          [osc,endc,conver,bb,sigp,sigs,tps,tpst,b,iti]=...
%           rocochk(osc,conver,bb,it,itm,itc,pt,st,...
%                   tpso,tpst,epsl,maxtps,fnam,nx,nc,b,a,cc,iti);
%
% Input/output arguments:
%
% osc    : oscillation flag and divergence counter
% endc   : flag indicating end of iterations
% conver : number of successive converged iterations
% bb     : adjusted numerical damping
% nocon  : flag indicating convergence status
%          0 standard output
%          1 no convergence
% tps    : Trace(pt+st)
% tpst   : array of Trace(pt+st) values
% epsl   : epsilon that determines convergence
% it     : total number of iterations
% iti    : number of iterations after change numerical damping
% itm    : maximum number of iterations
% itc    : plot parameter 1,2 or 3
% tpso   : previous value Trace(pt+st)
% maxtps : Trace(pt+st) > maxtps then divergence
% fnam   : String containing the calling function name
% nx, nc : system and compensator dimension
% b, a   : numerical damping and homotopy parameter
% cc     : flag for automatic adjustment numerical damping

function [osc,endc,conver,bb,nocon,tps,tpst,b,iti]=rocochk...
(osc,conver,bb,it,itm,itc,pt,st,tpso,tpst,epsl,maxtps,fnam,...
plstr,nx,nc,b,a,cc,iti);

% Set a to -1 if a is not in the input list
if nargin<18; a=-1; end;

% No automatic selection of the numerical damping
% if cc is not in the input list
if nargin<19; cc=1; end;

% Set iti=1 if it is not in the input list
% and check whether enough input arguments
% are present for automatic selection of the numerical damping
if nargin<20; iti=1;
if ~cc;
error('oscillation detection requires 19 inputs')
end;
end;

% Compute trace, relative difference and append trace array
tps=trace(pt+st);
tpsr=abs((tpso-tps)/(tps+1e-12));
tpst=[tpst tps];

nocon=0; endc=0;
% Maximum number of iterations exceeded
if it>itm;
disp(' ');
disp(['  ' fnam ' : Maximum number of iterations exceeded']);
endc=1; nocon=1;

% Trace exceeds maximum value
elseif abs(tps)>maxtps | tps < 0;
if ~cc;
b=b+0.5*(1-b); iti=0; nocon=2;
disp(' ');
disp(['  ' fnam ': Divergence'])
disp(['  Numerical damping increased to: ' num2str(b)]);
end;
if cc | b >= 0.995
disp(' ');
disp(['  ' fnam ' : No convergence']);
endc=1; nocon=1;
end

% Convergence count
elseif tpsr<epsl
conver=conver+1;

% Check oscillation and bad convergence
elseif ~cc & rem(iti,100)==0;
[osc]=detosc(osc,tpst,min(round(iti/2),500),min(round(iti/10),100));
if osc>1;
b=b+0.5*(1-b); iti=0; osc=0; nocon=2;
disp(' ');
disp(['  ' fnam ': Bad convergence'])
disp(['  Numerical damping increased to: ' num2str(b)]);
end;
if b >= 0.995
disp(' ');
disp(['  ' fnam ' : No convergence']);
endc=1; nocon=1;
end;

% Nothing special: continu iteration
else; conver=0; end;

% Reduce numerical damping to 90% for final convergence count
if conver==5; bb=0.9*b;

% Six consequtive iterations converged: convergence
elseif conver==6; endc=1;

% Nothing special: apply current numerical damping
else; bb=b; end;

% Display progress computation every itc iterations.
if (itc>0 & rem(it,itc)==0) | (itc~=0 & endc==1)
if a<0; str=['  ' fnam];
else; str=['  ' fnam ' alpha=' num2str(a)]; end
plconv(tpst,tpsr,epsl,endc,str,plstr,nx,nc);
end
```