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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!