%kuhntucker.m
clc;
clear all;
close all;
%demonstration for inequality constraints
figure
i=1;
j=1;
for x=-2:0.1:2
i=1;
for y=-2:0.1:2
z(i,j)=2*x^2+4*y+3;
i=i+1;
end
j=j+1;
end
x=-2:0.1:2;
y=-2:0.1:2;
contour(x,y,z,150)
y=-2:0.1:2;
x=2-y.^2;
hold on
plot(x,y,'k')
for x=-2:0.1:2
plot([x 0],[sqrt(2-x) sqrt(2-x)-1],'r')
plot([x 0],[sqrt(2-x) sqrt(2-x)*(1-2*x) ],'m')
hold on
end
figure
i=1;
j=1;
for x=-2:0.1:2
i=1;
for y=-2:0.1:2
z(i,j)=2*x^2+4*y+3;
i=i+1;
end
j=j+1;
end
x=-2:0.1:2;
y=-2:0.1:2;
contour(x,y,z,150)
y=-2:0.1:2;
x=2-y.^2;
hold on
plot(x,y,'k')
for x=-2:0.1:2
    plot([x 0],[sqrt(2-x) sqrt(2-x)-1],'r')
plot([x 0],[sqrt(2-x) sqrt(2-x)*(1-2*x) ],'m')
hold on
end
figure
i=1;
j=1;
for x=-2:0.1:2
i=1;
for y=-2:0.1:2
z(i,j)=2*x^2+4*y+3;
i=i+1;
end
j=j+1;
end
x=-2:0.1:2;
y=-2:0.1:2;
contour(x,y,z,150)
y=-2:0.1:2;
x=2-y.^2;
hold on
plot(x,y,'k')
for x=-2:0.1:2
plot([x 0],[-sqrt(2-x) -sqrt(2-x)-1],'r')
plot([x 0],[-sqrt(2-x) -sqrt(2-x)*(1-2*x) ],'m')
hold on
end
figure
y=-2:0.1:2;
x=2-y.^2;
hold on
plot(x,y,'k')