So I am rewriting some code from Matlab into Julia. I want the final plots to be the same however Julia is sorting the eigenvalues in ascending order which is making the plot confusing for my use case.
The following plot is produced by the Matlab code:
Matlab Plot
Matlab Code
g1=1.0;
g2=4.0;
eps=sym('eps');
A=[(-eps+(g1+g2)*mu*B)/2 0 0 0 0;
0 -eps/2 0 (g1-g2)*mu*B/2 0;
0 0 (-eps-(g1+g2)*mu*B)/2 0 0;
0 (g1-g2)*mu*B/2 0 -eps/2 t;
0 0 0 t eps/2];
E=eig(A); %energy levels (eigenvalues)
figure
subplot(2,2,1)
fplot([real(E(1)),real(E(2)),real(E(3)),real(E(4)),real(E(5))],[-0.260,0.260])
title('Energy spectrum')
xlabel('\epsilon (meV)')
ylabel('E (meV)')
The points of intersection are important and unfortunately, I lose them in the Julia code because of the ascending order.
Julia Plot
Julia Code
using PyPlot
using LinearAlgebra
function model_g1g2(g1, g2, B, t)
ÎĽ = 57.88e-3
ϵ = collect(range(-0.26, length=100, stop=0.26))
A = Array{Float64,2}(undef, 5, 5)
E = Array{Float64,2}(undef, 5, 100)
for i = 1:100
A = [(-ϵ[i]+(g1+g2)*μ*B)/2 0 0 0 0;
0 -ϵ[i]/2 0 (g1-g2)*μ*B/2 0;
0 0 (-ϵ[i]-(g1+g2)*μ*B)/2 0 0;
0 (g1-g2)*μ*B/2 0 -ϵ[i]/2 t;
0 0 0 t ϵ[i]/2]
E[:,i] = LinearAlgebra.eigvals(A)
end
figure, ((ax1)) = subplots(1,1, sharex=true)
for j = 1:5
ax1.plot(ϵ, E[j,:])
end
show(figure)
return figure
end
model_g1g2(1, 4, 0.5, 0.06)
So essentially I want to replicate the ordering Matlab’s eig
function uses without switching the eigenvalues after the fact. I will be tweaking the parameters so ideally don’t want to have to go back in and adjust it every time the points of intersection change.
Thanks