matlab使用CVX求解优化问题时,如果变量搜索空间过大,导致求解的数值解相当不准确,通过变量替换,缩小搜索空间

错误的做法

clear 
clc
rand('seed',1); 
%% 参数初始化
I = 5; 
N = 5; 
q = ones(1,I)/I;
theta = [11,13,15,18,21]/10;
T = 3;
D = 81920; 
eta =10; 
kappa = 10^(-28); 
c4 = 1;
Nq = N.*q;
for i  = 1:I
    if i<I
        mid_para(i) = theta(i)*sum(Nq(1,i:end)) - theta(i+1)*sum(Nq(1,i+1:end));
    else
        mid_para(i) = theta(i);
    end
    
end
%% 求解
% 解析解
f_star = (mid_para*D*eta./(c4*2*D*eta*kappa)).^(1/3);
% 数值解
cvx_begin 
    variable f(I)
    for i = 1:I
        U(i) = mid_para(i)*(T - D*eta*inv_pos(f(i)) - c4*D*eta*kappa*f(i)^2; 
    end
    minimize( sum(-U) )
    subject to
        f>zeros(I,1)
cvx_end

因为优化变量 f f f的取值范围是 [ 0 , 1 0 10 ] [0,10^{10}] [0,1010],所以采用CVX工具箱进行求解时,导致结果极其不准确。

正确的做法

采用 y = f ∗ 1 0 9 y=f*10^9 y=f109,带入到原始优化问题,得到如下程序。这样的话,采用的CVX求解出来的数值解和解析解近似相等。

clear 
clc
rand('seed',1); 
%% 参数初始化
I = 5; % 终端类型个数
N = 5; % 终端数量
q = ones(1,I)/I;% 每个类型概率
theta = [11,13,15,18,21]/10;
T = 3;
D = 81920; % bit
eta =10; %  cpu/bit
kappa = 10^(-28);  %   f=F*10^8     % effective capacitance coefficient of vehicular client's computing chipset
c4 = 1;
% theta = 1:(10-1)/(I-1):10;
%% 契约求解中间参数 b
Nq = N.*q;
for i  = 1:I
    if i<I
        mid_para(i) = theta(i)*sum(Nq(1,i:end)) - theta(i+1)*sum(Nq(1,i+1:end));
    else
        mid_para(i) = theta(i);
    end
    
end
%% 求解
% 解析解
f_star = (mid_para*D*eta./(c4*2*D*eta*kappa)).^(1/3);
% 数值解
cvx_begin 
    variable f(I)
    for i = 1:I
        U(i) = mid_para(i)*(T - D*eta*inv_pos(y(i)*10^9)) - c4*D*eta*kappa*y(i)^2*(10^18); 
    end
    minimize( sum(-U) )
    subject to
        y>zeros(I,1)
cvx_end

你可能感兴趣的:(凸优化学习,matlab学习,matlab,算法,开发语言)