function xprime=CS1(t,X) 
%OR CS1
global UU dyndata tend NI
indmat_Yes_S1

[D,e1] = Controller_PI(X(im_mt+NI),dyndata.x_nom(im_mt),dyndata.u_nom(end-1),X(1),1,1001,0,2);
[B,e2] = Controller_PI(X(im_mr+NI),dyndata.x_nom(im_mr),dyndata.u_nom(end),X(2),1,1001,0,2);

au=1;
[L,e3] = Controller_PI(log(X(im_xt(2)+NI)),log(dyndata.x_nom(im_xt(2))),...
            dyndata.u_nom(1),X(3),0.48*au/2,40*2,0,4);
       
[S1,e4] = Controller_PI(log((X(im_xS1(2)+NI))),log((dyndata.x_nom(im_xS1(2)))),...
            dyndata.u_nom(5),X(4),88*au/8,40*8,0,4);

[Rl,e5] = Controller_PI(log(1-sum(X(im_x1([1 1+coldata.Nt(1)])+NI))),...
            log(1-sum(dyndata.x_nom(im_x1([1 1+coldata.Nt(1)])))),...
            dyndata.u_nom(3),X(5),-0.333*au,40,0,1);


[RV,e6] = Controller_PI(log(X(im_x2(coldata.Nt(2))+NI)),...
            log(dyndata.x_nom(im_x2(coldata.Nt(2)))),...
            dyndata.u_nom(4),X(6),-0.03125*au,160,0,1);

[VBB1,e7] = Controller_PI(log((X(im_xr(2)+NI))),...
            log((dyndata.x_nom(im_xr(2)))),...
             dyndata.u_nom(2),X(7),0.2*au,40,0,4);
[VBB2,e8] = Controller_PI(log((X(im_xS1(1)+NI))),...
            log((dyndata.x_nom(im_xS1(1)))),...
            dyndata.u_nom(2),X(8),0.32*au*0,40,0,4);
VBB=VBB1;


if t==tend
%     t
UU=[UU; t [L;VBB;Rl;RV;S1;dyndata.u_nom(6:9); D; B;VBB1;VBB2]'];
end
xprime=Petlyuk_dxdt(t,[L;VBB;Rl;RV;S1;dyndata.u_nom(6:9); D; B ;X(NI+1:end)]);
xprime=[e1;e2;e3;e4;e5;e6;e7;e8;xprime];