ex_5_39.m

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

M
51
字号
% Exercise 5.39: SDP relaxations of the two-way partitioning problem% Boyd & Vandenberghe. "Convex Optimization"% Jo雔le Skaf - 09/07/05% (a figure is generated)%% Compares the optimal values of:% 1) the Lagrange dual of the two-way partitioning problem%               maximize    -sum(nu)%                   s.t.    W + diag(nu) >= 0% 2) the SDP relaxation of the two-way partitioning problem%               minimize    trace(WX)%                   s.t.    X >= 0%                           X_ii = 1% Input datarandn('state',0);n = 10;W = randn(n); W = 0.5*(W + W');% Lagrange dualfprintf(1,'Solving the dual of the two-way partitioning problem...');cvx_begin sdp    variable nu(n)    maximize ( -sum(nu) )    W + diag(nu) >= 0;cvx_endfprintf(1,'Done! \n');opt1 = cvx_optval;% SDP relaxationfprintf(1,'Solving the SDP relaxation of the two-way partitioning problem...');cvx_begin sdp    variable X(n,n) symmetric    minimize ( trace(W*X) )    diag(X) == 1;    X >= 0;cvx_endfprintf(1,'Done! \n');opt2 = cvx_optval;% Displaying resultsdisp('------------------------------------------------------------------------');disp('The optimal value of the Lagrange dual and the SDP relaxation fo the    ');disp('two-way partitioning problem are, respectively, ');disp([opt1 opt2])disp('They are equal as expected!');

⌨️ 快捷键说明

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