# nlcontrol

### Stephen vanHook (view profile)

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

[P, T]=idseq(XX,UU,m,mc,nd,case);
```function [P, T]=idseq(XX,UU,m,mc,nd,case);
% [StateTransitionVector, Pert]=IDSEQ(X,U,m,mc,nd,case);
% Function IDSEQ rearranges vectors of N applied perturbations U(:,1...N)
% and vectors of system responses X(:,1....N) into vectors of
% StateTransitions and corresponding perturbations Pert.
% m is the dimensionality of the state vector, mc-is the length
% of the controlling sequence, nd-is the delay between a perturbation
% and its effect on the system. Usually mc=m.
% case - 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

if (case == 0)
indx1=(1:m);          	% X indices for the future state
indu1=(1:m-1)+nd;            	% U indices for the future state
indx2=(mc+m+nd:mc+2*m+nd-1);  % X indices for the past state
indu2=(mc+m+nd:mc+2*m+2*nd-2);% U indices for the past state
indc = mc+m+nd-1;            	% controlling perturbation index

XD=delsig2(XX,[indx1 indx2]);
UD=delsig2(UU,[indu1 indu2]);
UC=delsig2(UU,indc);

% Allign XD and UD, UC vectors, because they were truncated
% by delaysig2

szc=size(UC,2);
szx=size(XD,2);

if (m + nd > 1) %U's are involved
szy=size(UD,2);
sz=min(szx,szy);
XD=XD(:,szx-sz+1:szx);
UD=UD(:,szy-sz+1:szy);
% Mapping is created as F(P)=T;
P=[XD; UD];
else
sz=szx;
XD=XD(:,szx-sz+1:szx);
P=[XD];
end
UC=UC(:,szc-sz+1:szc);
T=UC;

end

if (case == 1)
indx1=(0:m-1);        	% X indices for the future state
indu1=(0:m-1)+nd;            	% U indices for the future state
indx2=(mc+m+nd:mc+2*m+nd-1); 	% X indices for the past state
indu2=(mc+m+nd:mc+2*m+2*nd-1);% U indices for the past state
indc = mc+m+nd-1;            	% controlling perturbation index

XD=delsig2(diff(XX')',[indx1 indx2]);
UD=delsig2(UU,[indu1 indu2]);
UC=delsig2(UU,indc);

% Allign XD and UD, UC vectors, because they were truncated
% by delaysig2

szx=size(XD,2);
szy=size(UD,2);
szc=size(UC,2);

sz=min(szx,szy);
XD=XD(:,szx-sz+1:szx);
UD=UD(:,szy-sz+1:szy);
UC=UC(:,szc-sz+1:szc);
% Mapping is created as F(P)=T;

P=[XD; UD];
T=UC;
end

if (case == 2)
indx1=(0:m);        		% X indices for the future state
indu1=(1:m-1)+nd;            	% U indices for the future state
indx2=(mc+m+nd:mc+2*m+nd); 	% X indices for the past state
indu2=(mc+m+nd:mc+2*m+2*nd-2);% U indices for the past state
indc = mc+m+nd-1;            	% controlling perturbation index

XD=delsig2(XX,[indx1 indx2]);
UD=delsig2(diff(UU')',[indu1 indu2]);
UC=delsig2(UU,indc);

szc=size(UC,2);
szx=size(XD,2);

if(m + nd > 1) %U's are involved
szy=size(UD,2);
sz=min(szx,szy);
XD=XD(:,szx-sz+1:szx);
UD=UD(:,szy-sz+1:szy);
P=[XD; UD];
else
sz=szx;
XD=XD(:,szx-sz+1:szx);
P=[XD];
end
UC=UC(:,szc-sz+1:szc);
T=UC;

end

```