%% Solve Quadratic Programming Problem Using Interior-Point Solver
% Find the values of x that minimize
% f\left( x \right) = 0.5x_1^2 + x_2^2 - {x_1}{x_2} - 2{x_1} - 6{x_2},
% subject to the constraints
% \begin{array}{l}
% {x_1} \ge 0\\
% {x_2} \ge 0\\
% {x_1} + {x_2} \le 2\\
%  - {x_1} + 2{x_2} \le 2\\
% 2{x_1} + {x_2} \le 3.
% \end{array}
% Specify the Hessian matrix and linear multiplier vector for the objective function.

H = [1 -1; -1 2];
f = [-2; -6];

%
% Specify the inequality constraint parameters.

A = [-1 0; 0 -1; 1 1; -1 2; 2 1];
b = [0; 0; 2; 2; 3];

%
% Define Aeq and beq to indicate that there are no equality constraints.

n = length(f);
Aeq = zeros(0,n);
beq = zeros(0,1);

%
% As a best practice, verify that H is positive definite using the chol function.

[~,p] = chol(H);

%
% If p = 0, then H is positive definite.

p

%
% Create a default option set for mpcInteriorPointSolver.

opt = mpcInteriorPointOptions;

%
% To cold start the solver, specify an initial guess of zeros for the elements of x.

x0 = zeros(n,1);

%
% Solve the QP problem.

[x,exitflag] = mpcInteriorPointSolver(H,f,A,b,Aeq,beq,x0,opt);

%
% Examine the solution x.

x

% Copyright 2019 The MathWorks, Inc.