eucl_proj_cone1.m

来自「斯坦福大学Grant和Boyd教授等开发的凸优化matlab工具箱」· M 代码 · 共 38 行

M
38
字号
% 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 + =
减小字号Ctrl + -
显示快捷键?