# The solution of cvx

Thank you !Hope you can help me take a look at this problem.

You haven’t shown us the output. We don’t even know what solution method was used. Note that constrains are not satisfied exactly, but only to within a tolerance. And CVX reported that your problem was solved inaccurately. It is possible that your input data is not well-scaled.

Sorry，This is my code and output.
function [Q_,P_] = CVX_theta_Optimal(M,P_max,K,Z,v,q,p,BER)

cvx_solver mosek
cvx_begin
cvx_quiet false;
variable Q(M+1,M+1) hermitian semidefinite

``````expression F(K)
expression G(K)
expression P(K)

for i=1:K
if i == 1
s_inter = 0;
G_tmp = 0;
else
s_inter = 0;
G_tmp = 0;
for j=1:i-1
s_inter = p(j).*(trace(Z(:,:,j)*q)+ sum(abs(v(:,i)).^2)) + s_inter;
G_tmp = G_tmp + Z(:,:,j).';
end
end
G_gradient = G_tmp/log(2)*(s_inter+1);
G(i) = real((s_inter+1))/log(2)+2*real(trace(G_gradient.'*(Q-q)));
F(i) = -(-rel_entr(1,(real(trace(Z(:,:,i)*Q)+sum(abs(v(:,i)).^2)))))/log(2);
end
%expression N
%norm_grad = two_norm_grad(q);
%N = norm_nuc(Q)-norm(q)+2*real(trace(norm_grad*norm_grad'*(Q-q)));
minimize sum(P)
subject to
diag(Q) == 1 ;

for i=1:K
0<=P(i)<=P_max;
end

for i=1:K
P(i)-exp(log(2)*(log(2.^(1+(sqrt(1/200)*qfuncinv(BER)/log(2)))-1)/log(2)+real(G(i)+F(i))))>=0;
end

%N = 0;
``````

cvx_end
%Q
P
Q_ = Q;
P_ = P;

## Cones | Errors | Mov/Act | Centering Exp cone Poly cone | Status --------±--------------------------------±-------- 0/ 2 | 8.000e+00 6.868e+02 3.299e+43 | Infeasible

Status: Infeasible
Optimal value (cvx_optval): +Inf

P =

NaN
NaN
NaN
NaN

I don’t know why this problem occurs. I don’t know how to modify my code to make it run normally. Please help me, thank you!!!

Sorry，This is my code and output.

Follow the advice in the link in my previous post.

if the problem is still reported infeasible, follow the advice (except for section 1) at https://yalmip.github.io/debugginginfeasible .

Thank you very much！

Actually, as I wrote in the other thread, make sure you are using CVX 2.2 and Mosek 9.x. Otherwise you would not be getting the output with Cones | Errors … which shows the Successive approximation method was used.

OK，Thank you！I change my CVX version.

I have another question, when should I use cvx_quad?

As long as your problem can reformulated using the exponential cone and symmetric cones you should not use it.

Thank you very much!

I have another question that needs your help

When I solving the SOCP problem, the output is Nan?
this my problem

This is my code and output.
%% 参数
clc;clear ;
Z_mc=1;
c=3e8;
f =28e9;%f=18.5e+9; 8e-3=0.008 0.5lambda
lambda=c/f;
dx=5e-3;% 0.5lambda
dy=dx;
Ny=8;Nx=8;
kc=1j *2 *pi /lambda;
theta_0=0;%目标角度 *pi/180
phi_0=0;
% theta_i=30;%干扰角度 *pi/180
% phi_i=0;
% INR=30;
u=10.^(1./10);%主瓣阈值（上限）
l=10.^(-1./10);%主瓣阈值（下限）
taos=0.001;%旁瓣阈值（上限）30dB taos=0.001;%旁瓣阈值（上限）=10.^(-30./10); -30db
%% 目标导向矢量
a0_x=exp(kc *(0:Nx-1)’ *dx *sin(theta_0 *pi/180) *cos(phi_0 *pi/180));
a0_y=exp(kc *(0:Ny-1)’ *dy *sin(theta_0 *pi/180) *sin(phi_0 pi/180));
a0=kron(a0_x, a0_y);%导向矢量
a=a0’ Z_mc;%耦合导向矢量 1N
%% 主瓣导向矢量
theta_m=(-10:10);
phi_m=(-10:10);
M =length(theta_m);
for m=1:M
am_x=exp(kc * (0:Nx-1)’ * dx * sin(theta_m(m) * pi/180) * cos(phi_m(m) * pi/180));
am_y=exp(kc * (0:Ny-1)’ * dy * sin(theta_m(m) * pi/180) * sin(phi_m(m) * pi/180));
a10=kron(am_x, am_y);%导向矢量
a1(m,:)=a10’ * Z_mc;%耦合导向矢量 1N
end
%% 旁瓣导向矢量
theta_s=[-91:4:-9,11:4:91];
phi_s=[-91:4:-9,11:4:91];
S =length(theta_s);
for s=1:S
as_x=exp(kc * (0:Nx-1)’ * dx * sin(theta_s(s) * pi/180) * cos(phi_s(s) pi/180));
as_y=exp(kc * (0:Ny-1)’ * dy * sin(theta_s(s) * pi/180) * sin(phi_s(s) * pi/180));
a20=kron(as_x, as_y);%导向矢量
a2(s,:)=a20’ * Z_mc;%耦合导向矢量 1N
end
N=Ny * Nx;
%% cvx
yita=(u-l) * sqrt(Ny * Nx)/2;%导向矢量误差
cvx_begin
cvx_solver SeDuMi
variable w(N) complex %N1
minimize(norm(w))%优化目标
subject to
a * w==1;
for m=1:1:M
real(a1(m, : ) * w) -yita * norm(w) >= l;%
norm(a1(m, : ) * w)+yita * norm(w) <= u;%
end
for s=1:1:S
norm(a2(s,: ) * w) +yita * norm(w)<= taos;%
end
cvx_end
% wopt=w% N1

This is answered in When I solving the SOCP problem, the output is Nan? .

May I define a convex function in cvx, my goal is to minimize it, but why does it keep increasing every iteration?

You have to show much more clearly what you’re talking about.

This is my code:
cvx_solver mosek
cvx_begin
cvx_quiet false;
variable Q(M+1,M+1) hermitian semidefinite
variable P(K)
expression I2(K)
expression I3(K)

``````for i=1:K
s_inter = 0;
G_tmp = 0;
for j =1:K
if i ==j
continue
else
v = W(:,i)'*H_IC(:,j);
g = diag((H_IU(:,j))')*H_UC*W(:,i);
Z(1:M, :) = [g*g',g*v];
Z(M+1,:) = [g'*v',0];
s_inter = p(j).*(trace(Z*q)+abs(v).^2) + s_inter;
G_tmp = p(j).*Z'+G_tmp;
end
end
G_gradient = G_tmp./(log(2)*(s_inter+B*N_0));
I2(i) = log(real(s_inter+B*N_0))/log(2)+2*real(trace(G_gradient'*(Q-q)));

v = W(:,i)'*H_IC(:,i);
g = diag((H_IU(:,i))')*H_UC*W(:,i);
Z(1:M,:)  = [ g*g', g*v];
Z(M+1,:) = [ g'*v', 0  ];
I3(i) = -rel_entr(1,real(trace(Z*Q))+abs(v).^2)/log(2);
end

minimize sum(P)
subject to
diag(Q) == 1;
for i =1:K
P(i)>=exp(log(2)*((log(2.^(I1))-1)/log(2)+real(I2(i)-I3(i))));
end
0<=P<=P_max;
``````

cvx_end
Q_ = Q;
P_ = P;
P

# ===================================== Using Pade approximation for exponential cone with parameters m=3, k=3

## Calling Mosek 9.1.9: 4325 variables, 129 equality constraints

MOSEK Version 9.1.9 (Build date: 2019-11-21 11:34:40)
Copyright © MOSEK ApS, Denmark. WWW: mosek.com
Platform: Windows/64-X86

Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 129
Cones : 28
Scalar variables : 100
Matrix variables : 1
Integer variables : 0

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries : 1 time : 0.00
Lin. dep. - tries : 1 time : 0.00
Lin. dep. - number : 0
Presolve terminated. Time: 0.01
Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 129
Cones : 28
Scalar variables : 100
Matrix variables : 1
Integer variables : 0

Optimizer - threads : 8
Optimizer - solved problem : the primal
Optimizer - Constraints : 93
Optimizer - Cones : 28
Optimizer - Scalar variables : 88 conic : 84
Optimizer - Semi-definite variables: 1 scalarized : 8515
Factor - setup time : 0.00 dense det. time : 0.00
Factor - ML order time : 0.00 GP order time : 0.00
Factor - nonzeros before factor : 2765 after factor : 2773
Factor - dense dim. : 0 flops : 5.30e+07
ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME
0 4.8e+07 1.3e+00 1.0e+01 0.00e+00 1.985282281e-03 -9.220408006e+00 1.0e+00 0.05
1 8.6e+06 2.3e-01 4.8e+00 -1.00e+00 6.947473631e-03 -5.831348329e+00 1.8e-01 0.13
2 1.1e+06 3.1e-02 1.7e+00 -1.00e+00 4.734922348e-02 3.052093480e+01 2.4e-02 0.13
3 4.7e+04 1.3e-03 3.4e-01 -1.00e+00 1.030762272e+00 1.010340429e+03 9.8e-04 0.14
4 2.9e+03 7.9e-05 8.5e-02 -1.00e+00 1.566427960e+01 1.640517298e+04 6.1e-05 0.16
5 1.0e+02 2.7e-06 1.6e-02 -9.98e-01 4.369217326e+02 4.564408672e+05 2.1e-06 0.17
6 3.9e+01 1.0e-06 8.9e-03 -9.21e-01 1.671467397e+03 1.027177482e+06 8.1e-07 0.17
7 3.2e+01 8.6e-07 4.3e-03 1.67e-01 1.871035388e+03 3.555119483e+05 6.7e-07 0.19
8 1.1e+01 2.9e-07 5.5e-04 6.19e-01 2.758741115e+03 5.351320824e+04 2.2e-07 0.20
9 1.9e+00 5.1e-08 3.7e-05 1.04e+00 3.261105836e+03 1.065715728e+04 4.0e-08 0.22
10 5.7e-01 1.5e-08 7.5e-06 1.06e+00 3.583424306e+03 6.954712889e+03 1.2e-08 0.22
11 2.6e-01 7.0e-09 2.5e-06 1.02e+00 3.504456470e+03 5.318049222e+03 5.4e-09 0.23
12 5.3e-02 1.4e-09 2.5e-07 1.03e+00 2.873888100e+03 3.284661117e+03 1.1e-09 0.25
13 2.5e-02 6.7e-10 8.0e-08 1.01e+00 1.662255777e+03 1.866620014e+03 5.2e-10 0.25
14 5.4e-03 1.5e-10 8.3e-09 1.01e+00 5.579687882e+02 6.040153839e+02 1.1e-10 0.27
15 1.2e-03 3.2e-11 8.6e-10 1.02e+00 1.685801619e+02 1.790399530e+02 2.5e-11 0.28
16 3.1e-04 9.6e-12 1.1e-10 1.02e+00 9.193510716e+01 9.462730927e+01 6.4e-12 0.30
17 1.7e-04 6.0e-12 4.8e-11 1.01e+00 5.969287090e+01 6.122504564e+01 3.6e-12 0.31
18 7.7e-05 5.4e-12 1.4e-11 1.01e+00 4.766596104e+01 4.835464855e+01 1.6e-12 0.31
19 3.8e-05 1.7e-12 5.0e-12 1.00e+00 3.488359988e+01 3.522548797e+01 7.9e-13 0.33
20 1.1e-05 1.8e-12 8.1e-13 1.00e+00 2.930845504e+01 2.941016153e+01 2.3e-13 0.34
21 6.0e-06 1.5e-12 3.2e-13 1.00e+00 2.728598859e+01 2.734125058e+01 1.3e-13 0.34
22 1.5e-06 9.1e-13 3.8e-14 1.00e+00 2.619334496e+01 2.620677866e+01 3.1e-14 0.36
23 3.4e-07 1.9e-12 4.3e-15 1.00e+00 2.586872102e+01 2.587184084e+01 7.0e-15 0.38
24 4.0e-09 3.7e-12 5.6e-18 1.00e+00 2.579107750e+01 2.579111504e+01 8.5e-17 0.39
25 4.7e-11 6.1e-11 6.7e-21 1.00e+00 2.579012768e+01 2.579012812e+01 9.9e-19 0.39
26 5.2e-12 2.3e-10 1.7e-22 1.00e+00 2.579011710e+01 2.579011715e+01 1.1e-19 0.42
Optimizer terminated. Time: 0.45

Interior-point solution summary
Problem status : PRIMAL_AND_DUAL_FEASIBLE
Solution status : OPTIMAL
Primal. obj: 2.5790117104e+01 nrm: 3e+04 Viol. con: 2e-09 var: 0e+00 barvar: 0e+00 cones: 0e+00
Dual. obj: 2.5790117153e+01 nrm: 2e+05 Viol. con: 0e+00 var: 3e-10 barvar: 9e-15 cones: 0e+00
Optimizer summary
Optimizer - time: 0.45
Interior-point - iterations : 26 time: 0.42
Basis identification - time: 0.00
Primal - iterations : 0 time: 0.00
Dual - iterations : 0 time: 0.00
Clean primal - iterations : 0 time: 0.00
Clean dual - iterations : 0 time: 0.00
Simplex - time: 0.00
Primal simplex - iterations : 0 time: 0.00
Dual simplex - iterations : 0 time: 0.00
Mixed integer - relaxations: 0 time: 0.00

Status: Solved
Optimal value (cvx_optval): +25.7901

P =

6.654200333471935
5.627650485544604
6.552132903557885
6.956133381700099

# ===================================== Using Pade approximation for exponential cone with parameters m=3, k=3

## Calling Mosek 9.1.9: 4325 variables, 129 equality constraints

MOSEK Version 9.1.9 (Build date: 2019-11-21 11:34:40)
Copyright © MOSEK ApS, Denmark. WWW: mosek.com
Platform: Windows/64-X86

Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 129
Cones : 28
Scalar variables : 100
Matrix variables : 1
Integer variables : 0

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries : 1 time : 0.00
Lin. dep. - tries : 1 time : 0.00
Lin. dep. - number : 0
Presolve terminated. Time: 0.01
Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 129
Cones : 28
Scalar variables : 100
Matrix variables : 1
Integer variables : 0

Optimizer - threads : 8
Optimizer - solved problem : the primal
Optimizer - Constraints : 93
Optimizer - Cones : 28
Optimizer - Scalar variables : 88 conic : 84
Optimizer - Semi-definite variables: 1 scalarized : 8515
Factor - setup time : 0.00 dense det. time : 0.00
Factor - ML order time : 0.00 GP order time : 0.00
Factor - nonzeros before factor : 2765 after factor : 2773
Factor - dense dim. : 0 flops : 5.30e+07
ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME
0 7.5e+03 1.3e+00 1.0e+01 0.00e+00 1.154690662e-02 -9.220408006e+00 1.0e+00 0.05
1 1.3e+03 2.3e-01 4.3e+00 -9.99e-01 3.310482915e-02 -4.614270175e+00 1.8e-01 0.13
2 1.8e+02 3.2e-02 1.6e+00 -9.95e-01 2.255994396e-01 3.016819067e+01 2.4e-02 0.14
3 4.6e+01 7.8e-03 7.4e-01 -9.56e-01 1.060406638e+00 1.358034286e+02 6.1e-03 0.16
4 3.1e+01 5.4e-03 3.5e-01 -3.39e-01 2.531267504e+00 6.409488750e+01 4.2e-03 0.17
5 1.3e+01 2.2e-03 5.1e-02 7.84e-01 3.644766333e+00 1.044192239e+01 1.7e-03 0.19
6 2.5e+00 4.3e-04 4.4e-03 9.49e-01 4.315441514e+00 5.539103185e+00 3.4e-04 0.20
7 9.1e-01 1.6e-04 1.1e-03 1.02e+00 5.005675757e+00 5.727042348e+00 1.2e-04 0.20
8 4.0e-01 6.9e-05 3.7e-04 1.01e+00 5.126397702e+00 5.527861288e+00 5.3e-05 0.22
9 2.4e-01 4.2e-05 1.9e-04 9.65e-01 5.128492385e+00 5.406441107e+00 3.2e-05 0.23
10 1.0e-01 1.7e-05 5.7e-05 9.07e-01 5.546186966e+00 5.698842980e+00 1.3e-05 0.23
11 7.7e-02 1.3e-05 4.2e-05 6.52e-01 6.459654653e+00 6.609832253e+00 1.0e-05 0.25
12 3.0e-02 5.1e-06 1.5e-05 5.37e-01 9.519610927e+00 9.642596720e+00 3.9e-06 0.27
13 1.5e-02 2.5e-06 7.1e-06 1.97e-01 1.348392065e+01 1.360469049e+01 1.9e-06 0.28
14 8.7e-03 1.5e-06 4.4e-06 8.72e-02 1.660932947e+01 1.674692787e+01 1.1e-06 0.28
15 4.0e-03 6.9e-07 2.2e-06 2.54e-02 2.192154533e+01 2.207703713e+01 5.3e-07 0.30
16 1.7e-03 2.9e-07 1.3e-06 -4.42e-01 2.345589745e+01 2.378825079e+01 2.3e-07 0.31
17 1.1e-04 1.9e-08 3.4e-07 -7.58e-01 2.038652157e+01 2.529092209e+01 1.5e-08 0.31
18 2.2e-07 3.5e-10 1.5e-08 -9.86e-01 2.178143070e+01 2.427705906e+03 2.9e-11 0.33
19 4.3e-10 6.6e-10 6.6e-10 -1.00e+00 2.178143150e+01 1.231837802e+06 5.8e-14 0.34
20 8.5e-13 8.8e-10 1.1e-12 -1.00e+00 2.178143176e+01 6.306895837e+08 1.1e-16 0.36
21 8.5e-13 8.8e-10 1.1e-12 -1.00e+00 2.178143176e+01 6.306895837e+08 1.1e-16 0.39
22 1.7e-15 2.4e-11 1.7e-11 -1.00e+00 2.178143172e+01 3.229130031e+11 2.2e-19 0.41
23 1.7e-15 2.4e-11 1.7e-11 -1.00e+00 2.178143172e+01 3.229130031e+11 2.2e-19 0.45
24 1.7e-15 2.4e-11 1.7e-11 -1.00e+00 2.178143172e+01 3.229130031e+11 2.2e-19 0.50
Optimizer terminated. Time: 0.56

Interior-point solution summary
Problem status : PRIMAL_INFEASIBLE
Solution status : PRIMAL_INFEASIBLE_CER
Dual. obj: 2.0432106424e-04 nrm: 9e+01 Viol. con: 0e+00 var: 2e-11 barvar: 3e-17 cones: 0e+00
Optimizer summary
Optimizer - time: 0.56
Interior-point - iterations : 25 time: 0.53
Basis identification - time: 0.00
Primal - iterations : 0 time: 0.00
Dual - iterations : 0 time: 0.00
Clean primal - iterations : 0 time: 0.00
Clean dual - iterations : 0 time: 0.00
Simplex - time: 0.00
Primal simplex - iterations : 0 time: 0.00
Dual simplex - iterations : 0 time: 0.00
Mixed integer - relaxations: 0 time: 0.00

Status: Infeasible
Optimal value (cvx_optval): +Inf

It can get the result within a section but not iterate many times, I suspect my SCA is not stable, but I don’t know how to modify it

You have not shown the “SCA” portion of the code.

Yes, SCA can diverge to infeasibility, or wilder and wilder solutions, of whatever. You can search this forum for my advice on SCA.

Given that you are using Mosek, you will be better off replacing CVXQUAD’s exponential.m with the original CVX version. Then CVXQUAD will not be invoked, and you will get faster and more reliable solution using Mosek without CVXQUAD. But even if you do that, it is not a magic cure for SCA.

If I change it this way and it still doesn’t work, will I switch to a different solver with feasible results, such as Yamlip

Try using a non-convex nonlinear solver in YALMIP if your original problem is non-convex, as I presume it is if you are using SCA.