clear all;


## QUADRATIC OBJECTIVE FUNCTION

% Hessian matrix
H = [ 2.42412  -0.55027   2.01658;  ...
     -0.55027   0.71447  -0.73403;  ...
      2.01658  -0.73403   5.78823]; ...

% linear part of the objective function
q = [-0.00228; -0.17250; -0.33549];

% Check: the Hessian is positive definite
assert (all (eig (H) > 0));


## LINEAR INEQUALITY CONSTRAINTS

A = [eye(3); -eye(3)];
lb = [-5.33; -2.01; -4.73; -4.70; -0.98; -5.27];


## INITIAL GUESS

x0 = [-0.10; 1.32; 0.64];
  
% Note: the 5th constraint is violated by x0
assert (find (A * x0 < lb) == 5);

% Note: the documentation of qp does not say that x0 must be
% feasible, and does not indicate what happens if it's not


## CALL QP

[x, obj_qp, INFO, lambda] = qp ( ...
  x0,     ...  # initial guess
  H, q,   ...  # quandratic objective function
  [], [], ...  # linear quality constraints
  [], [], ...  # box constraints
  lb, A, Inf (size (lb)))  # linear inequality constraints

  
## CHECK THAT EVERYTHING WORKED FINE

% Check that qp identified the problem as a convex QP problem
% and properly converged to a global solution (or thinks it did)
assert (INFO.info == 0);

% Check that the solution is feasible
assert (all (A * x >= lb));
