1function [R,fr,Air,bir,y1,Q,Es,Status,Flag]=ReduceQP(H,f,Ae,be,Ai,bi,lb,ub,tol)
2% [Hr,fr,Air,bir,fvr,y1,Q,,Es,Status,Flag]=ReduceQP(H,f,Ae,be,Ai,bi,tol)
3% Given the following general Convex QP problem :
4% min 0.5*x
'*H*x + f'*x , such that Ae*x=be; Ai*x<=bi; lb<=x<=ub
6% with H
'=H>=0 and [Ae;H] full column rank
7% ReduceQP computes a reduced strictly convex QP problem
8% without any equality constraints :
9% min 0.5*y2'*Hr*y2 + fr
'*y2 , such that Air*y2<=bir;
11% and y1 such that the solution of the original problem is x=Q*[y1;y2]
12% where y2 is the solution of the reduced problem of size (n-p).
14% Note [p,n]=size(Ae), Q=[Q1,Q2] such that Hr=Q2'*H*Q2>0, Ae*Q2=0;
15% Q1
is nxp and Q2
is nx(n-p)
17%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18n=length(f);Flag=1;Status=
'OK';
19if nargin<9, tol=16*n*eps;end
20if nargin<8, ub=inf(n,1);end
21if nargin<7, lb=-inf(n,1);end
22if nargin<6, Ai=[];bi=[];end
23if nargin<4, error(
'ReduceQP requires at least 4 parameters');end
24[E,Error]=ExtendedFactorization(H,tol);Es=E;
27 %Null space decomposition
29 ref=abs(R(1,1))*tol;r=1;
30 while r<p&&abs(R(r+1,r+1))>ref;r=r+1;end
32 y1=R(L1,L1)\be(e(L1));%particular solution of equality constraints
33 if r<p%check rank deficiency
35 if norm(err)<tol*norm(be)%however feasible
36 Status=
'Rank deficient Feasible Equality Constraints';
40 Status=
'Infeasible Equality constraints';
41 Air=[];bir=[];R=[];fr=[];y1=[];Q=[];Es=[];
return;
44 E2=E*Q(:,L2);%reduced hessian factorization
46 ref=abs(R(1,1))*tol;r=1;
47 while r<n-p&&abs(R(r+1,r+1))>ref;r=r+1;end
50 Status=
'Reduce Hessian is singular';
51 Air=[];bir=[];R=[];fr=[];y1=[];Q=[];Es=[];
return;
53 Eye=eye(n);%Full Identity matrix
56 fr=E2
'*E1*y1+Q(:,L2)'*f;%reduced linear term
58 Lu=isfinite(ub);Ll=isfinite(lb);
59 Ai=[Ai;Eye(Lu,:);-Eye(Ll,:)];bi=[bi;ub(Lu);-lb(Ll)];
62 Air=Ai(:,L2);bir=bi-Ai(:,L1)*y1;
68 Status=
'The QP problem is not convex';
69 Air=[];bir=[];R=[];fr=[];y1=[];Q=[];Es=[];
return;
71%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%