How to put matrices defined earlier in "for loop" later
Show older comments
I have this program defined,where E_i,E_j are 3x3 matrices, I use Qetlab Tensor Product to make 9x9 matrices
syms x p_1 p_2 r
rho_alpha = (1/21).*[2 0 0 0 2 0 0 0 2;0 5-x 0 0 0 0 0 0 0;0 0 x 0 0 0 0 0 0;
0 0 0 x 0 0 0 0 0;2 0 0 0 2 0 0 0 2;0 0 0 0 0 5-x 0 0 0;
0 0 0 0 0 0 5-x 0 0;0 0 0 0 0 0 0 x 0;2 0 0 0 2 0 0 0 2];
E_1 = sqrt(r).*[1 0 0;0 sqrt(1-p_1) 0;0 0 sqrt(1-p_2)];
E_2 = sqrt(r).*[0 sqrt(p_1) 0;0 0 0;0 0 0];
E_3 = sqrt(r).*[0 0 sqrt(p_2);0 0 0;0 0 0];
E_4 = sqrt(1-r).*[sqrt(1-p_1-p_2) 0 0;0 1 0;0 0 1];
E_5 = sqrt(1-r).*[0 0 0; sqrt(p_1) 0 0;0 0 0];
E_6 = sqrt(1-r).*[0 0 0;0 0 0; sqrt(p_2) 0 0];
for i = 1:6
for j = 1:6
rho_alpha1 = Tensor(E_j,E_i)*rho_alpha*transpose(Tensor(E_i,E_j));
end
end
rho_alpha1
the main issue i have is how to use E_1,E_2,E_3,E_4,E_5,E_6 matrices as E_i and E_j in for loop.
I am trying to replicate the results of this paper : Distillability sudden death and sudden birth in a
two-qutrit system under decoherence at finite temperature.
Accepted Answer
More Answers (2)
Instead of making 6 separate variables, you can put those 6 matrices in a single variable that you can index, e.g., a 3D array or a cell array. Here they are in a 3D array:
syms x p_1 p_2 r
rho_alpha = (1/21).*[2 0 0 0 2 0 0 0 2;0 5-x 0 0 0 0 0 0 0;0 0 x 0 0 0 0 0 0;
0 0 0 x 0 0 0 0 0;2 0 0 0 2 0 0 0 2;0 0 0 0 0 5-x 0 0 0;
0 0 0 0 0 0 5-x 0 0;0 0 0 0 0 0 0 x 0;2 0 0 0 2 0 0 0 2];
E = cat(3, ...
sqrt(r).*[1 0 0;0 sqrt(1-p_1) 0;0 0 sqrt(1-p_2)], ...
sqrt(r).*[0 sqrt(p_1) 0;0 0 0;0 0 0], ...
sqrt(r).*[0 0 sqrt(p_2);0 0 0;0 0 0], ...
sqrt(1-r).*[sqrt(1-p_1-p_2) 0 0;0 1 0;0 0 1], ...
sqrt(1-r).*[0 0 0; sqrt(p_1) 0 0;0 0 0], ...
sqrt(1-r).*[0 0 0;0 0 0; sqrt(p_2) 0 0] ...
)
for i = 1:6
for j = 1:6
% note that rho_alpha1 is overwritten each time though the loops ...
rho_alpha1 = Tensor(E(:,:,j),E(:,:,i))*rho_alpha*transpose(Tensor(E(:,:,i),E(:,:,j)));
end
end
rho_alpha1 % ... so this is rho_alpha1 for i == j == 6 only
1 Comment
Gurvir
on 29 Jul 2023
Walter Roberson
on 29 Jul 2023
syms x p_1 p_2 r
rho_alpha = (1/21).*[2 0 0 0 2 0 0 0 2;0 5-x 0 0 0 0 0 0 0;0 0 x 0 0 0 0 0 0;
0 0 0 x 0 0 0 0 0;2 0 0 0 2 0 0 0 2;0 0 0 0 0 5-x 0 0 0;
0 0 0 0 0 0 5-x 0 0;0 0 0 0 0 0 0 x 0;2 0 0 0 2 0 0 0 2];
E{1} = sqrt(r).*[1 0 0;0 sqrt(1-p_1) 0;0 0 sqrt(1-p_2)];
E{2} = sqrt(r).*[0 sqrt(p_1) 0;0 0 0;0 0 0];
E{3} = sqrt(r).*[0 0 sqrt(p_2);0 0 0;0 0 0];
E{4} = sqrt(1-r).*[sqrt(1-p_1-p_2) 0 0;0 1 0;0 0 1];
E{5} = sqrt(1-r).*[0 0 0; sqrt(p_1) 0 0;0 0 0];
E{6} = sqrt(1-r).*[0 0 0;0 0 0; sqrt(p_2) 0 0];
for i = 1:6
for j = 1:6
rho_alpha = Tensor(E{j},E{i})*rho_alpha*transpose(Tensor(E{i},E{j}));
end
end
rho_alpha
5 Comments
Gurvir
on 29 Jul 2023
Bruno Luong
on 29 Jul 2023
Gurvir
on 29 Jul 2023
Bruno Luong
on 29 Jul 2023
Edited: Bruno Luong
on 29 Jul 2023
The flaw is not from Voss and Walter they simply duplicate your orginal code calculation inside the loops. Your original code doesn't do any sum, so how they suppose to know adding a sum on intermediate result?
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






