# Why do I get the solution as a sparse matrix and not a complex matrix

``````clear all;
clc;
para.K=2;
para.Nt=8;
para.M=20;
para.SINRu=10^(0.1*-10);
para.SINRm=10^(0.1*-10);
para.Power=20;

theta=exp(1i*rand(para.M,1)*2*pi);
Theta=diag(theta);

Noise_Power=10^(0.1*(-150));
%% Get the effective channel
[Channel_BI,Channel_IuU,Channel_ImU,Channel_uUmU,g]=Channel(para);

Channel_k=zeros(1,para.Nt);
Hk=zeros(para.Nt,para.Nt);
Channel_k=Channel_ImU'*Theta*Channel_BI;
Channel_k=Channel_k/sqrt(Noise_Power);
Hk=Channel_k*Channel_k';

Channel_K=zeros(1,para.Nt);
HK=zeros(para.Nt,para.Nt);
Channel_K=Channel_IuU'*Theta*Channel_BI;
Channel_K=Channel_K/sqrt(Noise_Power);
HK=Channel_K*Channel_K';

beta_0=0.5;
%% Get the initialization of the Wu,Wm
% [Wu_0,Wm_0]=Initialization_W_beta(para,HK,Hk,g,beta_0);
wu_0=randn(para.Nt,1)+1i*randn(para.Nt,1);
wu_0=sqrt(0.5*para.Power*rand)*wu_0/norm(wu_0,'fro');
Wu_0=wu_0*wu_0';

wm_0=randn(para.Nt,1)+1i*randn(para.Nt,1);
wm_0=sqrt(0.5*para.Power*rand)*wm_0/norm(wm_0,'fro');
Wm_0=wm_0*wm_0';

l0=trace(Hk*Wm_0)/(trace(Hk*Wu_0)+1);
e=sqrt(trace(Hk*Wu_0)/l0);
q0=sqrt(beta_0*g*trace(HK*(Wm_0+Wu_0)));
m0=sqrt((1-beta_0)*trace(HK*Wu_0));
Initial_Value=min(trace(Wu_0+Wm_0));
Record1=[Initial_Value];

Flag1=1;
Counter=0;
Max_Times=19;
while Flag1
Counter=Counter+1;

cvx_begin quiet
cvx_solver mosek%SDPT3%SeDuMi%mosek
cvx_expert true
variable beta1
variable Wu(para.Nt,para.Nt) complex %hermitian
variable Wm(para.Nt,para.Nt) complex %hermitian
variable l
variable q
variable m

Wu==hermitian_semidefinite(para.Nt);
Wm==hermitian_semidefinite(para.Nt);

2*real(m0*m)-square_abs(m0)>=para.SINRu;

beta1>=0;
beta1<=1;

real(para.SINRm*trace(HK*Wu))+para.SINRm*inv_pos(1-beta1)-real(trace(HK*Wm))<=0;

square_abs(e*l)+square_abs(trace(Hk*Wu)/e)<=2*real(trace(Hk*Wm))-2*l;

[beta1*g,q;q,trace(HK*(Wu+Wm))]==hermitian_semidefinite(2);

real(2*real(q0*q)-square_abs(real(q0)))>=para.SINRm-l;

[1-beta1,m;m,trace(HK*Wu)]==hermitian_semidefinite(2);

real(trace(Wu+Wm))<=10;

minimize(real(trace(Wu+Wm)))
cvx_end

Flagg=1;
if strcmp(cvx_status,'Solved') || strcmp(cvx_status,'Inaccurate/Solved')
Updated_l=l;
Updated_q=q;
Updated_m=m;
Updated_e=sqrt(trace(Hk*Wu)/l0);
Updated_Wu=Wu;
Updated_Wm=Wm;
Updated_beta1=beta1;
Updated_Value=cvx_optval;
else
Flagg=0;
break;
end

Record1=[Record1,Updated_Value];
if Counter>Max_Times
Flag1=0;
Final_Wu=Updated_Wu;
Final_Wm=Updated_Wm;
Final_beta1=Updated_beta1;
else
l0=Updated_l;
q0=Updated_q;
m0=Updated_m;
e=Updated_e;
Wu_0=Updated_Wu;
Wm_0=Updated_Wm;
beta_0=Updated_beta1;
Initial_Value=Updated_Value;
end

end
if Flagg==1
%     [V,D]=eig(Final_Wu);
%     wm=eig(Final_Wm);
Obj=Record1(1,length(Record1));
beta1=Final_beta1;
else
beta1=zeros(1,para.M);
Obj=0;
end
figure
plot(0:length(Record1)-1,Record1)
``````

Remove `quiet`, Make sure you are looking at an iteration in which CVX says was solved. Then look at the values of `Wm` and `Wu` after `cvx_end`.

If the optimal value does not have any complex elements, they will be listed as `double`.

For example,

``````cvx_begin
variable x(3,3) complex
minimize(norm(x,'fro'))
cvx_end
``````

`disp(x)`
All zero sparse: 3×3

`whos x`
Name Size Bytes Class Attributes

x 3x3 48 double sparse
`