frob_norm_diag_scaling.m

来自「HERE IS A GOOD PSO TOOL BOX」· M 代码 · 共 51 行

M
51
字号
% Frobenious norm diagonal scaling example% Section 4.5.4 example in Boyd & Vandenberghe "Convex Optimization"% (see page 163 for more details)%% Given a square matrix M, the goal is to find a positive vector d% such that ||DMD^{-1}||_F is minimized, where D = diag(d).% The problem can be cast into an unconstrained GP:%%   minimize   sum_{i,j=1}^{n} M_ij^2*d_i^2/d_j^2%% with variable d (vector in R^n) and data matrix M in R^{n-by-n}.%% Almir Mutapcic 10/15/05randn('state',0);% matrix size (M is an n-by-n matrix)n = 4;M = randn(n,n);% GP variablesgpvar d(n);% objective expressed using a for loopobj = posynomial; % initialize an empty posynomialfor i = 1:n  for j = 1:n    obj = obj + M(i,j)^2*d(i)^2*d(j)^-2;  endend% objective can also be expressed using matrices% (can also use it below in the problem solving routine)% obj_vect = sum( sum( diag(d.^2)*(M.^2)*diag(d.^-2) ) );% solve the unconstrained GP problem[opt_frob_norm, solution, status] = gpsolve(obj,[]);% assign GP variables to their values (d now becomes an array of doubles)assign(solution);% construct matrix D and display resultsdisp(' ')disp('Optimal diagonal scaling d is: '), dD = diag(d);frob_norm_M = norm(M,'fro');frob_norm_A = norm(D*M*inv(D),'fro');fprintf(1,['The Frobenius norm for M before the scaling is %3.4f\n'...          'and after the optimal scaling (DMD^{-1}) it is %3.4f.\n'],...          frob_norm_M,frob_norm_A);

⌨️ 快捷键说明

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