フィルターのクリア

Generating Block Matrix Dynamically

5 ビュー (過去 30 日間)
Gözde Üstün
Gözde Üstün 2020 年 6 月 27 日
コメント済み: Gözde Üstün 2020 年 7 月 3 日
Hello,
I am generating this matrix in 2d:
0.7071 0.7071
0.7071 0.7071
But for even number (and of course greater than 2) I need to generate that:
0.7071 0.7071 0 0
0.7071 0.7071 0 0
0 0 0.7071 0.7071
0 0 0.7071 0.7071
But I can not handle with my size problem. Here is my code:
function [A,B] = CHSH2d(d)
A=zeros(d,d,2,d);
B=A;
projectors_of_sigma_x = [1/sqrt(2)*[1;1],1/sqrt(2)*[1;-1]];
for k = 1:d
for l =1:d
A(:,:,1,k)=repmat(projectors_of_sigma_x(:,k),1,d);
if d > 2
A(:,:,1,k) = blkdiag(A(:,:,1,k));
end
end
end
end

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 6 月 27 日
編集済み: Ameer Hamza 2020 年 6 月 27 日
This example show how to use blkdiag to create such a matrix
M = [0.7071 0.7071
0.7071 0.7071];
n = 4;
M_cell = repmat({M}, 1, n/2);
M_out = blkdiag(M_cell{:})
Result
M_out =
0.7071 0.7071 0 0
0.7071 0.7071 0 0
0 0 0.7071 0.7071
0 0 0.7071 0.7071
You can avoid for-loop in your code.
  14 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 7 月 2 日
See this
d = 4;
A=zeros(d,d,2,d);
B=A;
projectors_of_sigma_x = [1/sqrt(2)*[1;1],1/sqrt(2)*[1;-1]];
for k = 1:d/2 % what is pattern for k>d/2
A(:,:,1,k)=repmat(projectors_of_sigma_x(:,k),d/2,d);
end
It saves the values of A(:,:1,1) and A(:,:1,2). But how to extent the patten beyond that for an arbitrary value of 'd' is not clear to me. The description you provided is clear for d=4, but what if d=8 or d=16.
Gözde Üstün
Gözde Üstün 2020 年 7 月 3 日
Thank you very much I asked you the wrong question so sorry I will ask the right question now in the different page

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by