📄 eucl_proj_cone1.m
字号:
% Euclidean projection on the nonnegative orthant% Section 8.1.1, Boyd & Vandenberghe "Convex Optimization"% Joelle Skaf - 10/07/05%% The projection of x0 on the proper cone K = R+^n is given by% minimize || x - x0 ||^2% s.t. x >= 0% It is also given by: P_K(x0)_k = max{x0_k,0}cvx_quiet(true);% Input datarandn('seed',0);n = 10;x0 = randn(n,1);fprintf(1,'Computing the analytical solution...');% Analytical solutionpk_x0 = max(x0,0);fprintf(1,'Done! \n');% Solution via CVXfprintf(1,'Computing the solution via a QP...');cvx_begin variable x(n) minimize ( norm(x - x0) ) x >= 0;cvx_endfprintf(1,'Done! \n');% Verificationdisp('-----------------------------------------------------------------');disp('Verifying that the analytical solution and the solution obtained via QP are equal: ');[pk_x0 x]disp('They are equal as expected!');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -