フィルターのクリア

Result of A(:,:,1,1) coming as result of A(:,:,1,2)

1 回表示 (過去 30 日間)
Gözde Üstün
Gözde Üstün 2020 年 7 月 6 日
コメント済み: Christine Tobler 2020 年 7 月 10 日
Hello,
Ihave this code:
function [A,B] = trying(d)
A=zeros(d,d,2,d);
sigma_x = [0,1;1,0];
sigma_z = [1,0;0,-1];
if d==2
x = sigma_x;
z = sigma_z;
end
if d==4
x = kron(sigma_x,sigma_x);
z = kron(sigma_z,sigma_z);
end
[xv1,xv2] = eig(x);
%xv1 = [xv1(:,2),xv1(:,1)];
[zv1,zv2] = eig(z);
%zv1 = [zv1(:,2),zv1(:,1)];
for i=1:d
% for k = 1:2
A(:,:,1,i)= xv1(:,i)*transpose(xv1(:,i));
A(:,:,2,i)= zv1(:,i)*transpose(zv1(:,i));
% end
end
end
However, I have inverse result For instance the result should be like that:
A(:,:,1,1) =
0.5000 0.5000
0.5000 0.5000
A(:,:,2,1) =
1 0
0 1
A(:,:,1,2) =
0.5000 -0.5000
-0.5000 0.5000
But I have this result:
A(:,:,1,1) =
0.5000 -0.5000
-0.5000 0.5000
A(:,:,2,1) =
0 0
0 1
A(:,:,1,2) =
0.5000 0.5000
0.5000 0.5000
So I tried the that But it did not work
xv1 = [xv1(:,2),xv1(:,1)];
zv1 = [zv1(:,2),zv1(:,1)];
for i=1:d
for k = 1:2
A(:,:,1,i)= xv1(:,k)*transpose(xv1(:,k));
A(:,:,2,i)= zv1(:,k)*transpose(zv1(:,k));
end
end
Any idea?
  2 件のコメント
Geoff Hayes
Geoff Hayes 2020 年 7 月 6 日
Gözde - why should the output look like the first block of output that you have shown? What algorithm or equations are you basing your code on? Also, note the following
for i=1:d
% for k = 1:2
A(:,:,1,i)= xv1(:,i)*transpose(xv1(:,i));
A(:,:,2,i)= zv1(:,i)*transpose(zv1(:,i));
% end
end
Since i is either 1 or 2, then this means that you also have A(:,:,2,2) set with a value which in this case is
A(:,:,2,2) =
1 0
0 0
Is this expected or should you just have populated A(:,:1,1), A(:,:,1,2), and A(:,:,2,1)?
Gözde Üstün
Gözde Üstün 2020 年 7 月 6 日
Hello,
Because I am using "eig" function and in the eig function, first eigenvector is coming as second eigen vector.
You are right I (should) have also A(:,:,2,2) but for showing you I just put the other values.

サインインしてコメントする。

回答 (1 件)

Christine Tobler
Christine Tobler 2020 年 7 月 7 日
The eigenvectors returned by EIG are returned in the same order as the eigenvalues, but the eigenvalues are not necessarily sorted. Could this be the issue here?
  2 件のコメント
Gözde Üstün
Gözde Üstün 2020 年 7 月 7 日
Yeah How can I solve this prolem? I used that:
xv1 = [xv1(:,2),xv1(:,1)];
zv1 = [zv1(:,2),zv1(:,1)];
for i=1:d
for k = 1:2
A(:,:,1,i)= xv1(:,k)*transpose(xv1(:,k));
A(:,:,2,i)= zv1(:,k)*transpose(zv1(:,k));
end
end
But it did not work for me
Christine Tobler
Christine Tobler 2020 年 7 月 10 日
You can sort the eigenvalues and eigenvectors before using them further, see this example for how to do that.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by