# Own writing function cannot run in the cvx

**the original problem is:

minimize sum(i=1~m) of [tr(Aiρ)-bi]^2/(2tr(Ai*ρ))

subject to ρ+=ρ,ρ>=0,tr(ρ)=1.**

Some specification:

1.ρ is the density matrix and is Hermitian,which is 16*16.

2.m<=256,which indicates the number of a series of randomly chosen numbers from 1 to 256. In the series of randomly chosen numbers, on two of them are the same.

3.Ai is a 16*16 matrix, bi is the observation value. These matrices and values can be accessed easily, and they are provided by some simple functions.

Here is how I used the cvx:

cvx_begin

variable rho1(16,16) complex semidefinite

minimize getSumWithTr(m,array,rho0,rho1)

cvx_end

where array is the group of randomly chosen numbers, rho0 is the original density matrix to calculate the bi value.

Here is the getSumWithTr function:

function temp=getSumWithTr(m,numberArray,rho0,rho1) %calculates the sum

temp=0;

for i=1:m

tempn=zeros(4,1);

tempAi=zeros(16,16);

tempbi=0;

tempr=0;

d1=0;

d2=0;

d3=0;

d4=0;

tempn=numberArray(i);

tempn=nick_ftot(tempn);         %translate the 10-base digit to 4-base digit

d1=tempn(1);

d2=tempn(2);

d3=tempn(3);

d4=tempn(4);

tempAi=getAi(d1,d2,d3,d4);     %get the operator Ai

tempbi=getbi(d1,d2,d3,d4,rho0); %get the observation bi

tempr=trace(tempAi*rho1)-tempbi;

tempr=tempr*tempr;

tempr=tempr/(2*trace(tempAi*rho1));

temp=temp+tempr;

end


end

I think this function doesn’t meet the DCP ruleset and here is the error message

Error using cvx/times (line 173)
Disciplined convex programming error:
Cannot perform the operation: {convex} ./ {real affine}

Error in cvx/rdivide (line 19)
z = times( x, y, ‘./’ );

Error in cvx/mtimes (line 36)
z = feval( oper, x, y );

Error in cvx/mrdivide (line 15)
z = mtimes( x, y, ‘rdivide’ );

Error in getSumWithTr (line 23)
tempr=tempr/(2trace(tempAirho1));

Error in minimize (line 14)
x = evalin( ‘caller’, sprintf( '%s ', varargin{:} ) );

Thus, please help me to modify this function. Or is there any other method to solve out the problem? Thanks!

Unless you can guarantee that each \mathop{\textrm{Tr}}(A_i\rho)>0, this problem is not convex, and CVX cannot solve it. If it is convex, you might consider using the quad_over_lin function to represent the individual terms.