% opt_func.m

function xp=opt_func(t,x)

A=[5 1;-5 1;-1 -2];
b=[0 10 10]';
Q=[4 1;1 2];
c=[-12 -10]';

u = 3;
boundary = 0.1;

k1 = sat(A(1,:)*x-b(1),boundary);
k2 = sat(A(2,:)*x-b(2),boundary);
k3 = sat(A(3,:)*x-b(3),boundary);
k0 = (1-k1)*(1-k2)*(1-k3);

%xp=(~k0)*(-u*k1*A(1,:)'-u*k2*A(2,:)'-u*k3*A(3,:)');
xp=-k0*(Q*x+c)-u*k1*A(1,:)'-u*k2*A(2,:)'-u*k3*A(3,:)';
%it is also interesting to try the negative of the objective function
%xp=-k0*(Q*x+c)-u*k1*A(1,:)'-u*k2*A(2,:)'-u*k3*A(3,:)';

