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!