function norm = merit (z, f, lb, ub)

n = length(z);
norm = 0;
for i=1:n
    if (z(i) <= lb(i)) 
      dt = min(0,f(i));
      norm = norm + dt*dt;
    elseif (z(i) >= ub(i)) 
      dt = max(0,f(i));
      norm = norm + dt*dt;
    else
      norm = norm + f(i)*f(i);
    end
end
norm = sqrt(norm);
return;
