⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eucl_proj_rect.m~

📁 斯坦福大学Grant和Boyd教授等开发的凸优化matlab工具箱
💻 M~
字号:
% Euclidean projection on a rectangle% Section 8.1.1, Boyd & Vandenberghe "Convex Optimization"% Joelle Skaf - 10/07/05%% The projection of x0 on a rectangle C = {x | l <= x <= u} is given by%           minimize || x - x0 ||^2%               s.t.    l <= x <= u% It is also given by P_C(x0)_k = l_k       if  x0_k <= l_k%                                 x0_k      if  l_k <= x0_k <= u_k%                                 u_k       if  x0_k >= u_kcvx_quiet(true);% Input datan  = 10;% generating vector l and u such that l < ul  = -rand(n,1);u  = rand(n,1);x0 = randn(n,1);% Analytical solutionfprintf(1,'Computing the analytical solution ...');pc_x0 = x0;pc_x0(find(x0<=l)) = l(find(x0<=l));pc_x0(find(x0>=u)) = u(find(x0>=u));fprintf(1,'Done! \n');% Solution via QPfprintf(1,'Computing the optimal solution by solving a QP ...');cvx_begin    cv    variable x(n)    minimize ( norm(x-x0) )    x <= u;    x >= l;cvx_endfprintf(1,'Done! \n');% Verificationdisp('-----------------------------------------------------------------');disp('Verifying that the analytical solution and the solution obtained via QP are equal: ');[pc_x0 x]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -