%% Quadratic Minimization with Linear Constraints and Bounds
% Find the x that minimizes the quadratic expression
% \frac{1}{2}x^T Hx + f^T x
% where
% H=\left\lbrack \begin{array}{ccc}
% 1 & -1 & 1\\
% -1 & 2 & -2\\
% 1 & -2 & 4
% \end{array}\right\rbrack, f=\left\lbrack \begin{array}{c}
% 2\\
% -3\\
% 1
% \end{array}\right\rbrack,
% subject to the constraints
% 0\le x\le 1, \sum x = 1/2.
% To solve this problem, first enter the coefficients.

H = [1,-1,1
    -1,2,-2
    1,-2,4];
f = [2;-3;1];
lb = zeros(3,1);
ub = ones(size(lb));
Aeq = ones(1,3);
beq = 1/2;

% Call quadprog, entering [] for the inputs A and b.

x = quadprog(H,f,[],[],Aeq,beq,lb,ub)

% Copyright 2018 The MathWorks, Inc.