function xdot=veh_mmx5(t,x)
Ca=30000;
l1=1.2;
l2=1.22;
m=1280;
Iz=2500;
U=18.3;
%A linear model of the vehicle is used in the simulations
%A=[-(2*Ca+2*Ca)/(m*U) 0 -U-(2*Ca*l1-2*Ca*l2)/(m*U) 0;...
%0 0 1 0;-(2*l1*Ca-2*l2*Ca)/(Iz*U) 0 -(2*l1^2*Ca+2*l2^2*Ca)/(Iz*U) 0;-1 -U 0 0];
%b=[2*Ca/m 0 2*l1*Ca/Iz 0]';
%c=[0 0 0 1];
eta=-0.1653;
r=4*(t>=1);
%min-max controller implementation
rho=abs(0.0329*x(1)+2.2854*x(2)+0.2429*x(3)-0.1653*x(4))+abs(r*eta);
%u=-rho*sign(0.1571*(x(1)-x(5))+26.9931*(x(2)-x(6))+6.3324*(x(3)-x(7))-3.025*(x(4)-x(8)));
%to accelerate simulations, an approximation of the sign function is used
f=0.1571*(x(1)-x(5))+26.9931*(x(2)-x(6))+6.3324*(x(3)-x(7))-3.025*(x(4)-x(8));
mu=0.00001;
u=-rho*(f/(abs(f)+mu));
%closed-loop system
xdot=[-((2*Ca+2*Ca)/(m*U))*x(1)+(-U-(2*Ca*l1-2*Ca*l2)/(m*U))*x(3)+(2*Ca/m)*u;
x(3);
(-(2*l1*Ca-2*l2*Ca)/(Iz*U))*x(1)+(-(2*l1^2*Ca+2*l2^2*Ca)/(Iz*U))*x(3)+(2*l1*Ca/Iz)*u;
-x(1)-U*x(2);
-6.6638*x(5)-107.1281*x(6)-29.635*x(7)+7.7479*x(8)+(2*Ca/m)*eta*r;
x(7);
-0.9205*x(5)-65.8195*x(6)-10.8362*x(7)+4.7603*x(8)+(2*l1*Ca/Iz)*eta*r;
-x(5)-18.3*x(6)];


