%% Lack of regularity of a single constraint
%
% minimize x_1
% subject to x_1^3-x_2^2 = 0.

x1 = linspace(-1,1,100);
x2 = linspace(-1,1,100);

[X1,X2] = meshgrid(x1,x2);

F = X1;
G = X1.^3 - X2.^2;

mesh(X1,X2,G)
xlabel('x_1')
ylabel('x_2')
zlabel('x_1^3-x_2^2')

contour(X1,X2,G)
hold on
contour(X1,X2,F)
hold off
xlabel('x_1')
ylabel('x_2')

%
% Let's compute the gradient of the cost and the constraint at the origin

syms x1 x2 d

f = x1
g = x1^3-x2^2


df = gradient(f,[x1 x2])
dg = gradient(g,[x2 x2])
dg0 = subs(dg,[x1 x2],[0 0])