randn('seed',0);
n = 10;
x0 = randn(n,1);
fprintf(1,'Computing the analytical solution...');
pk_x0 = max(x0,0);
fprintf(1,'Done! \n');
fprintf(1,'Computing the solution via a QP...');
cvx_begin quiet
variable x(n)
minimize ( norm(x - x0) )
x >= 0;
cvx_end
fprintf(1,'Done! \n');
disp('-----------------------------------------------------------------');
disp('Verifying that the analytical solution and the solution obtained via QP are equal: ');
[pk_x0 x]
disp('They are equal as expected!');
Computing the analytical solution...Done!
Computing the solution via a QP...Done!
-----------------------------------------------------------------
Verifying that the analytical solution and the solution obtained via QP are equal:
ans =
1.1650 1.1650
0.6268 0.6269
0.0751 0.0750
0.3516 0.3516
0 -0.0000
1.6961 1.6961
0.0591 0.0590
1.7971 1.7971
0.2641 0.2641
0.8717 0.8717
They are equal as expected!