Creating Dynamic High Dimensional Block Diagonal Matrix

1 次查看(过去 30 天)
Hello,
I can create a matrix for dimenson = 2. However for even d and d>2, It should be a lock diagonal matrix of the previous result. I cannot run my code. I tried too many combination but I dont know how I can solve my problem
Here is my code:
A=zeros(d,d,2,d);
B=A;
projectors_of_sigma_x = [1/sqrt(2)*[1;1],1/sqrt(2)*[1;-1]];
for k = 1:d
A(:,:,1,k)=repmat(projectors_of_sigma_x(:,k),1,d); % In this line I am giving the value (1/sqrt(2)*[1;1]) to A(:,:,1,1) and value 1/sqrt(2)*[1;-1] to A(:,:,1,2)
if k > 2
A(:,:,1,k) = repmat({A(:,:,1,k)}, 1, d/2); %This line and the following line I am trying to create a matrix which is a blog diagonal of the previous result for even d and of course d>2
A(:,:,1,k) = blkdiag(A{:,:,1,k});
end
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by