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

📄 eucl_proj_hyp.m

📁 斯坦福大学Grant和Boyd教授等开发的凸优化matlab工具箱
💻 M
字号:
% Euclidean projection on a hyperplane% Section 8.1.1, Boyd & Vandenberghe "Convex Optimization"% Joelle Skaf - 10/04/05%% The projection of x0 on a hyperplane C = {x | a'*x = b} is given by%           minimize || x - x0 ||^2%               s.t.    a'*x = b% It is also given by P_C(x0) = x0 + (b - a'*x0)*a/||a||^2cvx_quiet(true);% Input datarandn('seed',0);n  = 10;a  = randn(n,1);b  = randn(1);x0 = randn(n,1);% Analytical solutionfprintf(1,'Computing the analytical solution ...');pc_x0 = x0 + (b - a'*x0)*a/norm(a)^2;fprintf(1,'Done! \n');% Solution via QPfprintf(1,'Computing the optimal solution by solving a QP ...');cvx_begin    variable x(n)    minimize ( square_pos(norm(x - x0)) )    a'*x == b;cvx_endfprintf(1,'Done! \n');% Verificationdisp('--------------------------------------------------------------------------------');disp('Verifying that p_C(x0) and x_star belong to the hyperplane C: ');disp(['a^T*p_C(x0) - b = ' num2str(a'*pc_x0 - b)]);disp(['a^T*x_star - b  = ' num2str(a'*x - b)]);disp('Computing the distance between x0 and the hyperplane in each case');disp(['||x0 - p_C(x0)|| = ' num2str(norm(x0 - pc_x0))]);disp(['||x0 - x_star || = ' num2str(norm(x0 - x))]);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 + -