// min S(x) = x1^2 + x2^2 + x3^2   (problema super restrito)
//  s.a. g1(x) = 2 * x1 + x2 - 5 <= 0
//       g2(x) = x1 + x3 - 2 <= 0
//       g3(x) = x1 + 2 * x2 + x3 - 10 <= 0
//       h1(x) = 2 * x1 - 2 * x2 + x3 + 2 = 0
//       h2(x) = 10 * x1 + 8 * x2 - 14 * x3 - 26 = 0
//       h3(x) = -4 * x1 + 5 * x2 - 6 * x3 - 6 = 0
//       x1 >= 1,  x2 >= 2,  x3 >= 0
//
// x' =[1  2  0]

Q=[1 0 0;0 1 0;0 0 1]*2
c=[0; 0; 0]
A=[2  1  0
   1  0  1
   1  2  1]
b=[5; 2; 10]
Aeq=[ 2 -2   1
     10  8 -14
     -4  5  -6]
beq=[-2; 26; 6]
lb=[1; 2; 0]
ub=[]

op=optimset('LargeScale','off');
[x,s,ex,out,lambda]=quadprog(Q,c,A,b,Aeq,beq,lb,ub,[],op)

// removendo as restricoes de igualdade

Aeq1=[]
beq1=[]

[x1,s1,ex,out,lambda1]=quadprog(Q,c,A,b,Aeq1,beq1,lb,ub,[],op)

// mudando a funcao objetivo

c2=[-1;0;-3]

[x2,s2,ex,out,lambda2]=quadprog(Q,c2,A,b,Aeq1,beq1,lb,ub,[],op)

// mudando o limite inferior

lb3=zeros(3,1);
[x3,s3,ex,out,lambda3]=quadprog(Q,c2,A,b,Aeq1,beq1,lb3,ub,[],op)

// resolvendo o ultimo caso como LP (min)

Al=[A eye(3) zeros(3) zeros(3);Q zeros(3) -A' eye(3)];
bl=[b;-c2];
cl=0.5*[c2;zeros(3,1);b;zeros(3,1)];
LB=[zeros(6,1);zeros(6,1)];
UB=[Inf*ones(6,1);Inf*ones(6,1)];
op=optimset('LargeScale','off');
[Xm,FVALm,EXITFLAG,OUTPUT,LAMBDAm]=LINPROG(cl,[],[],Al,bl,LB,UB,[],op)

// resolvendo o ultimo caso como LP (maxmin)

Al=[A eye(3) zeros(3) zeros(3);Q zeros(3) A' -eye(3)];
bl=[b;-c2];
cl=0.5*[c2;zeros(3,1);-b;zeros(3,1)];
LB=[zeros(6,1);-Inf*ones(6,1)];
UB=[Inf*ones(6,1);zeros(6,1)];
op=optimset('LargeScale','off');
[XM,FVALM,EXITFLAG,OUTPUT,LAMBDAM]=LINPROG(cl,[],[],Al,bl,LB,UB,[],op)
