function [X,LAMBDA,EXITFLAG] = qpw(H,f,A,b,VLB,VUB,X0,N)
% QPW Quadratic programming. 
%    QPW is a wrapper to QUADPROG.
% 
%    X=QPW(H,f,A,b) solves the quadratic programming problem:
% 
%             min 0.5*x'Hx + f'x   subject to:  Ax <= b 
%              x    
% 
%       X=QPW(H,f,A,b,VLB,VUB) defines a set of lower and upper
%        bounds on the design variables, X, so that the solution  
%        is always in the range VLB <= X <= VUB.
% 
%        X=QPW(H,f,A,b,VLB,VUB,X0) sets the initial starting point to X0.
% 
%        X=QPW(H,f,A,b,VLB,VUB,X0,N) indicates that the first N constraints 
%        defined by A and b are equality constraints.
% 
%        [x,LAMBDA]=QPW(H,f,A,b) returns the set of Lagrangian multipliers,
%        LAMBDA, at the solution.
% 
%        [X,LAMBDA,EXITFLAG] = QPW(H,f,A,b) also returns a string EXITFLAG that 
%   describes the exit condition of QUADPROG.  
%   If EXITFLAG is:
%      > 0 then QUADPROG converged with a solution X.
%      0   then the maximum number of iterations was exceeded (only occurs
%           with large-scale method).
%      < 0 then the problem is unbounded, infeasible, or 
%           QUADPROG failed to converge with a solution X.
% 

if nargin < 8, N = 0; 
      if nargin < 7, X = []; 
         if nargin < 6, VUB = []; 
           if nargin < 5, VLB = [];
end, end, end, end

if isempty(N), N=0; end 
M = length(b);
options = optimset('Display','off');

[X,FVAL,EXITFLAG,OUTPUT,OLAMBDA]=quadprog(H,f,A(N+1:M,:),b(N+1:M),A(1:N,:),b(1:N),VLB,VUB,X,options);
LAMBDA = [OLAMBDA.eqlin; OLAMBDA.ineqlin];



