How can I find error in this problem?

Does this text about cvx is right for cvx dcprules ? cvx didn’t report an error,but the result is not correct?
I am trying to solve a cvx problem like this
max 0.5+<H,X>/const
s.t. <A_i,X>=B_i
0.5+ <H,X>/const <= 0.5
and X is a semidefinite hermitian matrix,H and each A_i is const matrix.The model is just a simple model.
<H,X> reprents that Hadamard multiply between matrix H and matrix X,then,sum over all then elements of the outcom matrix.
Then the code is listed like this:

clear;clc
ksi=0.20;       % 损耗系数的值
e_ali=0.015 ;  %校准错误率
L=80 ;            %设置距离 ,单位为km
ita_det=0.145; %设置探测器的探测效率
p_dc=6.02e-6 ; %设置暗计数率
alpha=0.1;       %设置双方发送的相干态的平均光子数
ita=ita_det*10^(-ksi*L/10.0);%计算整体透过率
alpha_in=alpha*ita ;
P_pass=( p_dc+(1-p_dc )*(1-exp(-2*alpha_in ) ) ) *(1-p_dc) + (1-p_dc)*exp(-2*alpha_in)*p_dc ;%计算探测器的响应率
E_bit=(e_ali*(1-p_dc)^2*(1-exp(-2*alpha_in))+(1-p_dc)*exp(-2*alpha_in)*p_dc)/P_pass; %计算比特误码率

%接下来建立多个稀疏矩阵,挑选出Gram矩阵中的特定的一些元素
m=[1 17  2  18];   %横坐标
n=[4  20  3  19];  %纵坐标
v=[1  -1  -1  1];   %非零值
H_1=sparse(m,n,v,48,48);%H_1矩阵为创建相位误码率使用


%建立第一个等式约束
m=[1 2 3 4  17 18 19 20 ];
n=[1 2 3  4   17 18 19 20 ];
v=[ 1 1 1 1 1 1 1 1];
H_2=sparse(m,n,v,48,48);%H_2为创建第一个约束中的x基中的响应率使用
suoyin_2=sub2ind([48,48],m,n);

m=[5 6 7 8  21 22 23 24];
n=[5 6 7 8  21 22 23 24];
v=[ 1 1 1 1 1 1 1 1];
H_3=sparse(m,n,v,48,48);%H_3为创建第一个约束中的y基中的响应率使用
suoyin_3=sub2ind([48,48],m,n);

%建立第二个等式约束
m=[ 2 3 18 19];
n=[ 2 3 18 19];
v=[1 1 1 1];
H_4=sparse(m,n,v,48,48);%H_4为创建第二个约束中的x基中误码率使用
suoyin_4=sub2ind([48,48],m,n);

m=[6 7 22 23];
n=[6 7 22 23];
v=[1 1 1 1];
H_5=sparse(m,n,v,48,48);%H_5为创建第二个约束中的y基中误码率使用
suoyin_5=sub2ind([48,48],m,n);

%下面建立第三个等式约束
lambda_0=zeros(256,1);%这个矢量存储等式约束左边的值
index_0=zeros(256,1);%储存等式约束右边的与Gram矩阵的相关项的横坐标
index_1=zeros(256,1);%储存等式约束右边的与Gram矩阵的相关项的纵坐标
fuzhu=[1 -1 1i -1i];%引入一个辅助向量为了计算相干态的內积
ind=0;
for  w=1:4  
    for  x=1:4
         for y=1:4
             for z=1:4
                  ind=ind+1;
                  xubu=exp(conj(fuzhu(w))*fuzhu(x)*alpha+conj(fuzhu(y))*fuzhu(z)*alpha-2*alpha);
                  lambda_0(ind)=xubu;
                  if  w < 3 
                            if y<3
                                index_0(ind)=1+2*( ~mod(w,2))+~mod(y,2);
                                
                            else
                                 index_0(ind)=1+8+2*( ~mod(w,2))+~mod(y,2);
                            end
                  else
                            if y<3
                                 index_0(ind)=1+12+2*( ~mod(w,2))+~mod(y,2);
                            else
                                  index_0(ind)=1+4+2*( ~mod(w,2))+~mod(y,2);
                            end
                  end        
                   if  x<3
                            if z < 3 
                                index_1(ind)=1+2*( ~mod(x,2))+~mod(z,2);
                            else
                                  index_1(ind)=1+8+2*( ~mod(x,2))+~mod(z,2);
                            end
                   else 
                            if z<3
                                  index_1(ind)=1+12+2*( ~mod(x,2))+~mod(z,2);
                            else
                                  index_1(ind)=1+4+2*( ~mod(x,2))+~mod(z,2);
                            end        
                   end     
             end
         end
    end  
end

index_all_1=sub2ind([48,48],index_0,index_1);
index_all_2=sub2ind([48,48],index_0+16,index_1+16);
index_all_3=sub2ind([48,48],index_0+32,index_1+32);

cvx_begin  sdp

    variable   G(48,48)   hermitian  semidefinite ;
    E_ph= 0.5+ ( 0.5*sum(sum(H_1.*G))+0.5*  conj( sum(sum(H_1.*G))))/4/P_pass;

    maximize( E_ph)
    subject to      
                   
                P_pass   == 0.25*sum(sum(G.*H_2))  ;                                  
                P_pass   ==  0.25*sum(sum(G.*H_3))  ;                                   
                E_bit * P_pass    == 0.25*sum(sum(G.*H_4))   ;                        
                E_bit * P_pass    ==    0.25*sum(sum(G.*H_5))  ;                    
                lambda_0  ==    G(index_all_1)+G(index_all_2)+G(index_all_3); 
                 E_ph<=0.5                                                         
cvx_end   
  R_min=P_pass*(1-E_ph*log2(E_ph)-E_bit*log2(E_bit)) 

in my code ,I set e_ph<=0.5,but whenever i change the value of parameters,cvx always give me a outcome e_ph=0.5,it seems like that the constraints that i set doesn’t work.and mostly, i get the value of cvx_ipbnd is inf.and cvx_status if solved.cvx didn’t report an error,but the result is not right

Thank you very much!

1 Like

You have not provided a reproducible example because you have not shown the input data.

Please copy and paste your code as text, and use the Preformatted text option. DO not post an image of your code.

Readers have no idea what problem you are trying to solve, what results you obtained, including CVX and solver status. Nor have you explained in what way the results is not correct.

I have change it ,can you help me with this problem? Thank you very much!

I also want to know whether it is correct that use “sum(sum(H))” in a equal constraint where H is a matrix

Multiple solvers all produce the same optimal solution. Whether the model you have provided to CVX is an adequate representation of whatever “real world” problem you are trying to model and optimize is another matter.

sum(sum(H)) , where H is an input (i.e. numerical) value to CVX is just a double precision number (i.e., constant to CVX). So it can be used in an equality constraint. As you have seen, CVX accepts and solves your problem( by calling a solver).

Note that you have defined <H,X> to equal sum(sum(H.*X)), which also equals trace(H'*X), which might be a more usual way for it to be defined…

As far as finding the error, i suggest you start with a simplified version of the model, verify tis correct functioning, then gradually increase the complexity until you get to the full model of intrest.

Thank you,I mean that it seems that the constraints doesn’t work,The model want to maxmize the value of E_ph,and I provided a constraint that E_ph<=0.5,then,cvx always provide the max(E_ph) is 0.5. and if i change the constraint to E_ph <=0.3,then ,cvx will always provide me the max(E_ph)is 0.3

Yesterday I noticed the combination of maximizing E_ph and imposing the constraint E_ph <= 0.5, but forgot to comment on it today. That seems to be a rather peculiar constraint to provide given that the objective is to maximize E_ph.

If the constraint E_ph <= 0.5 is removed from the program, the optimal value of E_ph = 1.

So if the constraint were E_ph <= q, for some number, q, then
for q < 0, problem is infeasible,
for q >= 0, optimal value of E_ph = min(q,1)

Thank you,I also find it peculiar,if i change max(E_ph) into min(E_ ph) ,does this problem is a convex? I will check it

Yes, that is convex, because the objective function is affine, which is convex when either either minimized or maximized. The optimal solution is E_ph = 0 (within solver tolerance), which of course is the case given my previous post stating the optimal solution as a function of q, as I defined it there.

As far as the combination of that objective and constraint being peculiar, that is a matter for you to consider. it is your optimization problem formulation, not mine. I have no idea what your optimization problem is supposed to represent.

maybe this problem is diffult fror cvx to optimize it ,if I change it into its dual problem,whether i can get a suitable solution,in your opinion

This problem is being easily solved by CVX and whatever solver it calls.Whether this problem formulation makes any sense for whatever real world phenomenon you are trying to model and optimize is another matter. So I don’t see how a dual formulation is going to help you unless the dual formulation is easier for you to modify into a problem which “makes sense”, or somehow avoids a coding or logic error, in the event that you made any.

okay,Thank you very much ,I will think this problem carefully

Have you ever meet this situation that because the number of constraints of a convex optimazation problem is small. Then cvx can not
give a situable solution?like this problem ,cvx directly give me the upperbound i set in the constraint as a outcome just because the number of constraints is 261,and the number of variation is about 1600

I don’t understand your question.

The number of constraints doesn’t tell you much.It matters what the constraints are. There is an important type of optimization called unconstrained optimization, in which there are no constraints, yet for many such problems, there is a finite optimal solution; for instance, minimizing a convex quadratic function.

Anyhow, maximizing a variable while imposing a constraint on the maximum value of that variable seems strange. Why do you want to do such a thing? You need to reexamne your model and model formulation.I have no idea what you are modeling; you presumably (hopefully) do.

Hello,now ,I get the correct solutions for this problem. I need its dual objective value,but the cvxr show me on the matlab window screen,How can I extract it by a command?
like this,I hope the value of dual objective can be the workspace of matlab!like this place
%E6%8D%95%E8%8E%B71

How can i do it ?Thank you !

If the problem has been solved to optimality, the dual objective equals the primal objective to within solver tolerance. You should nee it displayed in the solver output (although for the problem presented to the solver, which due to transformations by CVX, may not be the same as the objective value of the problem provided to CVX)…

I mean that I can see the dual objective value in the solver output, but I need to extract it.i need to
let the value be the workspace of matlab

HOW can I get the dual value using a command?Ii only need the dual value now

If the problem has been solved to optimality, then after CVX execution completes, cvx_optval, which contains the optimal objective value, should be both the primal and dual objective value, within solver tolerance.

Yeah,I got it now ,Thank you !