# Status failed but still got results

In my function
[eta_opt, eta_tcvx, q_opt]=traj_uplink_opt(B,gamma0,H,T,N,K,nodes,q_in,Ps,v_max,alpha), it containts a cvx problem.
But when I run this function, cvx shows:
Status: Failed
Optimal value (cvx_optval): NaN

But I still get results, i.e., values for q_opt.

Please help tell me why I can still get results even my cvx problem failed. I’m pretty sure that my function is a convex function
Thanks a lot!

My function is as the following:

delta_t=T/(N+1);
le=log2(exp(1));
alph=alpha;
ql=q_in;
%varu=zeros(K,N+2);

% for kk=1:K
% for n=1:N+2
% varu(kk,n)=Ps(kk)*gamma0/alph(kk,n);
% end
% end

a=zeros(K,N+2);
Rul=zeros(K,N+2);

for kk=1:K
for n=1:N+2
a(kk,n)=legamma0Ps(kk)/((H^2+(norm(ql(:,n)-nodes(:,kk)))^2)(H^2+(norm(ql(:,n)-nodes(:,kk)))^2+gamma0Ps(kk)/alph(kk,n) ));
Rul(kk,n)=-rel_entr(alph(kk,n),(alph(kk,n)(H^2+(norm(ql(:,n)-nodes(:,kk)))^2 ) +gamma0Ps(kk))/(H^2+(norm(ql(:,n) -nodes(:,kk) ))^2) )/log(2);
%alph(kk,n)*log2(1+varu(kk,n)/(H^2+(norm(ql(:,n)-nodes(:,kk)))^2));
end
end

cvx_begin
%cvx_quiet(true)
variable eta
variable q(2,N+2)
expression Ru_lb(K,N+2)

for kk=1:K
for n=1:N+2
Ru_lb(kk,n)=Rul(kk,n)-a(kk,n)*(pow_pos(norm(q(:,n)-nodes(:,kk)),2)-pow_pos(norm(ql(:,n)-nodes(:,kk)),2));
end
end

maximize (eta)
subject to
for kk=1:K
eta<=sum(Ru_lb(kk,:));
end

for n=1:N+1
norm(q(:,n+1)-q(:,n))<=v_max*delta_t;
end

q(:,1)==q(:,N+2);

cvx_end

You haven’t provided a reproducible example, so if you want any help, at least show the complete solver/CVX output from running it.

q_opt is an output argument of your function, but I don’t see in the code where you ever set its value. So I don’t know how its value relates to the value of q after CVX execution has completed.

Sorry for the inconvenience caused. The following is the whole code.

delta_t=T/(N+1);
le=log2(exp(1));
alph=alpha;
ql=q_in;
%varu=zeros(K,N+2);

% for kk=1:K
% for n=1:N+2
% varu(kk,n)=Ps(kk)*gamma0/alph(kk,n);
% end
% end

a=zeros(K,N+2);
Rul=zeros(K,N+2);

for kk=1:K
for n=1:N+2
a(kk,n)=legamma0Ps(kk)/((H^2+(norm(ql(:,n)-nodes(:,kk)))^2)(H^2+(norm(ql(:,n)-nodes(:,kk)))^2+gamma0Ps(kk)/alph(kk,n) ));
Rul(kk,n)=-rel_entr(alph(kk,n),(alph(kk,n)(H^2+(norm(ql(:,n)-nodes(:,kk)))^2 ) +gamma0Ps(kk))/(H^2+(norm(ql(:,n) -nodes(:,kk) ))^2) )/log(2);
%alph(kk,n)*log2(1+varu(kk,n)/(H^2+(norm(ql(:,n)-nodes(:,kk)))^2));
end
end

cvx_begin
%cvx_quiet(true)
variable eta
variable q(2,N+2)
expression Ru_lb(K,N+2)

for kk=1:K
for n=1:N+2
Ru_lb(kk,n)=Rul(kk,n)-a(kk,n)*(pow_pos(norm(q(:,n)-nodes(:,kk)),2)-pow_pos(norm(ql(:,n)-nodes(:,kk)),2));
end
end

maximize (eta)
subject to
for kk=1:K
eta<=sum(Ru_lb(kk,:));
end

for n=1:N+1
norm(q(:,n+1)-q(:,n))<=v_max*delta_t;
end

q(:,1)==q(:,N+2);

cvx_end

eta_tcvx=cvx_optval/(N+2);

q_opt=q;

R_final=zeros(K,N+2);
for kk=1:K
for n=1:N+2
R_final(kk,n)=-rel_entr(alph(kk,n),(alph(kk,n)(H^2+(norm(q_opt(:,n)-nodes(:,kk)))^2 ) +gamma0Ps(kk))/(H^2+(norm(q_opt(:,n) -nodes(:,kk) ))^2) )/log(2);
% =-rel_entr(alph(kk,n),(alph(kk,n)*(H^2+(norm(q_opt(:,n)-nodes(:,kk)))^2) +Ps(kk)*gamma0)/(H^2+(norm(q_opt(:,n)- nodes(:,kk) ))^2) )
end
end

R_sum=zeros(K,1);
for kk=1:K
R_sum(kk,1)=sum(R_final(kk,:))/(N+2);
end
eta_opt=R_sum;

And after running in the cvx, it shows
Calling SDPT3 4.0: 13477 variables, 6645 equality constraints
------------------------------------------------------------

** num. of constraints = 6645**
** dim. of sdp var = 3264, num. of sdp blk = 1632**
** dim. of socp var = 5199, num. of socp blk = 1733**
** dim. of linear var = 3381**
** dim. of free var = 1 *** convert ublk to lblk**

** SDPT3: Infeasible path-following algorithms**

** version predcorr gam expon scale_data**
** HKM 1 0.000 1 0 **
it pstep dstep pinfeas dinfeas gap prim-obj dual-obj cputime
-------------------------------------------------------------------
** 0|0.000|0.000|1.7e+02|1.4e+03|2.6e+10| 4.081630e-08 0.000000e+00| 0:0:00| spchol 1 1 **
** 1|0.113|0.185|1.5e+02|1.2e+03|3.2e+10| 1.772424e+04 3.871748e+07| 0:0:00| spchol 1 1 **
** 2|0.114|0.135|1.3e+02|1.0e+03|3.0e+10| 3.587738e+04 3.632560e+07| 0:0:00| spchol 1 1 **
** 3|0.721|0.065|3.7e+01|9.4e+02|1.2e+10| 1.305238e+05 3.753357e+07| 0:0:00| spchol 1 1 **
** 4|0.326|0.729|2.5e+01|2.5e+02|4.4e+09| 1.443765e+05 -7.080895e+06| 0:0:00| spchol 1 1 **
** 5|0.887|0.527|2.8e+00|1.2e+02|1.3e+09| 1.695684e+05 -2.865620e+06| 0:0:00| spchol 1 1 **
** 6|0.747|0.859|7.1e-01|1.7e+01|2.4e+08| 1.710342e+05 1.775558e+07| 0:0:01| spchol 1 1 **
** 7|0.661|0.648|2.4e-01|6.0e+00|8.6e+07| 1.590333e+05 2.975769e+07| 0:0:01| spchol 1 1 **
** 8|0.569|0.375|1.0e-01|3.7e+00|5.6e+07| 1.361988e+05 3.216563e+07| 0:0:01| spchol 1 1 **
** 9|0.569|0.317|4.5e-02|2.5e+00|4.2e+07| 1.073565e+05 3.090551e+07| 0:0:01| spchol 1 1 **
**10|0.631|0.239|1.6e-02|1.9e+00|3.6e+07| 7.568250e+04 2.696952e+07| 0:0:01| spchol 1 1 **
**11|0.491|0.493|8.4e-03|9.8e-01|2.1e+07| 5.564783e+04 1.498466e+07| 0:0:01| spchol 1 1 **
**12|1.000|0.595|3.9e-09|4.0e-01|1.2e+07| 2.087686e+04 4.751042e+06| 0:0:01| spchol 1 1 **
**13|0.826|0.961|2.2e-09|1.6e-02|4.9e+05| 6.958490e+03 1.792375e+05| 0:0:01| spchol 1 1 **
**14|0.631|0.186|9.6e-10|1.3e-02|4.3e+05| 5.574644e+03 1.395967e+05| 0:0:01| spchol 1 1 **
**15|0.971|0.380|7.6e-10|7.9e-03|3.1e+05| 4.419782e+03 7.373608e+04| 0:0:01| spchol 1 1 **
**16|1.000|0.293|5.4e-10|5.6e-03|2.6e+05| 3.721600e+03 4.515595e+04| 0:0:01| spchol 1 1 **
**17|1.000|0.324|4.0e-10|3.8e-03|2.0e+05| 3.160038e+03 2.420602e+04| 0:0:01| spchol 1 1 **
**18|1.000|0.330|1.2e-10|2.5e-03|1.5e+05| 2.635487e+03 1.196083e+04| 0:0:01| spchol 1 1 **
**19|1.000|0.292|3.2e-10|1.8e-03|1.2e+05| 2.266186e+03 5.149631e+03| 0:0:02| spchol 1 1 **
**20|1.000|0.312|3.1e-10|1.2e-03|9.5e+04| 1.891072e+03 9.081785e+02| 0:0:02| spchol 1 1 **
**21|1.000|0.291|8.2e-10|8.7e-04|7.7e+04| 1.567114e+03 -1.478347e+03| 0:0:02| spchol 1 1 **
**22|1.000|0.297|9.8e-10|6.1e-04|6.2e+04| 1.253093e+03 -2.782976e+03| 0:0:02| spchol 1 2 **
**23|1.000|0.294|1.8e-10|4.3e-04|5.0e+04| 9.828205e+02 -3.433954e+03| 0:0:02| spchol 2 2 **
**24|1.000|0.298|2.2e-10|3.0e-04|4.0e+04| 7.353685e+02 -3.625107e+03| 0:0:02| spchol 2 2 **
**25|1.000|0.298|5.0e-10|2.1e-04|3.3e+04| 5.363754e+02 -3.557738e+03| 0:0:02| spchol 2 2 **
**26|1.000|0.305|2.0e-10|1.5e-04|2.6e+04| 3.739646e+02 -3.302486e+03| 0:0:02| spchol 2 2 **
**27|1.000|0.308|5.0e-10|1.0e-04|2.0e+04| 2.537248e+02 -2.949169e+03| 0:0:02| spchol 2 2 **
**28|1.000|0.315|5.3e-10|7.0e-05|1.6e+04| 1.670895e+02 -2.540968e+03| 0:0:02| spchol 2 2 **
**29|1.000|0.321|1.6e-09|4.8e-05|1.2e+04| 1.066574e+02 -2.120916e+03| 0:0:02| spchol 2 2 **
**30|1.000|0.318|4.4e-09|3.3e-05|9.0e+03| 6.463155e+01 -1.738935e+03| 0:0:02| spchol 2 2 **
**31|1.000|0.325|4.9e-09|2.2e-05|6.7e+03| 3.358837e+01 -1.392521e+03| 0:0:02| spchol 2 2 **
**32|1.000|0.326|3.7e-09|1.5e-05|4.9e+03| 1.067472e+01 -1.099463e+03| 0:0:03| spchol 2 3 **
**33|1.000|0.323|8.8e-09|1.0e-05|3.6e+03|-5.839042e+00 -8.639965e+02| 0:0:03| spchol 2 3 **
**34|1.000|0.300|1.8e-08|7.0e-06|2.7e+03|-1.596699e+01 -6.970162e+02| 0:0:03| spchol 3 3 **
**35|1.000|0.319|2.2e-08|4.8e-06|2.0e+03|-2.534352e+01 -5.528137e+02| 0:0:03| spchol 3 3 **
**36|1.000|0.366|1.4e-08|3.0e-06|1.3e+03|-3.635054e+01 -4.135729e+02| 0:0:03| spchol 3 3 **
**37|1.000|0.318|3.7e-08|2.1e-06|9.6e+02|-4.372234e+01 -3.276042e+02| 0:0:03| spchol 3 4 **
**38|1.000|0.353|5.6e-08|1.3e-06|6.5e+02|-5.053225e+01 -2.532294e+02| 0:0:03| spchol 3 4 **
**39|1.000|0.338|4.7e-08|8.9e-07|4.5e+02|-5.584460e+01 -2.020735e+02| 0:0:03| spchol 4 4 **
**40|1.000|0.250|2.7e-07|6.8e-07|3.6e+02|-5.776198e+01 -1.774131e+02| 0:0:03| spchol 4 4 **
**41|1.000|0.356|1.4e-07|4.4e-07|2.6e+02|-6.100049e+01 -1.476058e+02| 0:0:03| spchol 4 5 **
**42|1.000|0.339|8.6e-08|3.1e-07|1.9e+02|-6.348153e+01 -1.276891e+02| 0:0:03| spchol 4 5 **
**43|1.000|0.400|2.8e-07|1.9e-07|1.3e+02|-6.603526e+01 -1.100743e+02| 0:0:03| spchol 5 6 **
**44|1.000|0.382|3.0e-07|1.2e-07|9.1e+01|-6.814731e+01 -9.875679e+01| 0:0:03| spchol 5 6 **
**45|1.000|0.206|7.3e-08|1.0e-07|8.5e+01|-6.755195e+01 -9.573191e+01| 0:0:04| spchol 5 6 **
**46|1.000|0.475|4.5e-07|5.8e-08|5.2e+01|-6.968607e+01 -8.788571e+01| 0:0:04| spchol 7 8 **
**47|1.000|0.240|7.1e-07|4.8e-08|4.6e+01|-6.963290e+01 -8.607387e+01| 0:0:04| spchol 9 10 **
**48|1.000|0.433|9.4e-07|2.9e-08|3.1e+01|-7.109770e+01 -8.250902e+01| 0:0:04| spchol 10 11 **
**49|1.000|0.305|1.1e-06|2.2e-08|2.5e+01|-7.151620e+01 -8.098902e+01| 0:0:04| spchol 12 14 **
**50|1.000|0.363|1.4e-06|1.6e-08|1.8e+01|-7.216906e+01 -7.946629e+01| 0:0:04| spchol 13 13 **
**51|1.000|0.366|1.2e-06|1.1e-08|1.3e+01|-7.272953e+01 -7.825701e+01| 0:0:04| spchol 15 16 **
**52|1.000|0.371|3.2e-06|7.9e-09|9.6e+00|-7.322921e+01 -7.730514e+01| 0:0:04| spchol 21 25 **
**53|1.000|0.371|5.5e-06|5.7e-09|6.9e+00|-7.344824e+01 -7.658852e+01| 0:0:04| spchol 25 26 **
**54|1.000|0.368|6.9e-07|4.2e-09|4.9e+00|-7.380839e+01 -7.606266e+01| 0:0:04| spchol **
** warning: symqmr failed: 0.3 **
** switch to LU factor. splu 23 7 **
**55|1.000|0.379|5.6e-06|3.0e-09|3.5e+00|-7.393687e+01 -7.565651e+01| 0:0:05| splu 25 ^ 2 **
**56|1.000|0.239|1.9e-06|2.7e-09|3.3e+00|-7.391560e+01 -7.552509e+01| 0:0:05| splu 25 15 **
**57|0.925|0.358|1.2e-05|2.1e-09|2.6e+00|-7.381186e+01 -7.534775e+01| 0:0:05| splu 30 10 **
**58|0.819|0.399|4.8e-06|1.5e-09|1.9e+00|-7.421295e+01 -7.516090e+01| 0:0:05| splu 30 30 **
59|0.557|0.250|3.8e-04|1.4e-09|1.7e+00|-8.028812e+01 -7.506155e+01| 0:0:05| splu 20 30 **
60|0.676|0.218|1.2e-04|1.4e-09|1.6e+00|-7.612973e+01 -7.502841e+01| 0:0:05| splu 24 ^ 9 **
61|1.000|0.234|4.8e-06|1.3e-09|1.6e+00|-7.409898e+01 -7.499200e+01| 0:0:06| splu 30 30 **
62|0.058|0.045|5.9e-06|1.5e-09|1.7e+00|-7.412050e+01 -7.498537e+01| 0:0:06| splu 18 4 **
63|0.831|0.263|4.4e-06|1.3e-09|1.3e+00|-7.422101e+01 -7.493560e+01| 0:0:06| splu 30 ^16 **
64|0.022|0.021|5.4e-06|1.5e-09|1.5e+00|-7.424598e+01 -7.493714e+01| 0:0:06| splu 21 4 **
65|0.629|0.098|2.5e-06|1.7e-09|1.5e+00|-7.424680e+01 -7.492644e+01| 0:0:06| splu 24 ^15 **
66|0.097|0.119|3.8e-06|1.7e-09|1.6e+00|-7.430308e+01 -7.492552e+01| 0:0:06| splu 25 4 **
67|0.809|0.265|7.4e-07|1.5e-09|1.4e+00|-7.429567e+01 -7.489488e+01| 0:0:06| splu 17 30 **
68|0.030|0.027|2.3e-05|1.7e-09|1.5e+00|-7.464496e+01 -7.489676e+01| 0:0:07| splu 13 3 **
69|0.479|0.138|1.2e-05|1.7e-09|1.5e+00|-7.450166e+01 -7.488050e+01| 0:0:07| splu 30 8 **
70|1.000|0.210|5.7e-06|1.6e-09|1.3e+00|-7.445975e+01 -7.485465e+01| 0:0:07| splu 30 30 **
71|0.854|0.225|8.4e-06|1.5e-09|1.3e+00|-7.440827e+01 -7.484762e+01| 0:0:07| splu 30 20 **
72|0.220|0.236|5.3e-06|1.4e-09|1.3e+00|-7.433286e+01 -7.485923e+01| 0:0:07| splu 30 8 **
73|0.693|0.163|2.3e-06|1.4e-09|1.3e+00|-7.423073e+01 -7.485581e+01| 0:0:07| splu 30 ^23 **
74|0.323|0.281|1.5e-05|1.2e-09|1.2e+00|-7.451688e+01 -7.484220e+01| 0:0:08|
** stop: progress is too slow

-------------------------------------------------------------------
** number of iterations = 74

** primal objective value = -7.45168788e+01

** dual objective value = -7.48421968e+01

** gap := trace(XZ) = 1.18e+00

** relative gap = 7.84e-03

** actual relative gap = 2.16e-03

** rel. primal infeas (scaled problem) = 1.55e-05

** rel. dual " " " = 1.20e-09

** rel. primal infeas (unscaled problem) = 0.00e+00

** rel. dual " " " = 0.00e+00

** norm(X), norm(y), norm(Z) = 1.0e+09, 5.4e-01, 5.4e-01

** norm(A), norm(b), norm© = 1.2e+02, 6.4e+04, 2.4e+00

** Total CPU time (secs) = 7.52 **
** CPU time per iteration = 0.10 **
** termination code = -5

** DIMACS: 4.4e-04 0.0e+00 1.4e-09 0.0e+00 2.2e-03 7.8e-03

-------------------------------------------------------------------

------------------------------------------------------------
Status: Failed
Optimal value (cvx_optval): NaN

But I can still get values for q.

Thanks a lot.

I think that I have solved the problem. The reason is that some values in my function are too small sometimes, making it extremely hard for cvx to perform.

Thanks for the help.

Hello! I have the same question with you.How do you solved it?

In the original post I see

norm(X), norm(y), norm(Z) = 1.0e+09, 5.4e-01, 5.4e-0

so that means the primal solution is very large i.e. norm(X)=1e9. That is an indication of a bad model. How to fix that is model dependent i.e. you should use your knowledge of the model to understand what is wrong with it.

Hello，I have the same problem, how do you solve it?

hello ,did you solve it now

The issue is most likely a badly formulated problem. So either he/she reformulated the problem or did something else.

You can try using another optimizer like Mosek.

The reason is that sometimes CVX will break due to the convergence requirement. I think you can try to multiply a constant in your objective to control the convergence of the CVX.

Thanks for your replay,I’ll try it ! Thank you very much!

hello,this method does not work for my code. The left and right sides of my equation constraint are always a little different. Are you also studying drones, can I discuss some problem with you?