function y=dtheta(x)
%y=dtheta(x)
%
%y = f(x) + 1/2*rho*alpha'*alpha,
%kde f(x) = x(1)^2 + x(2)^2 + m*x(2),
%    h1(x) = -x(1) - x(2) - 1
%    h2(x) = x(1) - x(2) - 3
%    alpha(x)=max{0,h(x)}

global rho m

f = x(1)^2 + x(2)^2 + m*x(2);
h(1,1) = -x(1) - x(2) - 1;
h(2,1) = x(1) - x(2) - 3;

alpha=max(zeros(2,1), h);

gf = [2*x(1); 2*x(2) + m];

if alpha(1,1)==0 && alpha(2,1)==0
   ga=zeros(2,1);
elseif alpha(1,1)>0 && alpha(2,1)==0
   ga=alpha(1,1)*[-1;-1];
elseif alpha(1,1)==0 && alpha(2,1)>0
   ga=alpha(2,1)*[1;-1];
else
   ga=alpha(1,1)*[-1;-1] + alpha(2,1)*[1;-1];
end;

y = gf + rho*ga;

% konec
