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:

ksi=0.20;       % 损耗系数的值
e_ali=0.015 ;  %校准错误率
L=80 ;            %设置距离 ,单位为km
ita_det=0.145; %设置探测器的探测效率
p_dc=6.02e-6 ; %设置暗计数率
alpha=0.1;       %设置双方发送的相干态的平均光子数
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; %计算比特误码率

m=[1 17  2  18];   %横坐标
n=[4  20  3  19];  %纵坐标
v=[1  -1  -1  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];

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];

m=[ 2 3 18 19];
n=[ 2 3 18 19];
v=[1 1 1 1];

m=[6 7 22 23];
n=[6 7 22 23];
v=[1 1 1 1];

fuzhu=[1 -1 1i -1i];%引入一个辅助向量为了计算相干态的內积
for  w=1:4  
    for  x=1:4
         for y=1:4
             for z=1:4
                  if  w < 3 
                            if y<3
                                index_0(ind)=1+2*( ~mod(w,2))+~mod(y,2);
                                 index_0(ind)=1+8+2*( ~mod(w,2))+~mod(y,2);
                            if y<3
                                 index_0(ind)=1+12+2*( ~mod(w,2))+~mod(y,2);
                                  index_0(ind)=1+4+2*( ~mod(w,2))+~mod(y,2);
                   if  x<3
                            if z < 3 
                                index_1(ind)=1+2*( ~mod(x,2))+~mod(z,2);
                                  index_1(ind)=1+8+2*( ~mod(x,2))+~mod(z,2);
                            if z<3
                                  index_1(ind)=1+12+2*( ~mod(x,2))+~mod(z,2);
                                  index_1(ind)=1+4+2*( ~mod(x,2))+~mod(z,2);


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); 

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

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 !