Effacer les filtres
Effacer les filtres

Creating Matrix with a Dynamic Size

1 vue (au cours des 30 derniers jours)
Gözde Üstün
Gözde Üstün le 1 Juil 2020
Hello,
I can create 2*2 matrix with the following code but for higher dimension I can not:
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]];
if d==2
A(:,:,1,k) = projectors_of_sigma_x(:,k)*transpose(projectors_of_sigma_x(:,k));
A(:,:,2,k) = projectors_of_sigma_z(:,k)*transpose(projectors_of_sigma_z(:,k));
else
A(:,:,1,1)=repmat(projectors_of_sigma_x(1)*transpose(projectors_of_sigma_x(1)),d,d); %this line is ok
A(:,:,1,2)=repmat(projectors_of_sigma_x(2)*transpose(projectors_of_sigma_x(2)),d,d); %In this line I am seeing the same result with A(:,:,1,1)
end
end
In the result of A(:,:,1,2) I am seeing the same result with A(:,:,1,1) but I should not!

Réponse acceptée

Gözde Üstün
Gözde Üstün le 1 Juil 2020
Ok I solved the problem:
for l=1:2
A(:,:,1,k) = repmat(projectors_of_sigma_x(:,l)*transpose(projectors_of_sigma_x(:,l)),d/2,d/2);
A(:,:,2,k) = repmat(projectors_of_sigma_z(:,l)*transpose(projectors_of_sigma_z(:,l)),d/2,d/2);
end

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements 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