% Robust optimisation

f = [0 -0.5 0 0 -0.5 0 0]; % linear cost function

H = [0 0 0 0 0 0 0;
    0 2/8 0 0 0 0 0;
    0 0 0 0 0 0 0;
    0 0 0 0 0 0 0;
    0 0 0 0 2/8 0 0;
    0 0 0 0 0 0 0;
    0 0 0 0 0 0 0]; % Quadratic cost function
H = 2*H; % need to recalculate H since quadprog uses 1/2 times H in the 
% formulation of the quadratic cost function

Aeq = [1 1 1 0 0 0 0 ;
    1 3/4 0 1 0 0 0 ;
    1 0 0 0 1 1 0;
    -3 0 0 0 5/4 0 1]; % Equallity constraint matrix
beq = [2;
    2;
    2;
    2]; % Constraint value vector
A = [0 0 0 0 0 0 0]; % Inequallity constraint matrix
b = [0]; % Constraint value vector
lb = [-1; 0; 0; 0; 0; 0; 0]; % Lower bound vector

ub = [1; Inf; Inf; Inf; Inf; Inf; Inf]; % upper bound vector

[x, fval, EF]=quadprog(H,f,A,b,Aeq,beq,lb,ub);

% EF is the existflag and if it is 1, the function linprog found a feasible
% soultion to the problem.
% Check if the solution is feasible 
if EF > 0
    fprintf('Feasbile solution \n ');
else
    fprintf('Unfeasible solution \n ');
end

% Prints results 
string = ['The solution is [%1.4f %1.4f %1.4f %1.4f %1.4f %1.4f %1.4f] \n ' ...
'the cost function is %2.4f \n '];

fprintf(string, x(:,1),fval );