%% Find an extremum of an equality constrained quadratic function
% Find an extremum (minimum or maximum) of the function
% f(\mathrm x)  = x_1+x_2^2+x_2x_3+2x_3^2
% subject to \frac{1}{2}(x_1^2+x_2^2+x_3^2)=1.
%% Expressing the cost function as a quadratic matrix form

Q = [0 0 0; 0 2 1; 0 1 4]
r = [1 0 0]'

%
%% Using CVX
% Dowload from http://cvxr.com/cvx/download/

cvx_begin
    variable x(3)
    minimize( 1/2*quad_form(x,Q)+r'*x )
    subject to
        sum_square(x) == 2
cvx_end

%
% :-( Nonconvex problem