%% Regularity of constraints at a given point
% Consider the following three inequalities
% x_1\geq 0,\quad x_2\geq 0;\quad x_2\leq (x_1-1)^2

syms x1 x2

h1 = -x1
h2 = -x2  
h3 = x2 - (x1-1)^2

%
% Let's plot the three functions whose intersection defines the feasible set

fimplicit([h1==0,h2+1e-8*x1==0,h3==0],[-1,2]) % fails without having both x1 and x2 in h2

%
% We now check regularity of the constraints. We need to compute the gradients first

gh1 = gradient(h1,[x1,x2])
gh2 = gradient(h2,[x1,x2])
gh3 = gradient(h3,[x1,x2])

%
% And now we evaluate the linear indepencence of the gradients at the point where h2 and h3 intersect, that is, the point

xr = [1; 0]

% that is, we consider the (column) rank of the matrix

gh23 = [gh2 gh3]

% which, when evaluated at the point xr is obviously rank-deficient

gh23r = subs(gh23,[x1;x2],xr)