Parametric Block Diagonal Matrix Unable to perform assignment because the size of the left side is 4-by-4 and the size of the right side is
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I have this code:
function [A,B] = CH2d(d)
A=zeros(d,d,2,d);
B=A;
projectors_of_sigma_x = [1/sqrt(2)*[1;1],1/sqrt(2)*[1;-1]];
projectors_of_sigma_x_plus_sigma_z = [[(sqrt(2)+1);1],[(-sqrt(2)+1);1]];
for k = 1:d
for l =1:d
% if d > 2
% A(:,:,1,k) = blkdiag(A(:,:,1,k));
% B(:,:,1,k) = blkdiag(B(:,:,1,k));
% end
A(:,:,1,k)=repmat(projectors_of_sigma_x(:,k),1,d);
B(:,:,1,k)=repmat(projectors_of_sigma_x_plus_sigma_z(:,k),1,d);
end
end
end
For d = 2 everything is perfect but if d bigger than 2 and d is even the output should be block diagonal matrix. So I added these script in the code:
if d > 2
A(:,:,1,k) = blkdiag(A(:,:,1,k));
B(:,:,1,k) = blkdiag(B(:,:,1,k));
end
But this time I have this error:
Unable to perform assignment because the size of the left side is 4-by-4 and the size of the right side is 2-by-4.
Error in CH2d (line 16)
A(:,:,1,k)=repmat(projectors_of_sigma_x(:,k),1,d);
How can I solve this problem? I think I need a new variable or I dont know
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!