# SDP solution and an algorithmic Problem(Index in position 4 exceeds array bounds (must not exceed 2).)

Hello,
I am trying to solve sdp equation. I know the equation. It is ok. But my array size of different so I have an error like that:

Index in position 4 exceeds array bounds (must not exceed 2).
trace(squeeze(sum(sigma_e(:,:,:),3))*kron(A_ax(:,:,x,a),B_by(:,:,y,b)))==P_exp(a,b,x,y) : T{a,b,x,y};
Here is my code:

``````    function [G,B,rho] = Terminal(P_exp,A_ax,B_by)

d = size(P_exp,1); %P_exp
basiscount=size(P_exp,3);
outcome=size(P_exp,4);
% m = size(P_exp,3);

d2=size(A_ax,1);
basiscount2=size(A_ax,3);
outcome2=size(A_ax,4);

cvx_begin

% variable sigma_e(d^2,d^2,d) hermitian semidefinite %unnormalized states sent by Eve d->m
% dual variables T{d,d,m,m} %d,d->m,m  m->basiscount
variable sigma_e(d^2,d^2,d) hermitian semidefinite %unnormalized states sent by Eve d->m
%variable sigma_e(outcome^2,outcome^2,outcome) hermitian semidefinite
% dual variables T{d,d,basiscount,basiscount} %d,d->m,m
dual variables T{basiscount,basiscount,outcome,outcome} %d,d->m,m
J=cvx(0);
xin=1;
for e=1:outcome2 %d->outcome
J=J+trace(sigma_e(:,:,e)*kron(A_ax(:,:,xin,e),eye(d)));%d->outcome
%     for g=1:m
%         J=J+trace(sigma_e(:,:,e)*kron(A_ax(:,:,xin,g),eye(d)));  %d->m
%     end
end
J=real(J);
minimize (-J)

subject to
% for dim=1:d
%   for dim2=1:d
for a=1:outcome %d->outcome
for b=1:outcome %d->outcome
for x=1:basiscount %m->basis count
for y=1:basiscount
%trace(squeeze(sum(sigma_e(:,:,:),3))*kron(A_ax(:,:,x,x),B_by(:,:,y,y)))==P_exp(a,b,x,y) : T{a,b,x,y};
trace(squeeze(sum(sigma_e(:,:,:),3))*kron(A_ax(:,:,x,a),B_by(:,:,y,b)))==P_exp(a,b,x,y) : T{a,b,x,y};
%trace(squeeze(sum(sigma_e(:,:,:),3))*kron(A_ax(:,:,a,x),B_by(:,:,b,y)))==P_exp(a,b,x,y) : T{a,b,x,y};
end
end

end
end
%   end
%end

%trace(squeeze(sum(sigma_e(:,:,:),3)))==1 :lambda ;

for e=1:outcome %d->outcome
sigma_e(:,:,e) ==semidefinite(d^2);
end
trace(sum(sigma_e,3)) == 1;

cvx_end
B=cell2mat(T);
%B=T(:,:,:,:);
%B=cell2mat(B);
%lambda=double(lambda);
G=double(J);
rho=double(sum(sigma_e,3));
``````

The thing is that: I have P(4,4,3,3) and have A(4,4,3,2), B(4,4,3,3) so in the related line when P can go until the 4, for A I have not 4 indexes, I can go until the 2. And I can’t solve this problem. I am scared to do wrong equation
How can I do a correlation for the code?
Best regards

Use `whos` to look at the dimensions of everything. For diagnostic purposes, instead of declaring variables, assign numerical values , e.g., `sigma_e= = ones(d^2,d^2,d);` . Perhaps don’t include the dual variables at this stage. Then all the following expressions need to be conformal, i.e., satisfy MATLAB’s rules on dimension, indices, etc.If they don’t the CVX code will be wrong.

OK I will try thanks !