フィルターのクリア

The Code Does not Compute the other elements of Matrix

1 回表示 (過去 30 日間)
Gözde Üstün
Gözde Üstün 2020 年 7 月 13 日
コメント済み: Gözde Üstün 2020 年 7 月 13 日
Hello,
I am trying to compute value of probabilitiy distribution The formula is ok, code is working I have no error but some values are coming as 0. However I should have a value except zero
Here is my code:
function P = Prob(A_ax,B_by,rho)
d=size(A_ax,1);
m=size(A_ax,4);
bcount=size(A_ax,3);
P = zeros(d,d,bcount,m);
for x=1:bcount %m->bcount
for y=1:bcount %m->bcount
for a=1:m %d
for b=1:m %d
for dim=1:d
for dim2=1:d
%P(dim,dim2,x,y) = real( trace(kron(A_ax(dim,dim2,x,a),B_by(dim,dim2,y,b))*rho));
P(a,b,x,y) = real( trace(kron(A_ax(:,:,x,a),B_by(:,:,y,b))*rho));
end
end
end
end
end
end
As you can see the other values are 0. Where am I doing wrong?

回答 (1 件)

KSSV
KSSV 2020 年 7 月 13 日
編集済み: KSSV 2020 年 7 月 13 日
function P = Prob(A_ax,B_by,rho)
d=size(A_ax,1);
m=size(A_ax,4);
bcount=size(A_ax,3);
P = zeros(d,d,bcount,bcount); %% Changed here
for x=1:bcount %m->bcount
for y=1:bcount %m->bcount
for a=1:d
for b=1:d
P(a,b,x,y) = real( trace(kron(A_ax(:,:,x,a),B_by(:,:,y,b))*rho));
end
end
end
end
  3 件のコメント
KSSV
KSSV 2020 年 7 月 13 日
run the loop till d, a = 1:d, b = 1:d
Gözde Üstün
Gözde Üstün 2020 年 7 月 13 日
I cannot because since we thought A(4,4,2,2) I have not 4 for the a value so I have an error (A_ax(:,:,x,a))

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by