Manipulating a multidimensional array.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Vira Roy
am 23 Apr. 2022
Kommentiert: Bruno Luong
am 24 Apr. 2022
PROBLEM: I have managed to create a multidimensional array storing eigenvectors of a hamiltonian. Now I want to manipulate the array to find the expectation value of a matrix and make a quiver plot.
EXPLANATION : I have the following Hamiltonian
with
. I want to find the eigenvectors for a set of values on a meshgrid and then use it to find
and
and then to do a quiver plot.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/974965/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/974970/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/975000/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/974995/image.png)
It can be done by solving analyticaly as well and the results are,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/974985/image.png)
The above can be easily coded as follows,
kx = linspace(-0.5,0.5,15);
ky = linspace(-0.5,0.5,15);
[KX,KY] = meshgrid(kx,kx);
X = -sin(atan2(KY,KX));
Y = cos(atan2(KY,KX));
quiver(KX,KY,X,Y)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/974990/image.jpeg)
My Attempt
kx = linspace(-0.5,0.5,15);
ky = linspace(-0.5,0.5,15);
[KX,KY] = meshgrid(kx,kx);
alpha_R = 0.18851;
M = length(kx);
% SPIN MATRICES
sigma_x = [0,1;1,0]; % sigma_x
sigma_y = [0,-1j;1j,0]; %sigma_y
I = [1,0;0,1]; % Identity
%Pre-allocation
E = nan(M,M,2);
Psi = nan(M,M,2);
Psi_prime = nan(M,M,2);
for i = 1: length(kx)
for j = 1: length(ky)
kx_t = kx(i);
ky_t = ky(j);
eps_k = kx_t^2 + ky_t^2; % epsilon_k
%hamiltonian
H = eps_k * I + alpha_R * (sigma_x .* ky_t - sigma_y .* kx_t);
E(i,j,:) = eig(H);
[V,D] = eig(H);
Psi(i,j,:) = V(:,1);
end
end
Psi_prime = pagectranspose(Psi);
%%%ERROR HERE
expx = Psi_prime .* sigma_x .* Psi ;
% expy
% quiver(KX,KY,expx,expy)
I want to find the expectation value of x and y and make a quiver plot of that to get the same texture as above.
Any help or guidance would be helpful. I just am unable to visualize a multidimensional array.
Thank You.
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 23 Apr. 2022
Bearbeitet: Bruno Luong
am 23 Apr. 2022
Try this:
kx = linspace(-0.5,0.5,15);
ky = linspace(-0.5,0.5,15);
[KX,KY] = meshgrid(kx,kx);
alpha_R = 0.18851;
M = length(kx);
% SPIN MATRICES
sigma_x = [0,1;1,0]; % sigma_x
sigma_y = [0,-1j;1j,0]; %sigma_y
I = [1,0;0,1]; % Identity
%Pre-allocation
E = nan(M,M,2);
Psi = nan(2,1,M,M); % BL's change here
for i = 1: length(kx)
for j = 1: length(ky)
kx_t = kx(i);
ky_t = ky(j);
eps_k = kx_t^2 + ky_t^2; % epsilon_k
%hamiltonian
H = eps_k * I + alpha_R * (sigma_x .* ky_t - sigma_y .* kx_t);
E(i,j,:) = eig(H);
[V,D] = eig(H);
Psi(:,:,i,j) = V(:,1); % BL's change here
end
end
% Psi_prime = pagectranspose(Psi); % BL's change here
%%%NO LONGER ERROR HERE
expx = pagemtimes(pagemtimes(Psi,'ctranspose',sigma_x,'none'),Psi); % BL's change here
expx = reshape(expx,[M M]); % BL's change here
expy = pagemtimes(pagemtimes(Psi,'ctranspose',sigma_y,'none'),Psi); % BL's change here
expy = reshape(expy,[M M]); % BL's change here
% expy
quiver(KX,KY,expx,expy)
5 Kommentare
SHUBHAM PATEL
am 24 Apr. 2022
Could you please tell how can we add a third feature (sigma_z, and expz) which is represented by the background color in the quiver plot?
In the code above if we want to add another two line.
% before the 'for' loop
sigma_z = [1,0;0,-1]; %sigma_z
%After the for loop
expz = pagemtimes(pagemtimes(Psi,'ctranspose',sigma_z,'none'),Psi); % BL's change here
expz = reshape(expz,[M M]); % BL's change here
And if we want to reflect the magnitude of espectation value of z by background color of the quiver plot, is it possible in MATLAB?
PS: The magnitude of expz is vecry small (zero), still I want to know the way.
Bruno Luong
am 24 Apr. 2022
It sounds lie a graphical/plotting related question. I suggest you to open a new question so other participants can give you answers.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Vector Fields finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!