% QP with H close to -I on unit box; min at every corner of the box clear; % number of variables n = 10; % form a random symmetric matrix (may be indefinite) H = rand(n,n); H = H + H'; H = -eye(n) + 0.1*H; f = zeros(n,1); % null inequalities A = zeros(1,n); b = 0; % null equality constraints; Aeq = []; beq = []; % unit bounds lb = -ones(1,n); ub = ones(1,n); options = optimset('LargeScale','off'); K = 5; % solve K times, starting from a (different) random vector each time, % storing the results in xsol xsol = zeros(n,K); fsol =zeros(1,K); for i=1:K, x = 2*(rand(n,1)-.5); % x= .99 + .01*rand(n,1); [x,fval,exitflag, output, lambda] = quadprog(H,f,A,b,Aeq,beq,lb, ... ub,x,options); xsol(:,i) = x; fsol(1,i) = fval; end % print solution array xsol fsol