# Error:The input matrix must be a double-precision matrix or a logical matrix

Why does the following code throw an error stating that the input matrix must be a double-precision matrix or a logical matrix?

function Phi = update_Phi(G,HD,HR,H,W,y,Tau,Pm,Rmin,miu,M,N,sigmav,sigmak)

h1=H(1,:);
h2=H(2,:);
h3=H(3,:);
h4=H(4,:);
hr1=HR(:,1);
hr2=HR(:,2);
hr3=HR(:,3);
hr4=HR(:,4);
w1=W(:,1);
w2=W(:,2);
w3=W(:,3);
w4=W(:,4);

cvx_begin quiet
cvx_precision best
cvx_solver sedumi
variable phi(M,1);

expression Phi;
expression D(M,4);
expression Kexi(M,M,4);
expression C(4);
expression P;
expression f;

Phi=diag(phi);
f=0;
P=sigmav*eye(M,M);

for k=1:4
sum1=0;
sum2=0;
sum3=0;
for j=1:4
if j~=k
sum1=sum1+W(:,j)*W(:,j)‘*HD(:,k);
sum2=sum2+diag(HR(:,k)’)GW(:,j)*W(:,j)‘*G’diag(HR(:,k));
sum3=sum3+W(:,j)‘HD(:,k)HD(:,k)'W(:,j);
end
end
D(:,k)=Tau(k)diag(HR(:,k)')GW(:,k)-abs(Tau(k))^2diag(HR(:,k)')Gsum1;
kexi(:,:,k)=abs(Tau(k))^2
sum2+abs(Tau(k))^2
sigmav
diag(HR(:,k)’)diag(HR(:,k));
C(k)=1+2
real(Tau(k)HD(:,k)'W(:,k))-abs(Tau(k))^2sum3;
P=P+diag(G
W(:,k))diag(GW(:,k))';
f=f+log(2
real(phi’*D(:,k))-real(phi’*Kexi(:,:,k)*phi)+real(C(k)));
end

maximize(2ysqrt(f)-y^2*phi’Pphi/miu)

subject to

square_abs(h1w1)>=(2^Rmin-1)(square_abs(h1w2)+square_abs(h1w3)+square_abs(h1w4)+sigmavsquare_pos(norm(hr1’Phi))+sigmak);
square_abs(h2
w2)>=(2^Rmin-1)(square_abs(h2w1)+square_abs(h2w3)+square_abs(h2w4)+sigmavsquare_pos(norm(hr2’Phi))+sigmak);
square_abs(h3
w3)>=(2^Rmin-1)
(square_abs(h3w1)+square_abs(h3w2)+square_abs(h3w4)+sigmavsquare_pos(norm(hr3’Phi))+sigmak);
square_abs(h4
w4)>=(2^Rmin-1)(square_abs(h4w1)+square_abs(h4w2)+square_abs(h4w3)+sigmav*square_pos(norm(hr4’*Phi))+sigmak);

for m=1:M
square_abs(phi(m))<=Pm/(square_abs(G(m,:)*W(:,1))+square_abs(G(m,:)*W(:,2))+square_abs(G(m,:)*W(:,3))+square_abs(G(m,:)*W(:,4))+sigmav);
end

cvx end

Why

You haven’t provided the input data. Perhaps the error is due to “improper” input data. Why don’t you look at the statement where the error occurs, and look at the values of everything (all matrices) in that statement to try to identify what is causing the error? Based on what you have told us,l we don[t even know if this is a CVX error, or a MATLAB error.

As additional advice (which has nothing to do with the error message), don’t use `quiet` until you have verified everything is working properly. Never use `cvx_precision best` - it is a well-intentioned but misguided feature which we now know is not a good thing to use.

Thank you for your response, but even after not using quiet, I still cannot get the output because the error occurs at the command cvx_end. Also, I have used similar matrix inputs in another function file without any errors, so I’m not sure where the problem lies.

As I wrote, not using `quiet` is an additional suggestion, but has nothing to do with this error message.

I don’t think readers can determine what’s going on without a reproducible example which includes all the input data.