ex_8_5.m

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

M
33
字号
% One free point localization% Section 8.7.3, Boyd & Vandenberghe "Convex Optimization"% Joelle Skaf - 10/24/05%% K fixed points x_1,...,x_K in R^2 are given and the goal is to place% one additional point x such that the sum of the squares of the% Euclidean distances to fixed points is minimized:%           minimize    sum_{i=1}^K  ||x - x_i||^2% The optimal point is the average of the given fixed points% Data generationn = 2;K = 11;randn('state',0);P = randn(n,K);% minimizing the sum of Euclidean distancefprintf(1,'Minimizing the sum of the squares the distances to fixed points...');cvx_begin    variable x(2)    minimize ( sum( square_pos( norms(x*ones(1,K) - P,2) ) ) )cvx_endfprintf(1,'Done! \n');% Displaying resultsdisp('------------------------------------------------------------------');disp('The optimal point location is: ');disp(x);disp('The average location of the fixed points is');disp(sum(P,2)/K);disp('They are the same as expected!');

⌨️ 快捷键说明

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