# nlcontrol

### Stephen vanHook (view profile)

Nonlinear algorithm for controlling dynamical systems, particularly where linear methods fail.

P=ctrseq(XX,U,xgoal, ugoal, m,mc,nd,case);
```function P=ctrseq(XX,U,xgoal, ugoal, m,mc,nd,case);
% [StateTransitionVector]=CTRSEQ(X,U, XGOAL, UGOAL, m,mc,nd,case,);
% Function CTRSEQ rearranges vectors of N applied perturbations U(:,1...N)
% and vectors of the system responses X(:,1....N) into the vectors of
% the StateTransitions to the nearest steady state.
% XGOAL, UGOAL defines the goal dynamics
% m-is the dimensionality of the state vector, mc-is the length
% of the controlling sequence, nd-is the delay between perturbation
% and its effect on the system. Usually mc=m.
% case - is the goal dynamics type

% Valery Petrov, CNLD 10-29-96
% e-mail: Val.Petrov@chaos.ph.utexas.edu

% Copyright (c) The University of Texas at Austin

% Calculate indices for delayed observations and perturbations
% m-length of the embedding sequence
% mc-length of the controlling sequence
% nd-delay between perturbation application and its effect on the system
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Direct specification of the x and u

if (case==0)
indxp=(0:m-1); 	% X indeces for the present state
indup=(0:m+nd-2);	% U indeces for the present state

DX=XX;		        %Create differences

DDX=delsig2(DX,[indxp]);
GDX=delsig2(xgoal*ones(1,m+1),1:m);
XP=[GDX' DDX(:,size(DDX,2))'];
P=[XP'];

if(m + nd > 1)
DDU=delsig2(U,[indup]);
GDU=delsig2(ugoal*ones(1,m),1:(m-1));
UP=[GDU' DDU(:,size(DDU,2))'];

P=[XP';UP'];
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% X-specified differentially, U -directly

if (case==1)
indxp=(0:m-1); 	% X indices for the past state
indup=(0:m+nd-1);% U indeces for the past state

DX=diff(XX')';		%Create differences

DDX=delsig2(DX,[indxp]);
DDU=delsig2(U,[indup]);

GDX=delsig2(0*ones(size(xgoal))*ones(1,m+1),1:m);
GDU=delsig2(ugoal*ones(1,m+1),1:m);

XP=[GDX' DDX(:,size(DDX,2))'];
UP=[GDU' DDU(:,size(DDU,2))'];
P=[XP';UP'];

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Direct specification of x, differential  u

if (case==2)

indxp=(0:m); 	% X indices for the past state
indup=(0:m+nd-2);% U indices for the past state

DX=XX;		        %Create differences
DU=diff(U')';		        %Create differences

DDX=delsig2(DX,[indxp]);
GDX=delsig2(xgoal*ones(1,m+2),1:m+1);
XP=[GDX' DDX(:,size(DDX,2))'];
P=[XP'];

if (m + nd > 1)
DDU=delsig2(DU,[indup]);
GDU=delsig2(0*ones(size(ugoal))*ones(1,m),1:(m-1));
UP=[GDU' DDU(:,size(DDU,2))'];
P=[P; UP'];
end

end

```