Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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

Réponses (0)

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by