% min S(x) = 4 * x1^2 + 5 * x2^2
%  s.a. h(x) = 2 * x1 + 3 * x2 - 6 = 0
%        x >= 0
%  x' = [1.071  1.286]


op=optimset('LargeScale','off');
tic
Q=[4 0;0 5]*2
c=[0; 0]
A=[]
b=[]
Aeq=[2 3]
beq=6
lb=[0;0]
ub=[]

[x,s,ex,out,lambda]=quadprog(Q,c,A,b,Aeq,beq,lb,ub,[],op)
toc

tic
Al=[Aeq 0 0 0;Q Aeq' -eye(2)]
bl=[beq;0;0]
cl=0.5*[0;0;-beq;0;0]
LB=[0;0;-Inf;-Inf;-Inf];
UB=[Inf;Inf;0;0;0];
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA]=linprog(cl,[],[],Al,bl,LB,UB,[],op)
toc

tic
A2=[Aeq 0 0 0;Q -Aeq' eye(2)]
b2=[beq;0;0]
c2=0.5*[0;0;beq;0;0]
LB2=[0;0;0;0;0];
UB2=[Inf;Inf;Inf;Inf;Inf];
[X2,FVAL2,EXITFLAG2,OUTPUT2,LAMBDA2]=linprog(c2,[],[],A2,b2,LB2,UB2,[],op)
toc
