This commit is contained in:
2023-07-26 00:46:01 +08:00
parent c7cbcd09af
commit 822fa7e626
212 changed files with 5687 additions and 5687 deletions

View File

@@ -1,50 +1,50 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8491
"""
import numpy as np
import cmath
import matplotlib.pyplot as plt
def main():
for n in np.arange(1, 11):
print('n=', n)
width = n
length = n
B_array = np.arange(0, 1, 0.001)
eigenvalue_all = np.zeros((B_array.shape[0], width*length))
i0 = 0
for B in B_array:
# print(B)
h = hamiltonian(width, length, B)
eigenvalue, eigenvector = np.linalg.eig(h)
eigenvalue_all[i0, :] = np.real(eigenvalue)
i0 += 1
plt.plot(B_array, eigenvalue_all, '.r', markersize=0.5)
plt.title('width=length='+str(n))
plt.xlabel('B*a^2/phi_0')
plt.ylabel('E')
plt.savefig('width=length='+str(n)+'.jpg', dpi=300)
plt.close('all') # 关闭所有plt防止循环画图时占用内存
# plt.show()
def hamiltonian(width, length, B): # 方格子哈密顿量
h = np.zeros((width*length, width*length), dtype=complex)
# y方向的跃迁
for x in range(length):
for y in range(width-1):
h[x*width+y, x*width+y+1] = 1
h[x*width+y+1, x*width+y] = 1
# x方向的跃迁
for x in range(length-1):
for y in range(width):
h[x*width+y, (x+1)*width+y] = 1*cmath.exp(-2*np.pi*1j*B*y)
h[(x+1)*width+y, x*width+y] = 1*cmath.exp(2*np.pi*1j*B*y)
return h
if __name__ == "__main__":
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8491
"""
import numpy as np
import cmath
import matplotlib.pyplot as plt
def main():
for n in np.arange(1, 11):
print('n=', n)
width = n
length = n
B_array = np.arange(0, 1, 0.001)
eigenvalue_all = np.zeros((B_array.shape[0], width*length))
i0 = 0
for B in B_array:
# print(B)
h = hamiltonian(width, length, B)
eigenvalue, eigenvector = np.linalg.eig(h)
eigenvalue_all[i0, :] = np.real(eigenvalue)
i0 += 1
plt.plot(B_array, eigenvalue_all, '.r', markersize=0.5)
plt.title('width=length='+str(n))
plt.xlabel('B*a^2/phi_0')
plt.ylabel('E')
plt.savefig('width=length='+str(n)+'.jpg', dpi=300)
plt.close('all') # 关闭所有plt防止循环画图时占用内存
# plt.show()
def hamiltonian(width, length, B): # 方格子哈密顿量
h = np.zeros((width*length, width*length), dtype=complex)
# y方向的跃迁
for x in range(length):
for y in range(width-1):
h[x*width+y, x*width+y+1] = 1
h[x*width+y+1, x*width+y] = 1
# x方向的跃迁
for x in range(length-1):
for y in range(width):
h[x*width+y, (x+1)*width+y] = 1*cmath.exp(-2*np.pi*1j*B*y)
h[(x+1)*width+y, x*width+y] = 1*cmath.exp(2*np.pi*1j*B*y)
return h
if __name__ == "__main__":
main()

View File

@@ -1,43 +1,43 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/962
"""
import numpy as np
def hamiltonian(width=2, length=4): # 有一定宽度和长度的方格子
h00 = np.zeros((width*length, width*length))
for i0 in range(length):
for j0 in range(width-1):
h00[i0*width+j0, i0*width+j0+1] = 1
h00[i0*width+j0+1, i0*width+j0] = 1
for i0 in range(length-1):
for j0 in range(width):
h00[i0*width+j0, (i0+1)*width+j0] = 1
h00[(i0+1)*width+j0, i0*width+j0] = 1
return h00
def main():
h0 = hamiltonian()
dim = h0.shape[0]
n = 4 # 选取第n个能级
eigenvalue, eigenvector = np.linalg.eig(h0) # 本征值、本征矢
# print(h0)
# print('哈密顿量的维度:', dim) # 哈密顿量的维度
# print('本征矢的维度:', eigenvector.shape) # 本征矢的维度
# print('能级(未排序):', eigenvalue) # 输出本征值。因为体系是受限的,所以是离散的能级
# print('选取第', n, '个能级,为', eigenvalue[n-1]) # 从1开始算查看第n个能级是什么这里本征值未排序
# print('第', n, '个能级对应的波函数:', eigenvector[:, n-1]) # 查看第n个能级对应的波函数
print('\n波函数模的平方:\n', np.square(np.abs(eigenvector[:, n-1]))) # 查看第n个能级对应的波函数模的平方
green = np.linalg.inv((eigenvalue[n-1]+1e-15j)*np.eye(dim)-h0) # 第n个能级对应的格林函数
total = np.trace(np.imag(green)) # 求该能级格林函数的迹,对应的是总态密度(忽略符号和系数)
print('归一化后的态密度分布:')
for i in range(dim):
print(np.imag(green)[i, i]/total) # 第n个能级单位化后的态密度分布
print('观察以上两个分布的数值情况,可以发现两者完全相同。')
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/962
"""
import numpy as np
def hamiltonian(width=2, length=4): # 有一定宽度和长度的方格子
h00 = np.zeros((width*length, width*length))
for i0 in range(length):
for j0 in range(width-1):
h00[i0*width+j0, i0*width+j0+1] = 1
h00[i0*width+j0+1, i0*width+j0] = 1
for i0 in range(length-1):
for j0 in range(width):
h00[i0*width+j0, (i0+1)*width+j0] = 1
h00[(i0+1)*width+j0, i0*width+j0] = 1
return h00
def main():
h0 = hamiltonian()
dim = h0.shape[0]
n = 4 # 选取第n个能级
eigenvalue, eigenvector = np.linalg.eig(h0) # 本征值、本征矢
# print(h0)
# print('哈密顿量的维度:', dim) # 哈密顿量的维度
# print('本征矢的维度:', eigenvector.shape) # 本征矢的维度
# print('能级(未排序):', eigenvalue) # 输出本征值。因为体系是受限的,所以是离散的能级
# print('选取第', n, '个能级,为', eigenvalue[n-1]) # 从1开始算查看第n个能级是什么这里本征值未排序
# print('第', n, '个能级对应的波函数:', eigenvector[:, n-1]) # 查看第n个能级对应的波函数
print('\n波函数模的平方:\n', np.square(np.abs(eigenvector[:, n-1]))) # 查看第n个能级对应的波函数模的平方
green = np.linalg.inv((eigenvalue[n-1]+1e-15j)*np.eye(dim)-h0) # 第n个能级对应的格林函数
total = np.trace(np.imag(green)) # 求该能级格林函数的迹,对应的是总态密度(忽略符号和系数)
print('归一化后的态密度分布:')
for i in range(dim):
print(np.imag(green)[i, i]/total) # 第n个能级单位化后的态密度分布
print('观察以上两个分布的数值情况,可以发现两者完全相同。')
if __name__ == '__main__':
main()

View File

@@ -1,56 +1,56 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4622
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
def hamiltonian(width=8, length=8): # 石墨烯格子的哈密顿量。这里width要求为4的倍数
h = np.zeros((width*length, width*length))
# y方向的跃迁
for x in range(length):
for y in range(width-1):
h[x*width+y, x*width+y+1] = 1
h[x*width+y+1, x*width+y] = 1
# x方向的跃迁
for x in range(length-1):
for y in range(width):
if np.mod(y, 4)==0:
h[x*width+y+1, (x+1)*width+y] = 1
h[(x+1)*width+y, x*width+y+1] = 1
h[x*width+y+2, (x+1)*width+y+3] = 1
h[(x+1)*width+y+3, x*width+y+2] = 1
return h
def main():
plot_precision = 0.01 # 画图的精度
Fermi_energy_array = np.arange(-5, 5, plot_precision) # 计算中取的费米能Fermi_energy组成的数组
dim_energy = Fermi_energy_array.shape[0] # 需要计算的费米能的个数
total_DOS_array = np.zeros((dim_energy)) # 计算结果总态密度total_DOS放入该数组中
h = hamiltonian() # 体系的哈密顿量
dim = h.shape[0] # 哈密顿量的维度
i0 = 0
for Fermi_energy in Fermi_energy_array:
print(Fermi_energy) # 查看计算的进展情况
green = np.linalg.inv((Fermi_energy+0.1j)*np.eye(dim)-h) # 体系的格林函数
total_DOS = -np.trace(np.imag(green))/pi # 通过格林函数求得总态密度
total_DOS_array[i0] = total_DOS # 记录每个Fermi_energy对应的总态密度
i0 += 1
sum_up = np.sum(total_DOS_array)*plot_precision # 用于图像归一化
plt.plot(Fermi_energy_array, total_DOS_array/sum_up, '-') # 画DOS(E)图像
plt.xlabel('费米能')
plt.ylabel('总态密度')
plt.show()
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4622
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
def hamiltonian(width=8, length=8): # 石墨烯格子的哈密顿量。这里width要求为4的倍数
h = np.zeros((width*length, width*length))
# y方向的跃迁
for x in range(length):
for y in range(width-1):
h[x*width+y, x*width+y+1] = 1
h[x*width+y+1, x*width+y] = 1
# x方向的跃迁
for x in range(length-1):
for y in range(width):
if np.mod(y, 4)==0:
h[x*width+y+1, (x+1)*width+y] = 1
h[(x+1)*width+y, x*width+y+1] = 1
h[x*width+y+2, (x+1)*width+y+3] = 1
h[(x+1)*width+y+3, x*width+y+2] = 1
return h
def main():
plot_precision = 0.01 # 画图的精度
Fermi_energy_array = np.arange(-5, 5, plot_precision) # 计算中取的费米能Fermi_energy组成的数组
dim_energy = Fermi_energy_array.shape[0] # 需要计算的费米能的个数
total_DOS_array = np.zeros((dim_energy)) # 计算结果总态密度total_DOS放入该数组中
h = hamiltonian() # 体系的哈密顿量
dim = h.shape[0] # 哈密顿量的维度
i0 = 0
for Fermi_energy in Fermi_energy_array:
print(Fermi_energy) # 查看计算的进展情况
green = np.linalg.inv((Fermi_energy+0.1j)*np.eye(dim)-h) # 体系的格林函数
total_DOS = -np.trace(np.imag(green))/pi # 通过格林函数求得总态密度
total_DOS_array[i0] = total_DOS # 记录每个Fermi_energy对应的总态密度
i0 += 1
sum_up = np.sum(total_DOS_array)*plot_precision # 用于图像归一化
plt.plot(Fermi_energy_array, total_DOS_array/sum_up, '-') # 画DOS(E)图像
plt.xlabel('费米能')
plt.ylabel('总态密度')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,52 +1,52 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4622
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
def hamiltonian(width=10, length=10): # 方格子哈密顿量
h = np.zeros((width*length, width*length))
# y方向的跃迁
for x in range(length):
for y in range(width-1):
h[x*width+y, x*width+y+1] = 1
h[x*width+y+1, x*width+y] = 1
# x方向的跃迁
for x in range(length-1):
for y in range(width):
h[x*width+y, (x+1)*width+y] = 1
h[(x+1)*width+y, x*width+y] = 1
return h
def main():
plot_precision = 0.01 # 画图的精度
Fermi_energy_array = np.arange(-5, 5, plot_precision) # 计算中取的费米能Fermi_energy组成的数组
dim_energy = Fermi_energy_array.shape[0] # 需要计算的费米能的个数
total_DOS_array = np.zeros((dim_energy)) # 计算结果总态密度total_DOS放入该数组中
h = hamiltonian() # 体系的哈密顿量
dim = h.shape[0] # 哈密顿量的维度
i0 = 0
for Fermi_energy in Fermi_energy_array:
print(Fermi_energy) # 查看计算的进展情况
green = np.linalg.inv((Fermi_energy+0.1j)*np.eye(dim)-h) # 体系的格林函数
total_DOS = -np.trace(np.imag(green))/pi # 通过格林函数求得总态密度
total_DOS_array[i0] = total_DOS # 记录每个Fermi_energy对应的总态密度
i0 += 1
sum_up = np.sum(total_DOS_array)*plot_precision # 用于图像归一化
plt.plot(Fermi_energy_array, total_DOS_array/sum_up, '-') # 画DOS(E)图像
plt.xlabel('费米能')
plt.ylabel('总态密度')
plt.show()
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4622
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
def hamiltonian(width=10, length=10): # 方格子哈密顿量
h = np.zeros((width*length, width*length))
# y方向的跃迁
for x in range(length):
for y in range(width-1):
h[x*width+y, x*width+y+1] = 1
h[x*width+y+1, x*width+y] = 1
# x方向的跃迁
for x in range(length-1):
for y in range(width):
h[x*width+y, (x+1)*width+y] = 1
h[(x+1)*width+y, x*width+y] = 1
return h
def main():
plot_precision = 0.01 # 画图的精度
Fermi_energy_array = np.arange(-5, 5, plot_precision) # 计算中取的费米能Fermi_energy组成的数组
dim_energy = Fermi_energy_array.shape[0] # 需要计算的费米能的个数
total_DOS_array = np.zeros((dim_energy)) # 计算结果总态密度total_DOS放入该数组中
h = hamiltonian() # 体系的哈密顿量
dim = h.shape[0] # 哈密顿量的维度
i0 = 0
for Fermi_energy in Fermi_energy_array:
print(Fermi_energy) # 查看计算的进展情况
green = np.linalg.inv((Fermi_energy+0.1j)*np.eye(dim)-h) # 体系的格林函数
total_DOS = -np.trace(np.imag(green))/pi # 通过格林函数求得总态密度
total_DOS_array[i0] = total_DOS # 记录每个Fermi_energy对应的总态密度
i0 += 1
sum_up = np.sum(total_DOS_array)*plot_precision # 用于图像归一化
plt.plot(Fermi_energy_array, total_DOS_array/sum_up, '-') # 画DOS(E)图像
plt.xlabel('费米能')
plt.ylabel('总态密度')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,84 +1,84 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4396
"""
import numpy as np
import matplotlib.pyplot as plt
import copy
import time
def matrix_00(width): # 一个切片slide)内的哈密顿量
h00 = np.zeros((width, width))
for width0 in range(width-1):
h00[width0, width0+1] = 1
h00[width0+1, width0] = 1
return h00
def matrix_01(width): # 切片之间的跃迁项hopping
h01 = np.identity(width)
return h01
def matrix_whole(width, length): # 方格子整体的哈密顿量宽度为width长度为length
hamiltonian = np.zeros((width*length, width*length))
for x in range(length):
for y in range(width-1):
hamiltonian[x*width+y, x*width+y+1] = 1
hamiltonian[x*width+y+1, x*width+y] = 1
for x in range(length-1):
for y in range(width):
hamiltonian[x*width+y, (x+1)*width+y] = 1
hamiltonian[(x+1)*width+y, x*width+y] = 1
return hamiltonian
def main():
width =4 # 方格子的宽度
length = 200 # 方格子的长度
h00 = matrix_00(width) # 一个切片slide)内的哈密顿量
h01 = matrix_01(width) # 切片之间的跃迁项hopping
hamiltonian = matrix_whole(width, length) # 方格子整体的哈密顿量宽度为width长度为length
fermi_energy = 0.1 # 费米能取为0.1为例。按理来说计算格林函数时这里需要加上一个无穷小的虚数但Python中好像不加也不会有什么问题。
start_1= time.perf_counter()
green = General_way(fermi_energy, hamiltonian) # 利用通常直接求逆的方法得到整体的格林函数green
end_1 = time.perf_counter()
start_2= time.perf_counter()
green_0n_n = Dyson_way(fermi_energy, h00, h01, length) # 利用Dyson方程得到的格林函数green_0n
end_2 = time.perf_counter()
# print(green)
print('\n整体格林函数中的一个分块矩阵green_0n\n', green[0:width, (length-1)*width+0:(length-1)*width+width]) # a:b代表 a <= x < b左闭右开
print('Dyson方程得到的格林函数green_0n\n', green_0n_n)
print('观察以上两个矩阵,可以直接看出两个矩阵完全相同。\n')
print('General_way执行时间=', end_1-start_1)
print('Dyson_way执行时间=', end_2-start_2)
def General_way(fermi_energy, hamiltonian):
dim_hamiltonian = hamiltonian.shape[0]
green = np.linalg.inv((fermi_energy)*np.eye(dim_hamiltonian)-hamiltonian)
return green
def Dyson_way(fermi_energy, h00, h01, length):
dim = h00.shape[0]
for ix in range(length):
if ix == 0:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00) # 如果有左电极还需要减去左电极的自能left_self_energy
green_0n_n = copy.deepcopy(green_nn_n) # 如果直接用等于两个变量会指向相同的id改变一个值另外一个值可能会发生改变容易出错所以要用上这个COPY
elif ix != length-1:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
else: # 这里和elif ix != length-1中的内容完全一样但如果有右电极这里是还需要减去右电极的自能right_self_energy
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
return green_0n_n
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4396
"""
import numpy as np
import matplotlib.pyplot as plt
import copy
import time
def matrix_00(width): # 一个切片slide)内的哈密顿量
h00 = np.zeros((width, width))
for width0 in range(width-1):
h00[width0, width0+1] = 1
h00[width0+1, width0] = 1
return h00
def matrix_01(width): # 切片之间的跃迁项hopping
h01 = np.identity(width)
return h01
def matrix_whole(width, length): # 方格子整体的哈密顿量宽度为width长度为length
hamiltonian = np.zeros((width*length, width*length))
for x in range(length):
for y in range(width-1):
hamiltonian[x*width+y, x*width+y+1] = 1
hamiltonian[x*width+y+1, x*width+y] = 1
for x in range(length-1):
for y in range(width):
hamiltonian[x*width+y, (x+1)*width+y] = 1
hamiltonian[(x+1)*width+y, x*width+y] = 1
return hamiltonian
def main():
width =4 # 方格子的宽度
length = 200 # 方格子的长度
h00 = matrix_00(width) # 一个切片slide)内的哈密顿量
h01 = matrix_01(width) # 切片之间的跃迁项hopping
hamiltonian = matrix_whole(width, length) # 方格子整体的哈密顿量宽度为width长度为length
fermi_energy = 0.1 # 费米能取为0.1为例。按理来说计算格林函数时这里需要加上一个无穷小的虚数但Python中好像不加也不会有什么问题。
start_1= time.perf_counter()
green = General_way(fermi_energy, hamiltonian) # 利用通常直接求逆的方法得到整体的格林函数green
end_1 = time.perf_counter()
start_2= time.perf_counter()
green_0n_n = Dyson_way(fermi_energy, h00, h01, length) # 利用Dyson方程得到的格林函数green_0n
end_2 = time.perf_counter()
# print(green)
print('\n整体格林函数中的一个分块矩阵green_0n\n', green[0:width, (length-1)*width+0:(length-1)*width+width]) # a:b代表 a <= x < b左闭右开
print('Dyson方程得到的格林函数green_0n\n', green_0n_n)
print('观察以上两个矩阵,可以直接看出两个矩阵完全相同。\n')
print('General_way执行时间=', end_1-start_1)
print('Dyson_way执行时间=', end_2-start_2)
def General_way(fermi_energy, hamiltonian):
dim_hamiltonian = hamiltonian.shape[0]
green = np.linalg.inv((fermi_energy)*np.eye(dim_hamiltonian)-hamiltonian)
return green
def Dyson_way(fermi_energy, h00, h01, length):
dim = h00.shape[0]
for ix in range(length):
if ix == 0:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00) # 如果有左电极还需要减去左电极的自能left_self_energy
green_0n_n = copy.deepcopy(green_nn_n) # 如果直接用等于两个变量会指向相同的id改变一个值另外一个值可能会发生改变容易出错所以要用上这个COPY
elif ix != length-1:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
else: # 这里和elif ix != length-1中的内容完全一样但如果有右电极这里是还需要减去右电极的自能right_self_energy
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
return green_0n_n
if __name__ == '__main__':
main()

View File

@@ -1,102 +1,102 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
def matrix_00(width, length):
h00 = np.zeros((width*length, width*length))
for x in range(length):
for y in range(width-1):
h00[x*width+y, x*width+y+1] = 1
h00[x*width+y+1, x*width+y] = 1
for x in range(length-1):
for y in range(width):
h00[x*width+y, (x+1)*width+y] = 1
h00[(x+1)*width+y, x*width+y] = 1
return h00
def matrix_01(width, length):
h01 = np.identity(width*length)
return h01
def main():
height = 2 # z
width = 3 # y
length = 4 # x
eta = 1e-2
E = 0
h00 = matrix_00(width, length)
h01 = matrix_01(width, length)
G_ii_n_array = G_ii_n_with_Dyson_equation(width, length, height, E, eta, h00, h01)
for i0 in range(height):
print('z=', i0+1, ':')
for j0 in range(width):
print(' y=', j0+1, ':')
for k0 in range(length):
print(' x=', k0+1, ' ', -np.imag(G_ii_n_array[i0, k0*width+j0, k0*width+j0])/pi) # 态密度
def G_ii_n_with_Dyson_equation(width, length, height, E, eta, h00, h01):
dim = length*width
G_ii_n_array = np.zeros((height, dim, dim), dtype=complex)
G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(dim)-h00)
for i in range(height): # i为格林函数的右下指标
# 初始化开始
G_nn_n_minus = G_11_1
G_in_n_minus = G_11_1
G_ni_n_minus = G_11_1
G_ii_n_minus = G_11_1
for i0 in range(i):
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
G_nn_n_minus = G_nn_n
if i!=0:
G_in_n_minus = G_nn_n
G_ni_n_minus = G_nn_n
G_ii_n_minus = G_nn_n
# 初始化结束
for j0 in range(height-1-i): # j0为格林函数的右上指标表示当前体系大小即G^{(j0)}
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
G_nn_n_minus = G_nn_n
G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵
G_ii_n_minus = G_ii_n
G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n)
G_in_n_minus = G_in_n
G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus)
G_ni_n_minus = G_ni_n
G_ii_n_array[i, :, :] = G_ii_n_minus
return G_ii_n_array
def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2
dim = H00.shape[0]
G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V))
return G_nn_n
def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2
G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n)
return G_in_n
def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2
G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus)
return G_ni_n
def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i
G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus)
return G_ii_n
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
def matrix_00(width, length):
h00 = np.zeros((width*length, width*length))
for x in range(length):
for y in range(width-1):
h00[x*width+y, x*width+y+1] = 1
h00[x*width+y+1, x*width+y] = 1
for x in range(length-1):
for y in range(width):
h00[x*width+y, (x+1)*width+y] = 1
h00[(x+1)*width+y, x*width+y] = 1
return h00
def matrix_01(width, length):
h01 = np.identity(width*length)
return h01
def main():
height = 2 # z
width = 3 # y
length = 4 # x
eta = 1e-2
E = 0
h00 = matrix_00(width, length)
h01 = matrix_01(width, length)
G_ii_n_array = G_ii_n_with_Dyson_equation(width, length, height, E, eta, h00, h01)
for i0 in range(height):
print('z=', i0+1, ':')
for j0 in range(width):
print(' y=', j0+1, ':')
for k0 in range(length):
print(' x=', k0+1, ' ', -np.imag(G_ii_n_array[i0, k0*width+j0, k0*width+j0])/pi) # 态密度
def G_ii_n_with_Dyson_equation(width, length, height, E, eta, h00, h01):
dim = length*width
G_ii_n_array = np.zeros((height, dim, dim), dtype=complex)
G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(dim)-h00)
for i in range(height): # i为格林函数的右下指标
# 初始化开始
G_nn_n_minus = G_11_1
G_in_n_minus = G_11_1
G_ni_n_minus = G_11_1
G_ii_n_minus = G_11_1
for i0 in range(i):
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
G_nn_n_minus = G_nn_n
if i!=0:
G_in_n_minus = G_nn_n
G_ni_n_minus = G_nn_n
G_ii_n_minus = G_nn_n
# 初始化结束
for j0 in range(height-1-i): # j0为格林函数的右上指标表示当前体系大小即G^{(j0)}
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
G_nn_n_minus = G_nn_n
G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵
G_ii_n_minus = G_ii_n
G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n)
G_in_n_minus = G_in_n
G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus)
G_ni_n_minus = G_ni_n
G_ii_n_array[i, :, :] = G_ii_n_minus
return G_ii_n_array
def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2
dim = H00.shape[0]
G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V))
return G_nn_n
def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2
G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n)
return G_in_n
def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2
G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus)
return G_ni_n
def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i
G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus)
return G_ii_n
if __name__ == '__main__':
main()

View File

@@ -1,99 +1,99 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
def matrix_00(width, length):
h00 = np.zeros((width*length, width*length))
for x in range(length):
for y in range(width-1):
h00[x*width+y, x*width+y+1] = 1
h00[x*width+y+1, x*width+y] = 1
for x in range(length-1):
for y in range(width):
h00[x*width+y, (x+1)*width+y] = 1
h00[(x+1)*width+y, x*width+y] = 1
return h00
def matrix_01(width, length):
h01 = np.identity(width*length)
return h01
def main():
height = 2 # z
width = 3 # y
length = 4 # x
eta = 1e-2
E = 0
h00 = matrix_00(width, length)
h01 = matrix_01(width, length)
G_ii_n_with_Dyson_equation_version_II(width, length, height, E, eta, h00, h01)
def G_ii_n_with_Dyson_equation_version_II(width, length, height, E, eta, h00, h01):
dim = length*width
G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(dim)-h00)
for i in range(height): # i为格林函数的右下指标
# 初始化开始
G_nn_n_minus = G_11_1
G_in_n_minus = G_11_1
G_ni_n_minus = G_11_1
G_ii_n_minus = G_11_1
for i0 in range(i):
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
G_nn_n_minus = G_nn_n
if i!=0:
G_in_n_minus = G_nn_n
G_ni_n_minus = G_nn_n
G_ii_n_minus = G_nn_n
# 初始化结束
for j0 in range(height-1-i): # j0为格林函数的右上指标表示当前体系大小即G^{(j0)}
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
G_nn_n_minus = G_nn_n
G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵
G_ii_n_minus = G_ii_n
G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n)
G_in_n_minus = G_in_n
G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus)
G_ni_n_minus = G_ni_n
# 输出
print('z=', i+1, ':')
for j0 in range(width):
print(' y=', j0+1, ':')
for k0 in range(length):
print(' x=', k0+1, ' ', -np.imag(G_ii_n_minus[k0*width+j0, k0*width+j0])/pi) # 态密度
def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2
dim = H00.shape[0]
G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V))
return G_nn_n
def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2
G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n)
return G_in_n
def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2
G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus)
return G_ni_n
def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i
G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus)
return G_ii_n
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
def matrix_00(width, length):
h00 = np.zeros((width*length, width*length))
for x in range(length):
for y in range(width-1):
h00[x*width+y, x*width+y+1] = 1
h00[x*width+y+1, x*width+y] = 1
for x in range(length-1):
for y in range(width):
h00[x*width+y, (x+1)*width+y] = 1
h00[(x+1)*width+y, x*width+y] = 1
return h00
def matrix_01(width, length):
h01 = np.identity(width*length)
return h01
def main():
height = 2 # z
width = 3 # y
length = 4 # x
eta = 1e-2
E = 0
h00 = matrix_00(width, length)
h01 = matrix_01(width, length)
G_ii_n_with_Dyson_equation_version_II(width, length, height, E, eta, h00, h01)
def G_ii_n_with_Dyson_equation_version_II(width, length, height, E, eta, h00, h01):
dim = length*width
G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(dim)-h00)
for i in range(height): # i为格林函数的右下指标
# 初始化开始
G_nn_n_minus = G_11_1
G_in_n_minus = G_11_1
G_ni_n_minus = G_11_1
G_ii_n_minus = G_11_1
for i0 in range(i):
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
G_nn_n_minus = G_nn_n
if i!=0:
G_in_n_minus = G_nn_n
G_ni_n_minus = G_nn_n
G_ii_n_minus = G_nn_n
# 初始化结束
for j0 in range(height-1-i): # j0为格林函数的右上指标表示当前体系大小即G^{(j0)}
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
G_nn_n_minus = G_nn_n
G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵
G_ii_n_minus = G_ii_n
G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n)
G_in_n_minus = G_in_n
G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus)
G_ni_n_minus = G_ni_n
# 输出
print('z=', i+1, ':')
for j0 in range(width):
print(' y=', j0+1, ':')
for k0 in range(length):
print(' x=', k0+1, ' ', -np.imag(G_ii_n_minus[k0*width+j0, k0*width+j0])/pi) # 态密度
def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2
dim = H00.shape[0]
G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V))
return G_nn_n
def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2
G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n)
return G_in_n
def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2
G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus)
return G_ni_n
def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i
G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus)
return G_ii_n
if __name__ == '__main__':
main()

View File

@@ -1,49 +1,49 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
def hamiltonian(width, length, height):
h = np.zeros((width*length*height, width*length*height))
for i0 in range(length):
for j0 in range(width):
for k0 in range(height-1):
h[k0*width*length+i0*width+j0, (k0+1)*width*length+i0*width+j0] = 1
h[(k0+1)*width*length+i0*width+j0, k0*width*length+i0*width+j0] = 1
for i0 in range(length):
for j0 in range(width-1):
for k0 in range(height):
h[k0*width*length+i0*width+j0, k0*width*length+i0*width+j0+1] = 1
h[k0*width*length+i0*width+j0+1, k0*width*length+i0*width+j0] = 1
for i0 in range(length-1):
for j0 in range(width):
for k0 in range(height):
h[k0*width*length+i0*width+j0, k0*width*length+(i0+1)*width+j0] = 1
h[k0*width*length+(i0+1)*width+j0, k0*width*length+i0*width+j0] = 1
return h
def main():
height = 2 # z
width = 3 # y
length = 4 # x
h = hamiltonian(width, length, height)
E = 0
green = np.linalg.inv((E+1e-2j)*np.eye(width*length*height)-h)
for k0 in range(height):
print('z=', k0+1, ':')
for j0 in range(width):
print(' y=', j0+1, ':')
for i0 in range(length):
print(' x=', i0+1, ' ', -np.imag(green[k0*width*length+i0*width+j0, k0*width*length+i0*width+j0])/pi) # 态密度
if __name__ == "__main__":
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
def hamiltonian(width, length, height):
h = np.zeros((width*length*height, width*length*height))
for i0 in range(length):
for j0 in range(width):
for k0 in range(height-1):
h[k0*width*length+i0*width+j0, (k0+1)*width*length+i0*width+j0] = 1
h[(k0+1)*width*length+i0*width+j0, k0*width*length+i0*width+j0] = 1
for i0 in range(length):
for j0 in range(width-1):
for k0 in range(height):
h[k0*width*length+i0*width+j0, k0*width*length+i0*width+j0+1] = 1
h[k0*width*length+i0*width+j0+1, k0*width*length+i0*width+j0] = 1
for i0 in range(length-1):
for j0 in range(width):
for k0 in range(height):
h[k0*width*length+i0*width+j0, k0*width*length+(i0+1)*width+j0] = 1
h[k0*width*length+(i0+1)*width+j0, k0*width*length+i0*width+j0] = 1
return h
def main():
height = 2 # z
width = 3 # y
length = 4 # x
h = hamiltonian(width, length, height)
E = 0
green = np.linalg.inv((E+1e-2j)*np.eye(width*length*height)-h)
for k0 in range(height):
print('z=', k0+1, ':')
for j0 in range(width):
print(' y=', j0+1, ':')
for i0 in range(length):
print(' x=', i0+1, ' ', -np.imag(green[k0*width*length+i0*width+j0, k0*width*length+i0*width+j0])/pi) # 态密度
if __name__ == "__main__":
main()

View File

@@ -1,95 +1,95 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
def matrix_00(width):
h00 = np.zeros((width, width))
for width0 in range(width-1):
h00[width0, width0+1] = 1
h00[width0+1, width0] = 1
return h00
def matrix_01(width):
h01 = np.identity(width)
return h01
def main():
width = 2
length = 3
eta = 1e-2
E = 0
h00 = matrix_00(width)
h01 = matrix_01(width)
G_ii_n_array = G_ii_n_with_Dyson_equation(width, length, E, eta, h00, h01)
for i0 in range(length):
# print('G_{'+str(i0+1)+','+str(i0+1)+'}^{('+str(length)+')}:')
# print(G_ii_n_array[i0, :, :],'\n')
print('x=', i0+1, ':')
for j0 in range(width):
print(' y=', j0+1, ' ', -np.imag(G_ii_n_array[i0, j0, j0])/pi) # 态密度
def G_ii_n_with_Dyson_equation(width, length, E, eta, h00, h01):
G_ii_n_array = np.zeros((length, width, width), complex)
G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(width)-h00)
for i in range(length): # i为格林函数的右下指标
# 初始化开始
G_nn_n_minus = G_11_1
G_in_n_minus = G_11_1
G_ni_n_minus = G_11_1
G_ii_n_minus = G_11_1
for i0 in range(i):
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
G_nn_n_minus = G_nn_n
if i!=0:
G_in_n_minus = G_nn_n
G_ni_n_minus = G_nn_n
G_ii_n_minus = G_nn_n
# 初始化结束
for j0 in range(length-1-i): # j0为格林函数的右上指标表示当前体系大小即G^{(j0)}
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
G_nn_n_minus = G_nn_n
G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵
G_ii_n_minus = G_ii_n
G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n)
G_in_n_minus = G_in_n
G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus)
G_ni_n_minus = G_ni_n
G_ii_n_array[i, :, :] = G_ii_n_minus
return G_ii_n_array
def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2
dim = H00.shape[0]
G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V))
return G_nn_n
def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2
G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n)
return G_in_n
def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2
G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus)
return G_ni_n
def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i
G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus)
return G_ii_n
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
def matrix_00(width):
h00 = np.zeros((width, width))
for width0 in range(width-1):
h00[width0, width0+1] = 1
h00[width0+1, width0] = 1
return h00
def matrix_01(width):
h01 = np.identity(width)
return h01
def main():
width = 2
length = 3
eta = 1e-2
E = 0
h00 = matrix_00(width)
h01 = matrix_01(width)
G_ii_n_array = G_ii_n_with_Dyson_equation(width, length, E, eta, h00, h01)
for i0 in range(length):
# print('G_{'+str(i0+1)+','+str(i0+1)+'}^{('+str(length)+')}:')
# print(G_ii_n_array[i0, :, :],'\n')
print('x=', i0+1, ':')
for j0 in range(width):
print(' y=', j0+1, ' ', -np.imag(G_ii_n_array[i0, j0, j0])/pi) # 态密度
def G_ii_n_with_Dyson_equation(width, length, E, eta, h00, h01):
G_ii_n_array = np.zeros((length, width, width), complex)
G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(width)-h00)
for i in range(length): # i为格林函数的右下指标
# 初始化开始
G_nn_n_minus = G_11_1
G_in_n_minus = G_11_1
G_ni_n_minus = G_11_1
G_ii_n_minus = G_11_1
for i0 in range(i):
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
G_nn_n_minus = G_nn_n
if i!=0:
G_in_n_minus = G_nn_n
G_ni_n_minus = G_nn_n
G_ii_n_minus = G_nn_n
# 初始化结束
for j0 in range(length-1-i): # j0为格林函数的右上指标表示当前体系大小即G^{(j0)}
G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus)
G_nn_n_minus = G_nn_n
G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵
G_ii_n_minus = G_ii_n
G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n)
G_in_n_minus = G_in_n
G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus)
G_ni_n_minus = G_ni_n
G_ii_n_array[i, :, :] = G_ii_n_minus
return G_ii_n_array
def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2
dim = H00.shape[0]
G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V))
return G_nn_n
def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2
G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n)
return G_in_n
def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2
G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus)
return G_ni_n
def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i
G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus)
return G_ii_n
if __name__ == '__main__':
main()

View File

@@ -1,41 +1,41 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
def hamiltonian(width, length):
h = np.zeros((width*length, width*length))
for i0 in range(length):
for j0 in range(width-1):
h[i0*width+j0, i0*width+j0+1] = 1
h[i0*width+j0+1, i0*width+j0] = 1
for i0 in range(length-1):
for j0 in range(width):
h[i0*width+j0, (i0+1)*width+j0] = 1
h[(i0+1)*width+j0, i0*width+j0] = 1
return h
def main():
width = 2
length = 3
h = hamiltonian(width, length)
E = 0
green = np.linalg.inv((E+1e-2j)*np.eye(width*length)-h)
for i0 in range(length):
# print('G_{'+str(i0+1)+','+str(i0+1)+'}^{('+str(length)+')}:')
# print(green[i0*width+0: i0*width+width, i0*width+0: i0*width+width], '\n')
print('x=', i0+1, ':')
for j0 in range(width):
print(' y=', j0+1, ' ', -np.imag(green[i0*width+j0, i0*width+j0])/pi)
if __name__ == "__main__":
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/7650
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
def hamiltonian(width, length):
h = np.zeros((width*length, width*length))
for i0 in range(length):
for j0 in range(width-1):
h[i0*width+j0, i0*width+j0+1] = 1
h[i0*width+j0+1, i0*width+j0] = 1
for i0 in range(length-1):
for j0 in range(width):
h[i0*width+j0, (i0+1)*width+j0] = 1
h[(i0+1)*width+j0, i0*width+j0] = 1
return h
def main():
width = 2
length = 3
h = hamiltonian(width, length)
E = 0
green = np.linalg.inv((E+1e-2j)*np.eye(width*length)-h)
for i0 in range(length):
# print('G_{'+str(i0+1)+','+str(i0+1)+'}^{('+str(length)+')}:')
# print(green[i0*width+0: i0*width+width, i0*width+0: i0*width+width], '\n')
print('x=', i0+1, ':')
for j0 in range(width):
print(' y=', j0+1, ' ', -np.imag(green[i0*width+j0, i0*width+j0])/pi)
if __name__ == "__main__":
main()

View File

@@ -1,69 +1,69 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/408
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N, M, t1): # graphene哈密顿量N是条带的宽度参数
# 初始化为零矩阵
h00 = np.zeros((4*N, 4*N), dtype=complex)
h01 = np.zeros((4*N, 4*N), dtype=complex)
# 原胞内的跃迁h00
for i in range(N):
h00[i*4+0, i*4+0] = M
h00[i*4+1, i*4+1] = -M
h00[i*4+2, i*4+2] = M
h00[i*4+3, i*4+3] = -M
# 最近邻
h00[i*4+0, i*4+1] = t1
h00[i*4+1, i*4+0] = t1
h00[i*4+1, i*4+2] = t1
h00[i*4+2, i*4+1] = t1
h00[i*4+2, i*4+3] = t1
h00[i*4+3, i*4+2] = t1
for i in range(N-1):
# 最近邻
h00[i*4+3, (i+1)*4+0] = t1
h00[(i+1)*4+0, i*4+3] = t1
# 原胞间的跃迁h01
for i in range(N):
# 最近邻
h01[i*4+1, i*4+0] = t1
h01[i*4+2, i*4+3] = t1
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
return matrix
def main():
hamiltonian0 = functools.partial(hamiltonian, N=40, M=0, t1=1)
k = np.linspace(-pi, pi, 300)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/408
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N, M, t1): # graphene哈密顿量N是条带的宽度参数
# 初始化为零矩阵
h00 = np.zeros((4*N, 4*N), dtype=complex)
h01 = np.zeros((4*N, 4*N), dtype=complex)
# 原胞内的跃迁h00
for i in range(N):
h00[i*4+0, i*4+0] = M
h00[i*4+1, i*4+1] = -M
h00[i*4+2, i*4+2] = M
h00[i*4+3, i*4+3] = -M
# 最近邻
h00[i*4+0, i*4+1] = t1
h00[i*4+1, i*4+0] = t1
h00[i*4+1, i*4+2] = t1
h00[i*4+2, i*4+1] = t1
h00[i*4+2, i*4+3] = t1
h00[i*4+3, i*4+2] = t1
for i in range(N-1):
# 最近邻
h00[i*4+3, (i+1)*4+0] = t1
h00[(i+1)*4+0, i*4+3] = t1
# 原胞间的跃迁h01
for i in range(N):
# 最近邻
h01[i*4+1, i*4+0] = t1
h01[i*4+2, i*4+3] = t1
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
return matrix
def main():
hamiltonian0 = functools.partial(hamiltonian, N=40, M=0, t1=1)
k = np.linspace(-pi, pi, 300)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,65 +1,65 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/408
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k1, k2, M, t1, a=1/sqrt(3)): # graphene哈密顿量a为原子间距不赋值的话默认为1/sqrt(3)
# 初始化为零矩阵
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term),用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# # 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
matrix = h0 + h1
return matrix
def main():
hamiltonian0 = functools.partial(hamiltonian, M=0, t1=1, a=1/sqrt(3)) # 使用偏函数,固定一些参数
k1 = np.linspace(-2*pi, 2*pi, 500)
k2 = np.linspace(-2*pi, 2*pi, 500)
plot_bands_two_dimension(k1, k2, hamiltonian0)
def plot_bands_two_dimension(k1, k2, hamiltonian):
from matplotlib import cm
dim = hamiltonian(0, 0).shape[0]
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1, dim))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
matrix0 = hamiltonian(k10, k20)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
fig = plt.figure()
ax = fig.gca(projection='3d')
k1, k2 = np.meshgrid(k1, k2)
for dim0 in range(dim):
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], rcount=200, ccount=200, cmap=cm.coolwarm, linewidth=0, antialiased=False)
plt.show()
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/408
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k1, k2, M, t1, a=1/sqrt(3)): # graphene哈密顿量a为原子间距不赋值的话默认为1/sqrt(3)
# 初始化为零矩阵
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term),用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# # 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
matrix = h0 + h1
return matrix
def main():
hamiltonian0 = functools.partial(hamiltonian, M=0, t1=1, a=1/sqrt(3)) # 使用偏函数,固定一些参数
k1 = np.linspace(-2*pi, 2*pi, 500)
k2 = np.linspace(-2*pi, 2*pi, 500)
plot_bands_two_dimension(k1, k2, hamiltonian0)
def plot_bands_two_dimension(k1, k2, hamiltonian):
from matplotlib import cm
dim = hamiltonian(0, 0).shape[0]
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1, dim))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
matrix0 = hamiltonian(k10, k20)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
fig = plt.figure()
ax = fig.gca(projection='3d')
k1, k2 = np.meshgrid(k1, k2)
for dim0 in range(dim):
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], rcount=200, ccount=200, cmap=cm.coolwarm, linewidth=0, antialiased=False)
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,94 +1,94 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/410
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N, M, t1, t2, phi): # Haldane哈密顿量N是条带的宽度参数
# 初始化为零矩阵
h00 = np.zeros((4*N, 4*N), dtype=complex)
h01 = np.zeros((4*N, 4*N), dtype=complex)
# 原胞内的跃迁h00
for i in range(N):
h00[i*4+0, i*4+0] = M
h00[i*4+1, i*4+1] = -M
h00[i*4+2, i*4+2] = M
h00[i*4+3, i*4+3] = -M
# 最近邻
h00[i*4+0, i*4+1] = t1
h00[i*4+1, i*4+0] = t1
h00[i*4+1, i*4+2] = t1
h00[i*4+2, i*4+1] = t1
h00[i*4+2, i*4+3] = t1
h00[i*4+3, i*4+2] = t1
# 次近邻
h00[i*4+0, i*4+2] = t2*cmath.exp(-1j*phi)
h00[i*4+2, i*4+0] = h00[i*4+0, i*4+2].conj()
h00[i*4+1, i*4+3] = t2*cmath.exp(-1j*phi)
h00[i*4+3, i*4+1] = h00[i*4+1, i*4+3].conj()
for i in range(N-1):
# 最近邻
h00[i*4+3, (i+1)*4+0] = t1
h00[(i+1)*4+0, i*4+3] = t1
# 次近邻
h00[i*4+2, (i+1)*4+0] = t2*cmath.exp(1j*phi)
h00[(i+1)*4+0, i*4+2] = h00[i*4+2, (i+1)*4+0].conj()
h00[i*4+3, (i+1)*4+1] = t2*cmath.exp(1j*phi)
h00[(i+1)*4+1, i*4+3] = h00[i*4+3, (i+1)*4+1].conj()
# 原胞间的跃迁h01
for i in range(N):
# 最近邻
h01[i*4+1, i*4+0] = t1
h01[i*4+2, i*4+3] = t1
# 次近邻
h01[i*4+0, i*4+0] = t2*cmath.exp(1j*phi)
h01[i*4+1, i*4+1] = t2*cmath.exp(-1j*phi)
h01[i*4+2, i*4+2] = t2*cmath.exp(1j*phi)
h01[i*4+3, i*4+3] = t2*cmath.exp(-1j*phi)
h01[i*4+1, i*4+3] = t2*cmath.exp(1j*phi)
h01[i*4+2, i*4+0] = t2*cmath.exp(-1j*phi)
if i != 0:
h01[i*4+1, (i-1)*4+3] = t2*cmath.exp(1j*phi)
for i in range(N-1):
h01[i*4+2, (i+1)*4+0] = t2*cmath.exp(-1j*phi)
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
return matrix
def main():
hamiltonian0 = functools.partial(hamiltonian, N=40, M=2/3, t1=1, t2=1/3, phi=pi/4)
k = np.linspace(-pi, pi, 300)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/410
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N, M, t1, t2, phi): # Haldane哈密顿量N是条带的宽度参数
# 初始化为零矩阵
h00 = np.zeros((4*N, 4*N), dtype=complex)
h01 = np.zeros((4*N, 4*N), dtype=complex)
# 原胞内的跃迁h00
for i in range(N):
h00[i*4+0, i*4+0] = M
h00[i*4+1, i*4+1] = -M
h00[i*4+2, i*4+2] = M
h00[i*4+3, i*4+3] = -M
# 最近邻
h00[i*4+0, i*4+1] = t1
h00[i*4+1, i*4+0] = t1
h00[i*4+1, i*4+2] = t1
h00[i*4+2, i*4+1] = t1
h00[i*4+2, i*4+3] = t1
h00[i*4+3, i*4+2] = t1
# 次近邻
h00[i*4+0, i*4+2] = t2*cmath.exp(-1j*phi)
h00[i*4+2, i*4+0] = h00[i*4+0, i*4+2].conj()
h00[i*4+1, i*4+3] = t2*cmath.exp(-1j*phi)
h00[i*4+3, i*4+1] = h00[i*4+1, i*4+3].conj()
for i in range(N-1):
# 最近邻
h00[i*4+3, (i+1)*4+0] = t1
h00[(i+1)*4+0, i*4+3] = t1
# 次近邻
h00[i*4+2, (i+1)*4+0] = t2*cmath.exp(1j*phi)
h00[(i+1)*4+0, i*4+2] = h00[i*4+2, (i+1)*4+0].conj()
h00[i*4+3, (i+1)*4+1] = t2*cmath.exp(1j*phi)
h00[(i+1)*4+1, i*4+3] = h00[i*4+3, (i+1)*4+1].conj()
# 原胞间的跃迁h01
for i in range(N):
# 最近邻
h01[i*4+1, i*4+0] = t1
h01[i*4+2, i*4+3] = t1
# 次近邻
h01[i*4+0, i*4+0] = t2*cmath.exp(1j*phi)
h01[i*4+1, i*4+1] = t2*cmath.exp(-1j*phi)
h01[i*4+2, i*4+2] = t2*cmath.exp(1j*phi)
h01[i*4+3, i*4+3] = t2*cmath.exp(-1j*phi)
h01[i*4+1, i*4+3] = t2*cmath.exp(1j*phi)
h01[i*4+2, i*4+0] = t2*cmath.exp(-1j*phi)
if i != 0:
h01[i*4+1, (i-1)*4+3] = t2*cmath.exp(1j*phi)
for i in range(N-1):
h01[i*4+2, (i+1)*4+0] = t2*cmath.exp(-1j*phi)
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
return matrix
def main():
hamiltonian0 = functools.partial(hamiltonian, N=40, M=2/3, t1=1, t2=1/3, phi=pi/4)
k = np.linspace(-pi, pi, 300)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,70 +1,70 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/410
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量(a为原子间距不赋值的话默认为1/sqrt(3)
# 初始化为零矩阵
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
h2 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term),用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
# 次近邻项
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
matrix = h0 + h1 + h2 + h2.transpose().conj()
return matrix
def main():
hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=1/sqrt(3))
k1 = np.linspace(-2*pi, 2*pi, 500)
k2 = np.linspace(-2*pi, 2*pi, 500)
plot_bands_two_dimension(k1, k2, hamiltonian0)
def plot_bands_two_dimension(k1, k2, hamiltonian):
from matplotlib import cm
dim = hamiltonian(0, 0).shape[0]
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1, dim))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
matrix0 = hamiltonian(k10, k20)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
fig = plt.figure()
ax = fig.gca(projection='3d')
k1, k2 = np.meshgrid(k1, k2)
for dim0 in range(dim):
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
plt.show()
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/410
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量(a为原子间距不赋值的话默认为1/sqrt(3)
# 初始化为零矩阵
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
h2 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term),用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
# 次近邻项
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
matrix = h0 + h1 + h2 + h2.transpose().conj()
return matrix
def main():
hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=1/sqrt(3))
k1 = np.linspace(-2*pi, 2*pi, 500)
k2 = np.linspace(-2*pi, 2*pi, 500)
plot_bands_two_dimension(k1, k2, hamiltonian0)
def plot_bands_two_dimension(k1, k2, hamiltonian):
from matplotlib import cm
dim = hamiltonian(0, 0).shape[0]
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1, dim))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
matrix0 = hamiltonian(k10, k20)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
fig = plt.figure()
ax = fig.gca(projection='3d')
k1, k2 = np.meshgrid(k1, k2)
for dim0 in range(dim):
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,84 +1,84 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/2327
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入sqrt(), pi, exp等
import cmath # 要处理复数情况用到cmath.exp()
import functools # 使用偏函数functools.partial()
def get_terms(A, B, C, D, M, a):
E_s = C+M-4*(D+B)/(a**2)
E_p = C-M-4*(D-B)/(a**2)
V_ss = (D+B)/(a**2)
V_pp = (D-B)/(a**2)
V_sp = -1j*A/(2*a)
H0 = np.zeros((4, 4), dtype=complex) # 在位能 (on-site energy)
H1 = np.zeros((4, 4), dtype=complex) # x方向的跃迁 (hopping)
H2 = np.zeros((4, 4), dtype=complex) # y方向的跃迁 (hopping)
H0[0, 0] = E_s
H0[1, 1] = E_p
H0[2, 2] = E_s
H0[3, 3] = E_p
H1[0, 0] = V_ss
H1[1, 1] = V_pp
H1[2, 2] = V_ss
H1[3, 3] = V_pp
H1[0, 1] = V_sp
H1[1, 0] = -np.conj(V_sp)
H1[2, 3] = np.conj(V_sp)
H1[3, 2] = -V_sp
H2[0, 0] = V_ss
H2[1, 1] = V_pp
H2[2, 2] = V_ss
H2[3, 3] = V_pp
H2[0, 1] = 1j*V_sp
H2[1, 0] = 1j*np.conj(V_sp)
H2[2, 3] = -1j*np.conj(V_sp)
H2[3, 2] = -1j*V_sp
return H0, H1, H2
def BHZ_model(k, A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01, a=1, N=100): # 这边数值是不赋值时的默认参数
H0, H1, H2 = get_terms(A, B, C, D, M, a)
H00 = np.zeros((4*N, 4*N), dtype=complex) # 元胞内条带宽度为N
H01 = np.zeros((4*N, 4*N), dtype=complex) # 条带方向元胞间的跃迁
for i in range(N):
H00[i*4+0:i*4+4, i*4+0:i*4+4] = H0 # a:b代表 a <= x < b
H01[i*4+0:i*4+4, i*4+0:i*4+4] = H1
for i in range(N-1):
H00[i*4+0:i*4+4, (i+1)*4+0:(i+1)*4+4] = H2
H00[(i+1)*4+0:(i+1)*4+4, i*4+0:i*4+4] = np.conj(np.transpose(H2))
H = H00 + H01 * cmath.exp(-1j * k) + H01.transpose().conj() * cmath.exp(1j * k)
return H
def main():
hamiltonian0 = functools.partial(BHZ_model, N=50) # 使用偏函数,固定一些参数
k = np.linspace(-pi, pi, 300) # 300
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian, filename='bands_1D'):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim)) # np.zeros()里要用tuple
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k') # -.
# plt.savefig(filename + '.jpg') # plt.savefig(filename+'.eps')
plt.show()
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/2327
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入sqrt(), pi, exp等
import cmath # 要处理复数情况用到cmath.exp()
import functools # 使用偏函数functools.partial()
def get_terms(A, B, C, D, M, a):
E_s = C+M-4*(D+B)/(a**2)
E_p = C-M-4*(D-B)/(a**2)
V_ss = (D+B)/(a**2)
V_pp = (D-B)/(a**2)
V_sp = -1j*A/(2*a)
H0 = np.zeros((4, 4), dtype=complex) # 在位能 (on-site energy)
H1 = np.zeros((4, 4), dtype=complex) # x方向的跃迁 (hopping)
H2 = np.zeros((4, 4), dtype=complex) # y方向的跃迁 (hopping)
H0[0, 0] = E_s
H0[1, 1] = E_p
H0[2, 2] = E_s
H0[3, 3] = E_p
H1[0, 0] = V_ss
H1[1, 1] = V_pp
H1[2, 2] = V_ss
H1[3, 3] = V_pp
H1[0, 1] = V_sp
H1[1, 0] = -np.conj(V_sp)
H1[2, 3] = np.conj(V_sp)
H1[3, 2] = -V_sp
H2[0, 0] = V_ss
H2[1, 1] = V_pp
H2[2, 2] = V_ss
H2[3, 3] = V_pp
H2[0, 1] = 1j*V_sp
H2[1, 0] = 1j*np.conj(V_sp)
H2[2, 3] = -1j*np.conj(V_sp)
H2[3, 2] = -1j*V_sp
return H0, H1, H2
def BHZ_model(k, A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01, a=1, N=100): # 这边数值是不赋值时的默认参数
H0, H1, H2 = get_terms(A, B, C, D, M, a)
H00 = np.zeros((4*N, 4*N), dtype=complex) # 元胞内条带宽度为N
H01 = np.zeros((4*N, 4*N), dtype=complex) # 条带方向元胞间的跃迁
for i in range(N):
H00[i*4+0:i*4+4, i*4+0:i*4+4] = H0 # a:b代表 a <= x < b
H01[i*4+0:i*4+4, i*4+0:i*4+4] = H1
for i in range(N-1):
H00[i*4+0:i*4+4, (i+1)*4+0:(i+1)*4+4] = H2
H00[(i+1)*4+0:(i+1)*4+4, i*4+0:i*4+4] = np.conj(np.transpose(H2))
H = H00 + H01 * cmath.exp(-1j * k) + H01.transpose().conj() * cmath.exp(1j * k)
return H
def main():
hamiltonian0 = functools.partial(BHZ_model, N=50) # 使用偏函数,固定一些参数
k = np.linspace(-pi, pi, 300) # 300
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian, filename='bands_1D'):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim)) # np.zeros()里要用tuple
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k') # -.
# plt.savefig(filename + '.jpg') # plt.savefig(filename+'.eps')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,69 +1,69 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4322
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N):
# 初始化为零矩阵
h = np.zeros((4*N, 4*N), dtype=complex)
t=1
a=1
t0=0.2 # 层间跃迁
V=0.2 # 层间的势能差为2V
for i in range(N):
h[i*4+0, i*4+0] = V
h[i*4+1, i*4+1] = V
h[i*4+2, i*4+2] = -V
h[i*4+3, i*4+3] = -V
h[i*4+0, i*4+1] = -t*(1+cmath.exp(1j*k*a))
h[i*4+1, i*4+0] = -t*(1+cmath.exp(-1j*k*a))
h[i*4+2, i*4+3] = -t*(1+cmath.exp(1j*k*a))
h[i*4+3, i*4+2] = -t*(1+cmath.exp(-1j*k*a))
h[i*4+0, i*4+3] = -t0
h[i*4+3, i*4+0] = -t0
for i in range(N-1):
# 最近邻
h[i*4+1, (i+1)*4+0] = -t
h[(i+1)*4+0, i*4+1] = -t
h[i*4+3, (i+1)*4+2] = -t
h[(i+1)*4+2, i*4+3] = -t
return h
def main():
hamiltonian0 = functools.partial(hamiltonian, N=100)
k = np.linspace(-pi, pi, 400)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
print(k0)
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4322
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N):
# 初始化为零矩阵
h = np.zeros((4*N, 4*N), dtype=complex)
t=1
a=1
t0=0.2 # 层间跃迁
V=0.2 # 层间的势能差为2V
for i in range(N):
h[i*4+0, i*4+0] = V
h[i*4+1, i*4+1] = V
h[i*4+2, i*4+2] = -V
h[i*4+3, i*4+3] = -V
h[i*4+0, i*4+1] = -t*(1+cmath.exp(1j*k*a))
h[i*4+1, i*4+0] = -t*(1+cmath.exp(-1j*k*a))
h[i*4+2, i*4+3] = -t*(1+cmath.exp(1j*k*a))
h[i*4+3, i*4+2] = -t*(1+cmath.exp(-1j*k*a))
h[i*4+0, i*4+3] = -t0
h[i*4+3, i*4+0] = -t0
for i in range(N-1):
# 最近邻
h[i*4+1, (i+1)*4+0] = -t
h[(i+1)*4+0, i*4+1] = -t
h[i*4+3, (i+1)*4+2] = -t
h[(i+1)*4+2, i*4+3] = -t
return h
def main():
hamiltonian0 = functools.partial(hamiltonian, N=100)
k = np.linspace(-pi, pi, 400)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
print(k0)
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,83 +1,83 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4322
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N):
# 初始化为零矩阵
h = np.zeros((4*N, 4*N), dtype=complex)
h11 = np.zeros((4*N, 4*N), dtype=complex) # 元胞内
h12 = np.zeros((4*N, 4*N), dtype=complex) # 元胞间
t=1
a=1
t0=0.2 # 层间跃迁
V=0.2 # 层间的势能差为2V
for i in range(N):
h11[i*2+0, i*2+0] = V
h11[i*2+1, i*2+1] = V
h11[N*2+i*2+0, N*2+i*2+0] = -V
h11[N*2+i*2+1, N*2+i*2+1] = -V
h11[i*2+0, i*2+1] = -t
h11[i*2+1, i*2+0] = -t
h11[N*2+i*2+0, N*2+i*2+1] = -t
h11[N*2+i*2+1, N*2+i*2+0] = -t
h11[i*2+0, N*2+i*2+1] = -t0
h11[N*2+i*2+1, i*2+0] = -t0
for i in range(N-1):
h11[i*2+1, (i+1)*2+0] = -t
h11[(i+1)*2+0, i*2+1] = -t
h11[N*2+i*2+1, N*2+(i+1)*2+0] = -t
h11[N*2+(i+1)*2+0, N*2+i*2+1] = -t
for i in range(N):
h12[i*2+0, i*2+1] = -t
h12[N*2+i*2+0, N*2+i*2+1] = -t
h= h11 + h12*cmath.exp(-1j*k*a) + h12.transpose().conj()*cmath.exp(1j*k*a)
return h
def main():
hamiltonian0 = functools.partial(hamiltonian, N=100)
k = np.linspace(-pi, pi, 400)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
print(k0)
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4322
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N):
# 初始化为零矩阵
h = np.zeros((4*N, 4*N), dtype=complex)
h11 = np.zeros((4*N, 4*N), dtype=complex) # 元胞内
h12 = np.zeros((4*N, 4*N), dtype=complex) # 元胞间
t=1
a=1
t0=0.2 # 层间跃迁
V=0.2 # 层间的势能差为2V
for i in range(N):
h11[i*2+0, i*2+0] = V
h11[i*2+1, i*2+1] = V
h11[N*2+i*2+0, N*2+i*2+0] = -V
h11[N*2+i*2+1, N*2+i*2+1] = -V
h11[i*2+0, i*2+1] = -t
h11[i*2+1, i*2+0] = -t
h11[N*2+i*2+0, N*2+i*2+1] = -t
h11[N*2+i*2+1, N*2+i*2+0] = -t
h11[i*2+0, N*2+i*2+1] = -t0
h11[N*2+i*2+1, i*2+0] = -t0
for i in range(N-1):
h11[i*2+1, (i+1)*2+0] = -t
h11[(i+1)*2+0, i*2+1] = -t
h11[N*2+i*2+1, N*2+(i+1)*2+0] = -t
h11[N*2+(i+1)*2+0, N*2+i*2+1] = -t
for i in range(N):
h12[i*2+0, i*2+1] = -t
h12[N*2+i*2+0, N*2+i*2+1] = -t
h= h11 + h12*cmath.exp(-1j*k*a) + h12.transpose().conj()*cmath.exp(1j*k*a)
return h
def main():
hamiltonian0 = functools.partial(hamiltonian, N=100)
k = np.linspace(-pi, pi, 400)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
print(k0)
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,104 +1,104 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4829
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N, M, t1, t2, phi): # Kane-Mele model
# 初始化为零矩阵
h00 = np.zeros((2*4*N, 2*4*N), dtype=complex) # 因为自旋有上有下所以整个维度要乘2。这里4是元胞内部重复单位的大小规定元胞大小以4来倍增。
h01 = np.zeros((2*4*N, 2*4*N), dtype=complex)
for spin in range(2):
# 原胞内的跃迁h00
for i in range(N):
# 最近邻
h00[i*4*2+0*2+spin, i*4*2+1*2+spin] = t1
h00[i*4*2+1*2+spin, i*4*2+0*2+spin] = t1
h00[i*4*2+1*2+spin, i*4*2+2*2+spin] = t1
h00[i*4*2+2*2+spin, i*4*2+1*2+spin] = t1
h00[i*4*2+2*2+spin, i*4*2+3*2+spin] = t1
h00[i*4*2+3*2+spin, i*4*2+2*2+spin] = t1
# 次近邻
h00[i*4*2+0*2+spin, i*4*2+2*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
h00[i*4*2+2*2+spin, i*4*2+0*2+spin] = h00[i*4*2+0*2+spin, i*4*2+2*2+spin].conj()
h00[i*4*2+1*2+spin, i*4*2+3*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
h00[i*4*2+3*2+spin, i*4*2+1*2+spin] = h00[i*4*2+1*2+spin, i*4*2+3*2+spin].conj()
for i in range(N-1):
# 最近邻
h00[i*4*2+3*2+spin, (i+1)*4*2+0*2+spin] = t1
h00[(i+1)*4*2+0*2+spin, i*4*2+3*2+spin] = t1
# 次近邻
h00[i*4*2+2*2+spin, (i+1)*4*2+0*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h00[(i+1)*4*2+0*2+spin, i*4*2+2*2+spin] = h00[i*4*2+2*2+spin, (i+1)*4*2+0*2+spin].conj()
h00[i*4*2+3*2+spin, (i+1)*4*2+1*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h00[(i+1)*4*2+1*2+spin, i*4*2+3*2+spin] = h00[i*4*2+3*2+spin, (i+1)*4*2+1*2+spin].conj()
# 原胞间的跃迁h01
for i in range(N):
# 最近邻
h01[i*4*2+1*2+spin, i*4*2+0*2+spin] = t1
h01[i*4*2+2*2+spin, i*4*2+3*2+spin] = t1
# 次近邻
h01[i*4*2+0*2+spin, i*4*2+0*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h01[i*4*2+1*2+spin, i*4*2+1*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
h01[i*4*2+2*2+spin, i*4*2+2*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h01[i*4*2+3*2+spin, i*4*2+3*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
h01[i*4*2+1*2+spin, i*4*2+3*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h01[i*4*2+2*2+spin, i*4*2+0*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
if i != 0:
h01[i*4*2+1*2+spin, (i-1)*4*2+3*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
for i in range(N-1):
h01[i*4*2+2*2+spin, (i+1)*4*2+0*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
return matrix
def sign_spin(spin):
if spin==0:
sign=1
else:
sign=-1
return sign
def main():
hamiltonian0 = functools.partial(hamiltonian, N=20, M=0, t1=1, t2=0.03, phi=pi/2)
k = np.linspace(0, 2*pi, 300)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.ylim(-1, 1)
plt.show()
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4829
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N, M, t1, t2, phi): # Kane-Mele model
# 初始化为零矩阵
h00 = np.zeros((2*4*N, 2*4*N), dtype=complex) # 因为自旋有上有下所以整个维度要乘2。这里4是元胞内部重复单位的大小规定元胞大小以4来倍增。
h01 = np.zeros((2*4*N, 2*4*N), dtype=complex)
for spin in range(2):
# 原胞内的跃迁h00
for i in range(N):
# 最近邻
h00[i*4*2+0*2+spin, i*4*2+1*2+spin] = t1
h00[i*4*2+1*2+spin, i*4*2+0*2+spin] = t1
h00[i*4*2+1*2+spin, i*4*2+2*2+spin] = t1
h00[i*4*2+2*2+spin, i*4*2+1*2+spin] = t1
h00[i*4*2+2*2+spin, i*4*2+3*2+spin] = t1
h00[i*4*2+3*2+spin, i*4*2+2*2+spin] = t1
# 次近邻
h00[i*4*2+0*2+spin, i*4*2+2*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
h00[i*4*2+2*2+spin, i*4*2+0*2+spin] = h00[i*4*2+0*2+spin, i*4*2+2*2+spin].conj()
h00[i*4*2+1*2+spin, i*4*2+3*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
h00[i*4*2+3*2+spin, i*4*2+1*2+spin] = h00[i*4*2+1*2+spin, i*4*2+3*2+spin].conj()
for i in range(N-1):
# 最近邻
h00[i*4*2+3*2+spin, (i+1)*4*2+0*2+spin] = t1
h00[(i+1)*4*2+0*2+spin, i*4*2+3*2+spin] = t1
# 次近邻
h00[i*4*2+2*2+spin, (i+1)*4*2+0*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h00[(i+1)*4*2+0*2+spin, i*4*2+2*2+spin] = h00[i*4*2+2*2+spin, (i+1)*4*2+0*2+spin].conj()
h00[i*4*2+3*2+spin, (i+1)*4*2+1*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h00[(i+1)*4*2+1*2+spin, i*4*2+3*2+spin] = h00[i*4*2+3*2+spin, (i+1)*4*2+1*2+spin].conj()
# 原胞间的跃迁h01
for i in range(N):
# 最近邻
h01[i*4*2+1*2+spin, i*4*2+0*2+spin] = t1
h01[i*4*2+2*2+spin, i*4*2+3*2+spin] = t1
# 次近邻
h01[i*4*2+0*2+spin, i*4*2+0*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h01[i*4*2+1*2+spin, i*4*2+1*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
h01[i*4*2+2*2+spin, i*4*2+2*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h01[i*4*2+3*2+spin, i*4*2+3*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
h01[i*4*2+1*2+spin, i*4*2+3*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h01[i*4*2+2*2+spin, i*4*2+0*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
if i != 0:
h01[i*4*2+1*2+spin, (i-1)*4*2+3*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
for i in range(N-1):
h01[i*4*2+2*2+spin, (i+1)*4*2+0*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
return matrix
def sign_spin(spin):
if spin==0:
sign=1
else:
sign=-1
return sign
def main():
hamiltonian0 = functools.partial(hamiltonian, N=20, M=0, t1=1, t2=0.03, phi=pi/2)
k = np.linspace(0, 2*pi, 300)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.ylim(-1, 1)
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,23 +1,23 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5375
"""
import numpy as np
def hamiltonian(width=3, length=3): # 方格子哈密顿量
h = np.zeros((width*length, width*length))
# y方向的跃迁
for x in range(length):
for y in range(width-1):
h[x*width+y, x*width+y+1] = 1
h[x*width+y+1, x*width+y] = 1
# x方向的跃迁
for x in range(length-1):
for y in range(width):
h[x*width+y, (x+1)*width+y] = 1
h[(x+1)*width+y, x*width+y] = 1
return h
h = hamiltonian()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5375
"""
import numpy as np
def hamiltonian(width=3, length=3): # 方格子哈密顿量
h = np.zeros((width*length, width*length))
# y方向的跃迁
for x in range(length):
for y in range(width-1):
h[x*width+y, x*width+y+1] = 1
h[x*width+y+1, x*width+y] = 1
# x方向的跃迁
for x in range(length-1):
for y in range(width):
h[x*width+y, (x+1)*width+y] = 1
h[(x+1)*width+y, x*width+y] = 1
return h
h = hamiltonian()
print(h)

View File

@@ -1,21 +1,21 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5375
"""
import numpy as np
def hamiltonian(width=3, length=3): # 方格子哈密顿量
hopping_x = np.zeros((length, length))
hopping_y = np.zeros((width, width))
for i in range(length-1):
hopping_x[i, i+1] = 1
hopping_x[i+1, i] = 1
for i in range(width-1):
hopping_y[i, i+1] = 1
hopping_y[i+1, i] = 1
h = np.kron(hopping_x, np.eye(width))+np.kron(np.eye(length), hopping_y)
return h
h = hamiltonian()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5375
"""
import numpy as np
def hamiltonian(width=3, length=3): # 方格子哈密顿量
hopping_x = np.zeros((length, length))
hopping_y = np.zeros((width, width))
for i in range(length-1):
hopping_x[i, i+1] = 1
hopping_x[i+1, i] = 1
for i in range(width-1):
hopping_y[i, i+1] = 1
hopping_y[i+1, i] = 1
h = np.kron(hopping_x, np.eye(width))+np.kron(np.eye(length), hopping_y)
return h
h = hamiltonian()
print(h)

View File

@@ -1,64 +1,64 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6077
"""
import numpy as np
from math import *
import matplotlib.pyplot as plt
def main():
n = 0.5
k1 = np.arange(-n*pi, n*pi, n/50)
k2 = np.arange(-n*pi, n*pi, n/50)
plot_bands_two_dimension_direct(k1, k2, hamiltonian)
def hamiltonian(kx,kz,ky=0): # surface states of Weyl semimetal
A = 1
H = A*kx
return H
def sigma_x():
return np.array([[0, 1],[1, 0]])
def sigma_y():
return np.array([[0, -1j],[1j, 0]])
def sigma_z():
return np.array([[1, 0],[0, -1]])
def plot_bands_two_dimension_direct(k1, k2, hamiltonian):
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
fig = plt.figure()
ax = fig.gca(projection='3d')
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
if (k10**2+k20**2 <= 1):
eigenvalue_k[j0, i0] = hamiltonian(k10, k20)
else:
eigenvalue_k[j0, i0] = 'nan'
j0 += 1
i0 += 1
k1, k2 = np.meshgrid(k1, k2)
ax.scatter(k1, k2, eigenvalue_k)
plt.xlabel('kx')
plt.ylabel('kz')
ax.set_zlabel('E')
plt.show()
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6077
"""
import numpy as np
from math import *
import matplotlib.pyplot as plt
def main():
n = 0.5
k1 = np.arange(-n*pi, n*pi, n/50)
k2 = np.arange(-n*pi, n*pi, n/50)
plot_bands_two_dimension_direct(k1, k2, hamiltonian)
def hamiltonian(kx,kz,ky=0): # surface states of Weyl semimetal
A = 1
H = A*kx
return H
def sigma_x():
return np.array([[0, 1],[1, 0]])
def sigma_y():
return np.array([[0, -1j],[1j, 0]])
def sigma_z():
return np.array([[1, 0],[0, -1]])
def plot_bands_two_dimension_direct(k1, k2, hamiltonian):
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
fig = plt.figure()
ax = fig.gca(projection='3d')
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
if (k10**2+k20**2 <= 1):
eigenvalue_k[j0, i0] = hamiltonian(k10, k20)
else:
eigenvalue_k[j0, i0] = 'nan'
j0 += 1
i0 += 1
k1, k2 = np.meshgrid(k1, k2)
ax.scatter(k1, k2, eigenvalue_k)
plt.xlabel('kx')
plt.ylabel('kz')
ax.set_zlabel('E')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,67 +1,67 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6077
"""
import numpy as np
from math import *
import matplotlib.pyplot as plt
def main():
n = 0.5
k1 = np.arange(-n*pi, n*pi, n/20)
k2 = np.arange(-n*pi, n*pi, n/20)
plot_bands_two_dimension(k1, k2, hamiltonian)
def hamiltonian(kx,kz,ky=0): # Weyl semimetal
A = 1
M0 = 1
M1 = 1
H = A*(kx*sigma_x()+ky*sigma_y())+(M0-M1*(kx**2+ky**2+kz**2))*sigma_z()
return H
def sigma_x():
return np.array([[0, 1],[1, 0]])
def sigma_y():
return np.array([[0, -1j],[1j, 0]])
def sigma_z():
return np.array([[1, 0],[0, -1]])
def plot_bands_two_dimension(k1, k2, hamiltonian):
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
dim = hamiltonian(0, 0).shape[0]
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1, dim))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
matrix0 = hamiltonian(k10, k20)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
fig = plt.figure()
ax = fig.gca(projection='3d')
k1, k2 = np.meshgrid(k1, k2)
for dim0 in range(dim):
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
plt.xlabel('kx')
plt.ylabel('kz')
ax.set_zlabel('E')
plt.show()
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6077
"""
import numpy as np
from math import *
import matplotlib.pyplot as plt
def main():
n = 0.5
k1 = np.arange(-n*pi, n*pi, n/20)
k2 = np.arange(-n*pi, n*pi, n/20)
plot_bands_two_dimension(k1, k2, hamiltonian)
def hamiltonian(kx,kz,ky=0): # Weyl semimetal
A = 1
M0 = 1
M1 = 1
H = A*(kx*sigma_x()+ky*sigma_y())+(M0-M1*(kx**2+ky**2+kz**2))*sigma_z()
return H
def sigma_x():
return np.array([[0, 1],[1, 0]])
def sigma_y():
return np.array([[0, -1j],[1j, 0]])
def sigma_z():
return np.array([[1, 0],[0, -1]])
def plot_bands_two_dimension(k1, k2, hamiltonian):
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
dim = hamiltonian(0, 0).shape[0]
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1, dim))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
matrix0 = hamiltonian(k10, k20)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
fig = plt.figure()
ax = fig.gca(projection='3d')
k1, k2 = np.meshgrid(k1, k2)
for dim0 in range(dim):
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
plt.xlabel('kx')
plt.ylabel('kz')
ax.set_zlabel('E')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,77 +1,77 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6260
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入sqrt(), pi, exp等
import cmath # 要处理复数情况用到cmath.exp()
def hamiltonian(k1, k2, M=0, t1=1, a=1/sqrt(3)): # Haldane哈密顿量(a为原子间距不赋值的话默认为1/sqrt(3)
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
h2 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term), 用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# # 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
matrix = h0 + h1
return matrix
def main():
a = 1/sqrt(3)
Gamma0 = np.array([0, 0])
M0 = np.array([0, 2*pi/3/a])
K0 = np.array([2*np.sqrt(3)*pi/9/a, 2*pi/3/a])
kn = 100 # 每个区域的取点数
n = 3 # n个区域K-GammaGamma-M, M-K
k1_array = np.zeros(kn*n)
k2_array = np.zeros(kn*n)
# K-Gamma轴
k1_array[0:kn] = np.linspace(0, K0[0], kn)[::-1] # [::-1]表示反转数组
k2_array[0:kn] = np.linspace(0, K0[1], kn)[::-1]
# Gamma-M轴
k1_array[kn:2*kn] = np.zeros(kn)
k2_array[kn:2*kn] = np.linspace(0, M0[1], kn)
# M-K轴
k1_array[2*kn:3*kn] = np.linspace(0, K0[0], kn)
k2_array[2*kn:3*kn] = np.ones(kn)*M0[1]
i0 = 0
dim = hamiltonian(0, 0).shape[0]
eigenvalue_k = np.zeros((kn*n, dim))
fig, ax = plt.subplots()
for kn0 in range(kn*n):
k1 = k1_array[kn0]
k2 = k2_array[kn0]
eigenvalue, eigenvector = np.linalg.eig(hamiltonian(k1, k2))
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(range(kn*n), eigenvalue_k[:, dim0], '-k')
plt.ylabel('E')
ax.set_xticks([0, kn, 2*kn, 3*kn])
ax.set_xticklabels(['K', 'Gamma', 'M', 'K'])
plt.xlim(0, n*kn)
plt.grid(axis='x',c='r',linestyle='--')
plt.show()
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6260
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入sqrt(), pi, exp等
import cmath # 要处理复数情况用到cmath.exp()
def hamiltonian(k1, k2, M=0, t1=1, a=1/sqrt(3)): # Haldane哈密顿量(a为原子间距不赋值的话默认为1/sqrt(3)
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
h2 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term), 用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# # 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
matrix = h0 + h1
return matrix
def main():
a = 1/sqrt(3)
Gamma0 = np.array([0, 0])
M0 = np.array([0, 2*pi/3/a])
K0 = np.array([2*np.sqrt(3)*pi/9/a, 2*pi/3/a])
kn = 100 # 每个区域的取点数
n = 3 # n个区域K-GammaGamma-M, M-K
k1_array = np.zeros(kn*n)
k2_array = np.zeros(kn*n)
# K-Gamma轴
k1_array[0:kn] = np.linspace(0, K0[0], kn)[::-1] # [::-1]表示反转数组
k2_array[0:kn] = np.linspace(0, K0[1], kn)[::-1]
# Gamma-M轴
k1_array[kn:2*kn] = np.zeros(kn)
k2_array[kn:2*kn] = np.linspace(0, M0[1], kn)
# M-K轴
k1_array[2*kn:3*kn] = np.linspace(0, K0[0], kn)
k2_array[2*kn:3*kn] = np.ones(kn)*M0[1]
i0 = 0
dim = hamiltonian(0, 0).shape[0]
eigenvalue_k = np.zeros((kn*n, dim))
fig, ax = plt.subplots()
for kn0 in range(kn*n):
k1 = k1_array[kn0]
k2 = k2_array[kn0]
eigenvalue, eigenvector = np.linalg.eig(hamiltonian(k1, k2))
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(range(kn*n), eigenvalue_k[:, dim0], '-k')
plt.ylabel('E')
ax.set_xticks([0, kn, 2*kn, 3*kn])
ax.set_xticklabels(['K', 'Gamma', 'M', 'K'])
plt.xlim(0, n*kn)
plt.grid(axis='x',c='r',linestyle='--')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,100 +1,100 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8557
"""
import numpy as np
from math import *
def hamiltonian(Nx, Ny):
delta = 1e-3
gamma = 1e-3
lambda0 = 1
h = np.zeros((4*Nx*Ny, 4*Nx*Ny))
# 元胞内部跃迁
for x in range(Nx):
for y in range(Ny):
h[x*Ny*4+y*4+0, x*Ny*4+y*4+0] = delta
h[x*Ny*4+y*4+1, x*Ny*4+y*4+1] = delta
h[x*Ny*4+y*4+2, x*Ny*4+y*4+2] = -delta
h[x*Ny*4+y*4+3, x*Ny*4+y*4+3] = -delta
h[x*Ny*4+y*4+0, x*Ny*4+y*4+2] = gamma
h[x*Ny*4+y*4+0, x*Ny*4+y*4+3] = gamma
h[x*Ny*4+y*4+1, x*Ny*4+y*4+2] = -gamma
h[x*Ny*4+y*4+1, x*Ny*4+y*4+3] = gamma
h[x*Ny*4+y*4+2, x*Ny*4+y*4+0] = gamma
h[x*Ny*4+y*4+2, x*Ny*4+y*4+1] = -gamma
h[x*Ny*4+y*4+3, x*Ny*4+y*4+0] = gamma
h[x*Ny*4+y*4+3, x*Ny*4+y*4+1] = gamma
# y方向上的元胞间跃迁
for x in range(Nx):
for y in range(Ny-1):
h[x*Ny*4+y*4+0, x*Ny*4+(y+1)*4+3] = lambda0
h[x*Ny*4+(y+1)*4+1, x*Ny*4+y*4+2] = -lambda0
h[x*Ny*4+y*4+2, x*Ny*4+(y+1)*4+1] = -lambda0
h[x*Ny*4+(y+1)*4+3, x*Ny*4+y*4+0] = lambda0
# x方向上的元胞间跃迁
for x in range(Nx-1):
for y in range(Ny):
h[x*Ny*4+y*4+0, (x+1)*Ny*4+y*4+2] = lambda0
h[(x+1)*Ny*4+y*4+1, x*Ny*4+y*4+3] = lambda0
h[(x+1)*Ny*4+y*4+2, x*Ny*4+y*4+0] = lambda0
h[x*Ny*4+y*4+3, (x+1)*Ny*4+y*4+1] = lambda0
return h
def main():
Nx = 10
Ny = 10
fermi_energy = 0
h = hamiltonian(Nx, Ny)
green = np.linalg.inv((fermi_energy+1e-6j)*np.eye(h.shape[0])-h)
x_array = []
y_array = []
DOS = []
for x in range(Nx):
for y in range(Ny):
x_array.append(x*2+2)
y_array.append(y*2+2)
DOS.append(-np.imag(green[x*Ny*4+y*4+0, x*Ny*4+y*4+0])/pi)
x_array.append(x*2+1)
y_array.append(y*2+1)
DOS.append(-np.imag(green[x*Ny*4+y*4+1, x*Ny*4+y*4+1])/pi)
x_array.append(x*2+1)
y_array.append(y*2+2)
DOS.append(-np.imag(green[x*Ny*4+y*4+2, x*Ny*4+y*4+2])/pi)
x_array.append(x*2+2)
y_array.append(y*2+1)
DOS.append(-np.imag(green[x*Ny*4+y*4+3, x*Ny*4+y*4+3])/pi)
DOS = DOS/np.sum(DOS)
Plot_2D_Scatter(x_array, y_array, DOS, xlabel='x', ylabel='y', title='BBH Model', filename='BBH Model')
def Plot_2D_Scatter(x, y, value, xlabel='x', ylabel='y', title='title', filename='a'):
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
plt.subplots_adjust(bottom=0.2, right=0.8, left=0.2)
for i in range(np.array(x).shape[0]):
ax.scatter(x[i], y[i], marker='o', s=1000*value[i], c=[(1,0,0)])
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
ax.tick_params(labelsize=15) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
# plt.savefig(filename+'.jpg', dpi=300)
plt.show()
plt.close('all')
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8557
"""
import numpy as np
from math import *
def hamiltonian(Nx, Ny):
delta = 1e-3
gamma = 1e-3
lambda0 = 1
h = np.zeros((4*Nx*Ny, 4*Nx*Ny))
# 元胞内部跃迁
for x in range(Nx):
for y in range(Ny):
h[x*Ny*4+y*4+0, x*Ny*4+y*4+0] = delta
h[x*Ny*4+y*4+1, x*Ny*4+y*4+1] = delta
h[x*Ny*4+y*4+2, x*Ny*4+y*4+2] = -delta
h[x*Ny*4+y*4+3, x*Ny*4+y*4+3] = -delta
h[x*Ny*4+y*4+0, x*Ny*4+y*4+2] = gamma
h[x*Ny*4+y*4+0, x*Ny*4+y*4+3] = gamma
h[x*Ny*4+y*4+1, x*Ny*4+y*4+2] = -gamma
h[x*Ny*4+y*4+1, x*Ny*4+y*4+3] = gamma
h[x*Ny*4+y*4+2, x*Ny*4+y*4+0] = gamma
h[x*Ny*4+y*4+2, x*Ny*4+y*4+1] = -gamma
h[x*Ny*4+y*4+3, x*Ny*4+y*4+0] = gamma
h[x*Ny*4+y*4+3, x*Ny*4+y*4+1] = gamma
# y方向上的元胞间跃迁
for x in range(Nx):
for y in range(Ny-1):
h[x*Ny*4+y*4+0, x*Ny*4+(y+1)*4+3] = lambda0
h[x*Ny*4+(y+1)*4+1, x*Ny*4+y*4+2] = -lambda0
h[x*Ny*4+y*4+2, x*Ny*4+(y+1)*4+1] = -lambda0
h[x*Ny*4+(y+1)*4+3, x*Ny*4+y*4+0] = lambda0
# x方向上的元胞间跃迁
for x in range(Nx-1):
for y in range(Ny):
h[x*Ny*4+y*4+0, (x+1)*Ny*4+y*4+2] = lambda0
h[(x+1)*Ny*4+y*4+1, x*Ny*4+y*4+3] = lambda0
h[(x+1)*Ny*4+y*4+2, x*Ny*4+y*4+0] = lambda0
h[x*Ny*4+y*4+3, (x+1)*Ny*4+y*4+1] = lambda0
return h
def main():
Nx = 10
Ny = 10
fermi_energy = 0
h = hamiltonian(Nx, Ny)
green = np.linalg.inv((fermi_energy+1e-6j)*np.eye(h.shape[0])-h)
x_array = []
y_array = []
DOS = []
for x in range(Nx):
for y in range(Ny):
x_array.append(x*2+2)
y_array.append(y*2+2)
DOS.append(-np.imag(green[x*Ny*4+y*4+0, x*Ny*4+y*4+0])/pi)
x_array.append(x*2+1)
y_array.append(y*2+1)
DOS.append(-np.imag(green[x*Ny*4+y*4+1, x*Ny*4+y*4+1])/pi)
x_array.append(x*2+1)
y_array.append(y*2+2)
DOS.append(-np.imag(green[x*Ny*4+y*4+2, x*Ny*4+y*4+2])/pi)
x_array.append(x*2+2)
y_array.append(y*2+1)
DOS.append(-np.imag(green[x*Ny*4+y*4+3, x*Ny*4+y*4+3])/pi)
DOS = DOS/np.sum(DOS)
Plot_2D_Scatter(x_array, y_array, DOS, xlabel='x', ylabel='y', title='BBH Model', filename='BBH Model')
def Plot_2D_Scatter(x, y, value, xlabel='x', ylabel='y', title='title', filename='a'):
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
plt.subplots_adjust(bottom=0.2, right=0.8, left=0.2)
for i in range(np.array(x).shape[0]):
ax.scatter(x[i], y[i], marker='o', s=1000*value[i], c=[(1,0,0)])
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
ax.tick_params(labelsize=15) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
# plt.savefig(filename+'.jpg', dpi=300)
plt.show()
plt.close('all')
if __name__ == '__main__':
main()

View File

@@ -1,100 +1,100 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8557
"""
import numpy as np
from math import *
def hamiltonian(Nx, Ny):
delta = 1e-3
gamma = 1e-3
lambda0 = 1
h = np.zeros((4*Nx*Ny, 4*Nx*Ny))
# 元胞内部跃迁
for x in range(Nx):
for y in range(Ny):
h[x*Ny*4+y*4+0, x*Ny*4+y*4+0] = delta
h[x*Ny*4+y*4+1, x*Ny*4+y*4+1] = delta
h[x*Ny*4+y*4+2, x*Ny*4+y*4+2] = -delta
h[x*Ny*4+y*4+3, x*Ny*4+y*4+3] = -delta
h[x*Ny*4+y*4+0, x*Ny*4+y*4+2] = gamma
h[x*Ny*4+y*4+0, x*Ny*4+y*4+3] = gamma
h[x*Ny*4+y*4+1, x*Ny*4+y*4+2] = -gamma
h[x*Ny*4+y*4+1, x*Ny*4+y*4+3] = gamma
h[x*Ny*4+y*4+2, x*Ny*4+y*4+0] = gamma
h[x*Ny*4+y*4+2, x*Ny*4+y*4+1] = -gamma
h[x*Ny*4+y*4+3, x*Ny*4+y*4+0] = gamma
h[x*Ny*4+y*4+3, x*Ny*4+y*4+1] = gamma
# y方向上的元胞间跃迁
for x in range(Nx):
for y in range(Ny-1):
h[x*Ny*4+y*4+0, x*Ny*4+(y+1)*4+3] = lambda0
h[x*Ny*4+(y+1)*4+1, x*Ny*4+y*4+2] = -lambda0
h[x*Ny*4+y*4+2, x*Ny*4+(y+1)*4+1] = -lambda0
h[x*Ny*4+(y+1)*4+3, x*Ny*4+y*4+0] = lambda0
# x方向上的元胞间跃迁
for x in range(Nx-1):
for y in range(Ny):
h[x*Ny*4+y*4+0, (x+1)*Ny*4+y*4+2] = lambda0
h[(x+1)*Ny*4+y*4+1, x*Ny*4+y*4+3] = lambda0
h[(x+1)*Ny*4+y*4+2, x*Ny*4+y*4+0] = lambda0
h[x*Ny*4+y*4+3, (x+1)*Ny*4+y*4+1] = lambda0
return h
def main():
Nx = 10
Ny = 10
fermi_energy = 0
h = hamiltonian(Nx, Ny)
green = np.linalg.inv((fermi_energy+1e-6j)*np.eye(h.shape[0])-h)
DOS = np.zeros((Ny*2, Nx*2))
for x in range(Nx):
for y in range(Ny):
DOS[y*2+1, x*2+1] = -np.imag(green[x*Ny*4+y*4+0, x*Ny*4+y*4+0])/pi
DOS[y*2+0, x*2+0] = -np.imag(green[x*Ny*4+y*4+1, x*Ny*4+y*4+1])/pi
DOS[y*2+1, x*2+0] = -np.imag(green[x*Ny*4+y*4+2, x*Ny*4+y*4+2])/pi
DOS[y*2+0, x*2+1] = -np.imag(green[x*Ny*4+y*4+3, x*Ny*4+y*4+3])/pi
DOS = DOS/np.sum(DOS)
Plot_3D_Surface(np.arange(1, 2*Nx+0.001), np.arange(1, 2*Ny+0.001), DOS, xlabel='x', ylabel='y', zlabel='DOS', title='BBH Model', filename='BBH Model')
def Plot_3D_Surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='title', filename='a'):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
plt.subplots_adjust(bottom=0.1, right=0.65)
x, y = np.meshgrid(x, y)
if len(matrix.shape) == 2:
surf = ax.plot_surface(x, y, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
elif len(matrix.shape) == 3:
for i0 in range(matrix.shape[2]):
surf = ax.plot_surface(x, y, matrix[:,:,i0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
ax.set_zlabel(zlabel, fontsize=20, fontfamily='Times New Roman')
# ax.set_zlim(-1, 1) # 设置z轴的范围
ax.zaxis.set_major_locator(LinearLocator(2)) # 设置z轴主刻度的个数
ax.zaxis.set_major_formatter('{x:.2f}') # 设置z轴主刻度的格式
ax.tick_params(labelsize=15) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
cax = plt.axes([0.80, 0.15, 0.05, 0.75]) # color bar的位置 [左,下,宽度, 高度]
cbar = fig.colorbar(surf, cax=cax) # color bar
cbar.ax.tick_params(labelsize=15) # 设置color bar刻度的字体大小
for l in cbar.ax.yaxis.get_ticklabels():
l.set_family('Times New Roman')
# plt.savefig(filename+'.jpg', dpi=300)
plt.show()
plt.close('all')
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8557
"""
import numpy as np
from math import *
def hamiltonian(Nx, Ny):
delta = 1e-3
gamma = 1e-3
lambda0 = 1
h = np.zeros((4*Nx*Ny, 4*Nx*Ny))
# 元胞内部跃迁
for x in range(Nx):
for y in range(Ny):
h[x*Ny*4+y*4+0, x*Ny*4+y*4+0] = delta
h[x*Ny*4+y*4+1, x*Ny*4+y*4+1] = delta
h[x*Ny*4+y*4+2, x*Ny*4+y*4+2] = -delta
h[x*Ny*4+y*4+3, x*Ny*4+y*4+3] = -delta
h[x*Ny*4+y*4+0, x*Ny*4+y*4+2] = gamma
h[x*Ny*4+y*4+0, x*Ny*4+y*4+3] = gamma
h[x*Ny*4+y*4+1, x*Ny*4+y*4+2] = -gamma
h[x*Ny*4+y*4+1, x*Ny*4+y*4+3] = gamma
h[x*Ny*4+y*4+2, x*Ny*4+y*4+0] = gamma
h[x*Ny*4+y*4+2, x*Ny*4+y*4+1] = -gamma
h[x*Ny*4+y*4+3, x*Ny*4+y*4+0] = gamma
h[x*Ny*4+y*4+3, x*Ny*4+y*4+1] = gamma
# y方向上的元胞间跃迁
for x in range(Nx):
for y in range(Ny-1):
h[x*Ny*4+y*4+0, x*Ny*4+(y+1)*4+3] = lambda0
h[x*Ny*4+(y+1)*4+1, x*Ny*4+y*4+2] = -lambda0
h[x*Ny*4+y*4+2, x*Ny*4+(y+1)*4+1] = -lambda0
h[x*Ny*4+(y+1)*4+3, x*Ny*4+y*4+0] = lambda0
# x方向上的元胞间跃迁
for x in range(Nx-1):
for y in range(Ny):
h[x*Ny*4+y*4+0, (x+1)*Ny*4+y*4+2] = lambda0
h[(x+1)*Ny*4+y*4+1, x*Ny*4+y*4+3] = lambda0
h[(x+1)*Ny*4+y*4+2, x*Ny*4+y*4+0] = lambda0
h[x*Ny*4+y*4+3, (x+1)*Ny*4+y*4+1] = lambda0
return h
def main():
Nx = 10
Ny = 10
fermi_energy = 0
h = hamiltonian(Nx, Ny)
green = np.linalg.inv((fermi_energy+1e-6j)*np.eye(h.shape[0])-h)
DOS = np.zeros((Ny*2, Nx*2))
for x in range(Nx):
for y in range(Ny):
DOS[y*2+1, x*2+1] = -np.imag(green[x*Ny*4+y*4+0, x*Ny*4+y*4+0])/pi
DOS[y*2+0, x*2+0] = -np.imag(green[x*Ny*4+y*4+1, x*Ny*4+y*4+1])/pi
DOS[y*2+1, x*2+0] = -np.imag(green[x*Ny*4+y*4+2, x*Ny*4+y*4+2])/pi
DOS[y*2+0, x*2+1] = -np.imag(green[x*Ny*4+y*4+3, x*Ny*4+y*4+3])/pi
DOS = DOS/np.sum(DOS)
Plot_3D_Surface(np.arange(1, 2*Nx+0.001), np.arange(1, 2*Ny+0.001), DOS, xlabel='x', ylabel='y', zlabel='DOS', title='BBH Model', filename='BBH Model')
def Plot_3D_Surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='title', filename='a'):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
plt.subplots_adjust(bottom=0.1, right=0.65)
x, y = np.meshgrid(x, y)
if len(matrix.shape) == 2:
surf = ax.plot_surface(x, y, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
elif len(matrix.shape) == 3:
for i0 in range(matrix.shape[2]):
surf = ax.plot_surface(x, y, matrix[:,:,i0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
ax.set_zlabel(zlabel, fontsize=20, fontfamily='Times New Roman')
# ax.set_zlim(-1, 1) # 设置z轴的范围
ax.zaxis.set_major_locator(LinearLocator(2)) # 设置z轴主刻度的个数
ax.zaxis.set_major_formatter('{x:.2f}') # 设置z轴主刻度的格式
ax.tick_params(labelsize=15) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
cax = plt.axes([0.80, 0.15, 0.05, 0.75]) # color bar的位置 [左,下,宽度, 高度]
cbar = fig.colorbar(surf, cax=cax) # color bar
cbar.ax.tick_params(labelsize=15) # 设置color bar刻度的字体大小
for l in cbar.ax.yaxis.get_ticklabels():
l.set_family('Times New Roman')
# plt.savefig(filename+'.jpg', dpi=300)
plt.show()
plt.close('all')
if __name__ == '__main__':
main()

View File

@@ -1,81 +1,81 @@
(* Content-type: application/vnd.wolfram.mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 12.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 158, 7]
NotebookDataLength[ 2039, 71]
NotebookOptionsPosition[ 1730, 57]
NotebookOutlinePosition[ 2086, 73]
CellTagsIndexPosition[ 2043, 70]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[{
RowBox[{"Clear", "[", "\"\<`*\>\"", "]"}], "\n",
RowBox[{
RowBox[{"H", "=",
RowBox[{
RowBox[{"(",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"a0", ",", "0"}], "}"}], ",",
RowBox[{"{",
RowBox[{"0", ",", "a0"}], "}"}]}], "}"}], ")"}], "+",
RowBox[{"(",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"a3", ",",
RowBox[{"a1", "-",
RowBox[{"I", "*", "a2"}]}]}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{"a1", "+",
RowBox[{"I", "*", "a2"}]}], ",",
RowBox[{"-", "a3"}]}], "}"}]}], "}"}], ")"}]}]}], ";"}], "\n",
RowBox[{"MatrixForm", "[", "H", "]"}], "\n",
RowBox[{"eigenvalue", "=",
RowBox[{"MatrixForm", "[",
RowBox[{"Simplify", "[",
RowBox[{"Eigenvalues", "[", "H", "]"}], "]"}], "]"}]}], "\n",
RowBox[{"eigenvector", "=",
RowBox[{"MatrixForm", "[",
RowBox[{"Simplify", "[",
RowBox[{"Eigenvectors", "[", "H", "]"}], "]"}], "]"}]}]}], "Input",
CellChangeTimes->{{3.830338636045154*^9,
3.830338636046383*^9}},ExpressionUUID->"6b5e0acb-1938-4b1e-bd73-\
d3f6bb8905fc"]
},
WindowSize->{759, 670},
WindowMargins->{{Automatic, 572}, {64, Automatic}},
FrontEndVersion->"12.0 for Microsoft Windows (64-bit) (2019\:5e744\:67088\
\:65e5)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)
(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[558, 20, 1168, 35, 193, "Input",ExpressionUUID->"6b5e0acb-1938-4b1e-bd73-d3f6bb8905fc"]
}
]
*)
(* End of internal cache information *)
(* Content-type: application/vnd.wolfram.mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 12.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 158, 7]
NotebookDataLength[ 2039, 71]
NotebookOptionsPosition[ 1730, 57]
NotebookOutlinePosition[ 2086, 73]
CellTagsIndexPosition[ 2043, 70]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[{
RowBox[{"Clear", "[", "\"\<`*\>\"", "]"}], "\n",
RowBox[{
RowBox[{"H", "=",
RowBox[{
RowBox[{"(",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"a0", ",", "0"}], "}"}], ",",
RowBox[{"{",
RowBox[{"0", ",", "a0"}], "}"}]}], "}"}], ")"}], "+",
RowBox[{"(",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"a3", ",",
RowBox[{"a1", "-",
RowBox[{"I", "*", "a2"}]}]}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{"a1", "+",
RowBox[{"I", "*", "a2"}]}], ",",
RowBox[{"-", "a3"}]}], "}"}]}], "}"}], ")"}]}]}], ";"}], "\n",
RowBox[{"MatrixForm", "[", "H", "]"}], "\n",
RowBox[{"eigenvalue", "=",
RowBox[{"MatrixForm", "[",
RowBox[{"Simplify", "[",
RowBox[{"Eigenvalues", "[", "H", "]"}], "]"}], "]"}]}], "\n",
RowBox[{"eigenvector", "=",
RowBox[{"MatrixForm", "[",
RowBox[{"Simplify", "[",
RowBox[{"Eigenvectors", "[", "H", "]"}], "]"}], "]"}]}]}], "Input",
CellChangeTimes->{{3.830338636045154*^9,
3.830338636046383*^9}},ExpressionUUID->"6b5e0acb-1938-4b1e-bd73-\
d3f6bb8905fc"]
},
WindowSize->{759, 670},
WindowMargins->{{Automatic, 572}, {64, Automatic}},
FrontEndVersion->"12.0 for Microsoft Windows (64-bit) (2019\:5e744\:67088\
\:65e5)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)
(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[558, 20, 1168, 35, 193, "Input",ExpressionUUID->"6b5e0acb-1938-4b1e-bd73-d3f6bb8905fc"]
}
]
*)
(* End of internal cache information *)

View File

@@ -1,89 +1,89 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10385
"""
import numpy as np
from math import *
def main():
k1 = np.linspace(-pi, pi, 100)
k2 = np.linspace(-pi, pi, 100)
eigenvalue_array = Calculate_Eigenvalue_with_Two_Parameters(k1, k2, hamiltonian)
Plot_3D_Surface(k1, k2, eigenvalue_array, xlabel='kx', ylabel='ky', zlabel='E', title='', filename='a')
def hamiltonian(kx,ky,kz=0):
w0x = 2
w0y = 0
w0z = 0
vx = 1
vy = 1
vz = 1
H = (w0x*kx+w0y*ky+w0z*kz)*sigma_0() + vx*kx*sigma_x()+vy*ky*sigma_y()+vz*kz*sigma_z()
return H
def sigma_0():
return np.eye(2)
def sigma_x():
return np.array([[0, 1],[1, 0]])
def sigma_y():
return np.array([[0, -1j],[1j, 0]])
def sigma_z():
return np.array([[1, 0],[0, -1]])
def Calculate_Eigenvalue_with_Two_Parameters(x, y, matrix):
dim = np.array(matrix(0, 0)).shape[0]
dim_x = np.array(x).shape[0]
dim_y = np.array(y).shape[0]
eigenvalue_array = np.zeros((dim_y, dim_x, dim))
i0 = 0
for y0 in y:
j0 = 0
for x0 in x:
matrix0 = matrix(x0, y0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_array[i0, j0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
return eigenvalue_array
def Plot_3D_Surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a'):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
plt.subplots_adjust(bottom=0.1, right=0.8)
x, y = np.meshgrid(x, y)
if len(matrix.shape) == 2:
surf = ax.plot_surface(x, y, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
elif len(matrix.shape) == 3:
for i0 in range(matrix.shape[2]):
surf = ax.plot_surface(x, y, matrix[:,:,i0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
ax.set_zlabel(zlabel, fontsize=20, fontfamily='Times New Roman')
# ax.set_zlim(-1, 1) # 设置z轴的范围
ax.zaxis.set_major_locator(LinearLocator(5)) # 设置z轴主刻度的个数
ax.zaxis.set_major_formatter('{x:.2f}') # 设置z轴主刻度的格式
ax.tick_params(labelsize=15) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
# plt.savefig(filename+'.jpg', dpi=300)
plt.show()
plt.close('all')
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10385
"""
import numpy as np
from math import *
def main():
k1 = np.linspace(-pi, pi, 100)
k2 = np.linspace(-pi, pi, 100)
eigenvalue_array = Calculate_Eigenvalue_with_Two_Parameters(k1, k2, hamiltonian)
Plot_3D_Surface(k1, k2, eigenvalue_array, xlabel='kx', ylabel='ky', zlabel='E', title='', filename='a')
def hamiltonian(kx,ky,kz=0):
w0x = 2
w0y = 0
w0z = 0
vx = 1
vy = 1
vz = 1
H = (w0x*kx+w0y*ky+w0z*kz)*sigma_0() + vx*kx*sigma_x()+vy*ky*sigma_y()+vz*kz*sigma_z()
return H
def sigma_0():
return np.eye(2)
def sigma_x():
return np.array([[0, 1],[1, 0]])
def sigma_y():
return np.array([[0, -1j],[1j, 0]])
def sigma_z():
return np.array([[1, 0],[0, -1]])
def Calculate_Eigenvalue_with_Two_Parameters(x, y, matrix):
dim = np.array(matrix(0, 0)).shape[0]
dim_x = np.array(x).shape[0]
dim_y = np.array(y).shape[0]
eigenvalue_array = np.zeros((dim_y, dim_x, dim))
i0 = 0
for y0 in y:
j0 = 0
for x0 in x:
matrix0 = matrix(x0, y0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_array[i0, j0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
return eigenvalue_array
def Plot_3D_Surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a'):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
plt.subplots_adjust(bottom=0.1, right=0.8)
x, y = np.meshgrid(x, y)
if len(matrix.shape) == 2:
surf = ax.plot_surface(x, y, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
elif len(matrix.shape) == 3:
for i0 in range(matrix.shape[2]):
surf = ax.plot_surface(x, y, matrix[:,:,i0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
ax.set_zlabel(zlabel, fontsize=20, fontfamily='Times New Roman')
# ax.set_zlim(-1, 1) # 设置z轴的范围
ax.zaxis.set_major_locator(LinearLocator(5)) # 设置z轴主刻度的个数
ax.zaxis.set_major_formatter('{x:.2f}') # 设置z轴主刻度的格式
ax.tick_params(labelsize=15) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
# plt.savefig(filename+'.jpg', dpi=300)
plt.show()
plt.close('all')
if __name__ == '__main__':
main()

View File

@@ -1,40 +1,40 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
"""
import numpy as np
def main():
x_array = np.arange(-5, 5.1)
y_array = np.arange(-5, 5.1)
coordinates = []
for x in x_array:
for y in y_array:
coordinates.append([0+x*3, 0+y*np.sqrt(3)])
coordinates.append([1+x*3, 0+y*np.sqrt(3)])
coordinates.append([-1/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
coordinates.append([-3/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
plot_dots(coordinates)
def plot_dots(coordinates):
import matplotlib.pyplot as plt
x_range = max(np.array(coordinates)[:, 0])-min(np.array(coordinates)[:, 0])
y_range = max(np.array(coordinates)[:, 1])-min(np.array(coordinates)[:, 1])
fig, ax = plt.subplots(figsize=(9*x_range/y_range,9))
plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
plt.axis('off')
for i1 in range(len(coordinates)):
for i2 in range(len(coordinates)):
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=1)
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=8)
# plt.savefig('graphene.eps')
plt.show()
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
"""
import numpy as np
def main():
x_array = np.arange(-5, 5.1)
y_array = np.arange(-5, 5.1)
coordinates = []
for x in x_array:
for y in y_array:
coordinates.append([0+x*3, 0+y*np.sqrt(3)])
coordinates.append([1+x*3, 0+y*np.sqrt(3)])
coordinates.append([-1/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
coordinates.append([-3/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
plot_dots(coordinates)
def plot_dots(coordinates):
import matplotlib.pyplot as plt
x_range = max(np.array(coordinates)[:, 0])-min(np.array(coordinates)[:, 0])
y_range = max(np.array(coordinates)[:, 1])-min(np.array(coordinates)[:, 1])
fig, ax = plt.subplots(figsize=(9*x_range/y_range,9))
plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
plt.axis('off')
for i1 in range(len(coordinates)):
for i2 in range(len(coordinates)):
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=1)
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=8)
# plt.savefig('graphene.eps')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,35 +1,35 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
"""
import numpy as np
def main():
x_array = np.arange(-5, 5.1)
y_array = np.arange(-5, 5.1)
coordinates = []
for x in x_array:
for y in y_array:
coordinates.append([x, y])
plot_dots(coordinates)
def plot_dots(coordinates):
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(9,9))
plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
plt.axis('off')
for i1 in range(len(coordinates)):
for i2 in range(len(coordinates)):
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=1)
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=10)
# plt.savefig('square.eps')
plt.show()
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
"""
import numpy as np
def main():
x_array = np.arange(-5, 5.1)
y_array = np.arange(-5, 5.1)
coordinates = []
for x in x_array:
for y in y_array:
coordinates.append([x, y])
plot_dots(coordinates)
def plot_dots(coordinates):
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(9,9))
plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
plt.axis('off')
for i1 in range(len(coordinates)):
for i2 in range(len(coordinates)):
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=1)
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=10)
# plt.savefig('square.eps')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,72 +1,72 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
"""
import numpy as np
import copy
import matplotlib.pyplot as plt
from math import *
def main():
x_array = np.arange(-20, 20.1)
y_array = np.arange(-20, 20.1)
coordinates = []
for x in x_array:
for y in y_array:
coordinates.append([0+x*3, 0+y*np.sqrt(3)])
coordinates.append([1+x*3, 0+y*np.sqrt(3)])
coordinates.append([-1/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
coordinates.append([-3/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
x_range1 = max(np.array(coordinates)[:, 0])-min(np.array(coordinates)[:, 0])
y_range1 = max(np.array(coordinates)[:, 1])-min(np.array(coordinates)[:, 1])
theta = -1.1/180*pi
rotation_matrix = np.zeros((2, 2))
rotation_matrix[0, 0] = np.cos(theta)
rotation_matrix[1, 1] = np.cos(theta)
rotation_matrix[0, 1] = -np.sin(theta)
rotation_matrix[1, 0] = np.sin(theta)
coordinates2 = copy.deepcopy(coordinates)
for i in range(len(coordinates)):
coordinates2[i] = np.dot(rotation_matrix, coordinates[i])
x_range2 = max(np.array(coordinates2)[:, 0])-min(np.array(coordinates2)[:, 0])
y_range2 = max(np.array(coordinates2)[:, 1])-min(np.array(coordinates2)[:, 1])
x_range = max([x_range1, x_range2])
y_range = max([y_range1, y_range2])
fig, ax = plt.subplots(figsize=(9*x_range/y_range,9))
plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
plt.axis('off')
plot_dots_1(ax, coordinates)
plot_dots_2(ax, coordinates2)
plot_dots_0(ax, [[0, 0]])
plt.savefig('twist_graphene.eps')
plt.show()
def plot_dots_0(ax, coordinates):
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'ko', markersize=0.5)
def plot_dots_1(ax, coordinates):
for i1 in range(len(coordinates)):
for i2 in range(len(coordinates)):
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=0.2)
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=0.5)
def plot_dots_2(ax, coordinates):
for i1 in range(len(coordinates)):
for i2 in range(len(coordinates)):
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '--k', linewidth=0.2)
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'bo', markersize=0.5)
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
"""
import numpy as np
import copy
import matplotlib.pyplot as plt
from math import *
def main():
x_array = np.arange(-20, 20.1)
y_array = np.arange(-20, 20.1)
coordinates = []
for x in x_array:
for y in y_array:
coordinates.append([0+x*3, 0+y*np.sqrt(3)])
coordinates.append([1+x*3, 0+y*np.sqrt(3)])
coordinates.append([-1/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
coordinates.append([-3/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
x_range1 = max(np.array(coordinates)[:, 0])-min(np.array(coordinates)[:, 0])
y_range1 = max(np.array(coordinates)[:, 1])-min(np.array(coordinates)[:, 1])
theta = -1.1/180*pi
rotation_matrix = np.zeros((2, 2))
rotation_matrix[0, 0] = np.cos(theta)
rotation_matrix[1, 1] = np.cos(theta)
rotation_matrix[0, 1] = -np.sin(theta)
rotation_matrix[1, 0] = np.sin(theta)
coordinates2 = copy.deepcopy(coordinates)
for i in range(len(coordinates)):
coordinates2[i] = np.dot(rotation_matrix, coordinates[i])
x_range2 = max(np.array(coordinates2)[:, 0])-min(np.array(coordinates2)[:, 0])
y_range2 = max(np.array(coordinates2)[:, 1])-min(np.array(coordinates2)[:, 1])
x_range = max([x_range1, x_range2])
y_range = max([y_range1, y_range2])
fig, ax = plt.subplots(figsize=(9*x_range/y_range,9))
plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
plt.axis('off')
plot_dots_1(ax, coordinates)
plot_dots_2(ax, coordinates2)
plot_dots_0(ax, [[0, 0]])
plt.savefig('twist_graphene.eps')
plt.show()
def plot_dots_0(ax, coordinates):
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'ko', markersize=0.5)
def plot_dots_1(ax, coordinates):
for i1 in range(len(coordinates)):
for i2 in range(len(coordinates)):
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=0.2)
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=0.5)
def plot_dots_2(ax, coordinates):
for i1 in range(len(coordinates)):
for i2 in range(len(coordinates)):
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '--k', linewidth=0.2)
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'bo', markersize=0.5)
if __name__ == '__main__':
main()

View File

@@ -1,53 +1,53 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/12731
"""
import numpy as np
import guan
a_00 = np.random.uniform(-1, 1)
a_0x = np.random.uniform(-1, 1)
a_0y = np.random.uniform(-1, 1)
a_0z = np.random.uniform(-1, 1)
a_x0 = np.random.uniform(-1, 1)
a_xx = np.random.uniform(-1, 1)
a_xy = np.random.uniform(-1, 1)
a_xz = np.random.uniform(-1, 1)
a_y0 = np.random.uniform(-1, 1)
a_yx = np.random.uniform(-1, 1)
a_yy = np.random.uniform(-1, 1)
a_yz = np.random.uniform(-1, 1)
a_z0 = np.random.uniform(-1, 1)
a_zx = np.random.uniform(-1, 1)
a_zy = np.random.uniform(-1, 1)
a_zz = np.random.uniform(-1, 1)
hamiltonian_1 = \
a_00*guan.sigma_00()+a_0x*guan.sigma_0x()+a_0y*guan.sigma_0y()+a_0z*guan.sigma_0z()+ \
a_x0*guan.sigma_x0()+a_xx*guan.sigma_xx()+a_xy*guan.sigma_xy()+a_xz*guan.sigma_xz()+ \
a_y0*guan.sigma_y0()+a_yx*guan.sigma_yx()+a_yy*guan.sigma_yy()+a_yz*guan.sigma_yz()+ \
a_z0*guan.sigma_z0()+a_zx*guan.sigma_zx()+a_zy*guan.sigma_zy()+a_zz*guan.sigma_zz()
eigenvalue_1 = guan.calculate_eigenvalue(hamiltonian_1)
hamiltonian_2 = \
a_00*guan.sigma_00()+a_0x*guan.sigma_x0()+a_0y*guan.sigma_y0()+a_0z*guan.sigma_z0()+ \
a_x0*guan.sigma_0x()+a_xx*guan.sigma_xx()+a_xy*guan.sigma_yx()+a_xz*guan.sigma_zx()+ \
a_y0*guan.sigma_0y()+a_yx*guan.sigma_xy()+a_yy*guan.sigma_yy()+a_yz*guan.sigma_zy()+ \
a_z0*guan.sigma_0z()+a_zx*guan.sigma_xz()+a_zy*guan.sigma_yz()+a_zz*guan.sigma_zz()
eigenvalue_2 = guan.calculate_eigenvalue(hamiltonian_2)
print()
print('Eigenvalue:')
print(eigenvalue_1)
print(eigenvalue_2)
print()
print('Difference of matrices:')
print(hamiltonian_1-hamiltonian_2)
print()
# print(hamiltonian_1)
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/12731
"""
import numpy as np
import guan
a_00 = np.random.uniform(-1, 1)
a_0x = np.random.uniform(-1, 1)
a_0y = np.random.uniform(-1, 1)
a_0z = np.random.uniform(-1, 1)
a_x0 = np.random.uniform(-1, 1)
a_xx = np.random.uniform(-1, 1)
a_xy = np.random.uniform(-1, 1)
a_xz = np.random.uniform(-1, 1)
a_y0 = np.random.uniform(-1, 1)
a_yx = np.random.uniform(-1, 1)
a_yy = np.random.uniform(-1, 1)
a_yz = np.random.uniform(-1, 1)
a_z0 = np.random.uniform(-1, 1)
a_zx = np.random.uniform(-1, 1)
a_zy = np.random.uniform(-1, 1)
a_zz = np.random.uniform(-1, 1)
hamiltonian_1 = \
a_00*guan.sigma_00()+a_0x*guan.sigma_0x()+a_0y*guan.sigma_0y()+a_0z*guan.sigma_0z()+ \
a_x0*guan.sigma_x0()+a_xx*guan.sigma_xx()+a_xy*guan.sigma_xy()+a_xz*guan.sigma_xz()+ \
a_y0*guan.sigma_y0()+a_yx*guan.sigma_yx()+a_yy*guan.sigma_yy()+a_yz*guan.sigma_yz()+ \
a_z0*guan.sigma_z0()+a_zx*guan.sigma_zx()+a_zy*guan.sigma_zy()+a_zz*guan.sigma_zz()
eigenvalue_1 = guan.calculate_eigenvalue(hamiltonian_1)
hamiltonian_2 = \
a_00*guan.sigma_00()+a_0x*guan.sigma_x0()+a_0y*guan.sigma_y0()+a_0z*guan.sigma_z0()+ \
a_x0*guan.sigma_0x()+a_xx*guan.sigma_xx()+a_xy*guan.sigma_yx()+a_xz*guan.sigma_zx()+ \
a_y0*guan.sigma_0y()+a_yx*guan.sigma_xy()+a_yy*guan.sigma_yy()+a_yz*guan.sigma_zy()+ \
a_z0*guan.sigma_0z()+a_zx*guan.sigma_xz()+a_zy*guan.sigma_yz()+a_zz*guan.sigma_zz()
eigenvalue_2 = guan.calculate_eigenvalue(hamiltonian_2)
print()
print('Eigenvalue:')
print(eigenvalue_1)
print(eigenvalue_2)
print()
print('Difference of matrices:')
print(hamiltonian_1-hamiltonian_2)
print()
# print(hamiltonian_1)
# print(hamiltonian_2)

View File

@@ -1,49 +1,49 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/12731
"""
import numpy as np
import guan
a_00 = np.random.uniform(-1, 1)
a_0x = np.random.uniform(-1, 1)
a_0y = np.random.uniform(-1, 1)
a_0z = np.random.uniform(-1, 1)
a_x0 = np.random.uniform(-1, 1)
a_xx = np.random.uniform(-1, 1)
a_xy = np.random.uniform(-1, 1)
a_xz = np.random.uniform(-1, 1)
a_y0 = np.random.uniform(-1, 1)
a_yx = np.random.uniform(-1, 1)
a_yy = np.random.uniform(-1, 1)
a_yz = np.random.uniform(-1, 1)
a_z0 = np.random.uniform(-1, 1)
a_zx = np.random.uniform(-1, 1)
a_zy = np.random.uniform(-1, 1)
a_zz = np.random.uniform(-1, 1)
hamiltonian_1 = \
a_00*guan.sigma_00()+a_0x*guan.sigma_0x()+a_0y*guan.sigma_0y()+a_0z*guan.sigma_0z()+ \
a_x0*guan.sigma_x0()+a_xx*guan.sigma_xx()+a_xy*guan.sigma_xy()+a_xz*guan.sigma_xz()+ \
a_y0*guan.sigma_y0()+a_yx*guan.sigma_yx()+a_yy*guan.sigma_yy()+a_yz*guan.sigma_yz()+ \
a_z0*guan.sigma_z0()+a_zx*guan.sigma_zx()+a_zy*guan.sigma_zy()+a_zz*guan.sigma_zz()
eigenvalue_1 = guan.calculate_eigenvalue(hamiltonian_1)
# only guan.sigma_0x() is changed to guan.sigma_x0()
hamiltonian_3 = \
a_00*guan.sigma_00()+a_0x*guan.sigma_x0()+a_0y*guan.sigma_0y()+a_0z*guan.sigma_0z()+ \
a_x0*guan.sigma_x0()+a_xx*guan.sigma_xx()+a_xy*guan.sigma_xy()+a_xz*guan.sigma_xz()+ \
a_y0*guan.sigma_y0()+a_yx*guan.sigma_yx()+a_yy*guan.sigma_yy()+a_yz*guan.sigma_yz()+ \
a_z0*guan.sigma_z0()+a_zx*guan.sigma_zx()+a_zy*guan.sigma_zy()+a_zz*guan.sigma_zz()
eigenvalue_3 = guan.calculate_eigenvalue(hamiltonian_3)
print()
print('Eigenvalue:')
print(eigenvalue_1)
print(eigenvalue_3)
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/12731
"""
import numpy as np
import guan
a_00 = np.random.uniform(-1, 1)
a_0x = np.random.uniform(-1, 1)
a_0y = np.random.uniform(-1, 1)
a_0z = np.random.uniform(-1, 1)
a_x0 = np.random.uniform(-1, 1)
a_xx = np.random.uniform(-1, 1)
a_xy = np.random.uniform(-1, 1)
a_xz = np.random.uniform(-1, 1)
a_y0 = np.random.uniform(-1, 1)
a_yx = np.random.uniform(-1, 1)
a_yy = np.random.uniform(-1, 1)
a_yz = np.random.uniform(-1, 1)
a_z0 = np.random.uniform(-1, 1)
a_zx = np.random.uniform(-1, 1)
a_zy = np.random.uniform(-1, 1)
a_zz = np.random.uniform(-1, 1)
hamiltonian_1 = \
a_00*guan.sigma_00()+a_0x*guan.sigma_0x()+a_0y*guan.sigma_0y()+a_0z*guan.sigma_0z()+ \
a_x0*guan.sigma_x0()+a_xx*guan.sigma_xx()+a_xy*guan.sigma_xy()+a_xz*guan.sigma_xz()+ \
a_y0*guan.sigma_y0()+a_yx*guan.sigma_yx()+a_yy*guan.sigma_yy()+a_yz*guan.sigma_yz()+ \
a_z0*guan.sigma_z0()+a_zx*guan.sigma_zx()+a_zy*guan.sigma_zy()+a_zz*guan.sigma_zz()
eigenvalue_1 = guan.calculate_eigenvalue(hamiltonian_1)
# only guan.sigma_0x() is changed to guan.sigma_x0()
hamiltonian_3 = \
a_00*guan.sigma_00()+a_0x*guan.sigma_x0()+a_0y*guan.sigma_0y()+a_0z*guan.sigma_0z()+ \
a_x0*guan.sigma_x0()+a_xx*guan.sigma_xx()+a_xy*guan.sigma_xy()+a_xz*guan.sigma_xz()+ \
a_y0*guan.sigma_y0()+a_yx*guan.sigma_yx()+a_yy*guan.sigma_yy()+a_yz*guan.sigma_yz()+ \
a_z0*guan.sigma_z0()+a_zx*guan.sigma_zx()+a_zy*guan.sigma_zy()+a_zz*guan.sigma_zz()
eigenvalue_3 = guan.calculate_eigenvalue(hamiltonian_3)
print()
print('Eigenvalue:')
print(eigenvalue_1)
print(eigenvalue_3)
print()

View File

@@ -1,114 +1,114 @@
import numpy as np
import matplotlib.pyplot as plt
import os
# os.chdir('E:/data') # 设置路径
# 万有引力常数
G = 1
# 三体的质量
m1 = 10 # 绿色
m2 = 1000 # 红色
m3 = 10 # 蓝色
# 三体的初始位置
x1 = 0 # 绿色
y1 = 500
x2 = 0 # 红色
y2 = 0
x3 = 0 # 蓝色
y3 = 1000
# 三体的初始速度
v1_x = 1.5 # 绿色
v1_y = 0
v2_x = 0 # 红色
v2_y = 0
v3_x = 0.8 # 蓝色
v3_y = 0
# 步长
t = 0.1
plt.ion() # 开启交互模式
observation_max = 100 # 视线范围初始值
x1_all = [x1] # 轨迹初始值
y1_all = [y1]
x2_all = [x2]
y2_all = [y2]
x3_all = [x3]
y3_all = [y3]
i0 = 0
for i in range(1000000):
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
# 对物体1的计算
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度用上万有引力公式
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
v1_x = v1_x + a1_x*t # 物体1的速度
v1_y = v1_y + a1_y*t # 物体1的速度
x1 = x1 + v1_x*t # 物体1的水平位置
y1 = y1 + v1_y*t # 物体1的垂直位置
x1_all = np.append(x1_all, x1) # 记录轨迹
y1_all = np.append(y1_all, y1) # 记录轨迹
# 对物体2的计算
a2_1 = G*m1/(distance12**2)
a2_3 = G*m3/(distance23**2)
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
v2_x = v2_x + a2_x*t
v2_y = v2_y + a2_y*t
x2 = x2 + v2_x*t
y2 = y2 + v2_y*t
x2_all = np.append(x2_all, x2)
y2_all = np.append(y2_all, y2)
# 对物体3的计算
a3_1 = G*m1/(distance13**2)
a3_2 = G*m2/(distance23**2)
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
v3_x = v3_x + a3_x*t
v3_y = v3_y + a3_y*t
x3 = x3 + v3_x*t
y3 = y3 + v3_y*t
x3_all = np.append(x3_all, x3)
y3_all = np.append(y3_all, y3)
# 选择观测坐标
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
while True:
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内视线范围减半
else:
break
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
plt.plot(x1_all, y1_all, '-g') # 画轨迹
plt.plot(x2_all, y2_all, '-r')
plt.plot(x3_all, y3_all, '-b')
# plt.show() # 显示图像
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
if np.mod(i, 100) == 0: # 当运动明显时,把图画出来
print(i0)
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
i0 += 1
plt.clf() # 清空
import numpy as np
import matplotlib.pyplot as plt
import os
# os.chdir('E:/data') # 设置路径
# 万有引力常数
G = 1
# 三体的质量
m1 = 10 # 绿色
m2 = 1000 # 红色
m3 = 10 # 蓝色
# 三体的初始位置
x1 = 0 # 绿色
y1 = 500
x2 = 0 # 红色
y2 = 0
x3 = 0 # 蓝色
y3 = 1000
# 三体的初始速度
v1_x = 1.5 # 绿色
v1_y = 0
v2_x = 0 # 红色
v2_y = 0
v3_x = 0.8 # 蓝色
v3_y = 0
# 步长
t = 0.1
plt.ion() # 开启交互模式
observation_max = 100 # 视线范围初始值
x1_all = [x1] # 轨迹初始值
y1_all = [y1]
x2_all = [x2]
y2_all = [y2]
x3_all = [x3]
y3_all = [y3]
i0 = 0
for i in range(1000000):
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
# 对物体1的计算
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度用上万有引力公式
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
v1_x = v1_x + a1_x*t # 物体1的速度
v1_y = v1_y + a1_y*t # 物体1的速度
x1 = x1 + v1_x*t # 物体1的水平位置
y1 = y1 + v1_y*t # 物体1的垂直位置
x1_all = np.append(x1_all, x1) # 记录轨迹
y1_all = np.append(y1_all, y1) # 记录轨迹
# 对物体2的计算
a2_1 = G*m1/(distance12**2)
a2_3 = G*m3/(distance23**2)
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
v2_x = v2_x + a2_x*t
v2_y = v2_y + a2_y*t
x2 = x2 + v2_x*t
y2 = y2 + v2_y*t
x2_all = np.append(x2_all, x2)
y2_all = np.append(y2_all, y2)
# 对物体3的计算
a3_1 = G*m1/(distance13**2)
a3_2 = G*m2/(distance23**2)
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
v3_x = v3_x + a3_x*t
v3_y = v3_y + a3_y*t
x3 = x3 + v3_x*t
y3 = y3 + v3_y*t
x3_all = np.append(x3_all, x3)
y3_all = np.append(y3_all, y3)
# 选择观测坐标
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
while True:
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内视线范围减半
else:
break
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
plt.plot(x1_all, y1_all, '-g') # 画轨迹
plt.plot(x2_all, y2_all, '-r')
plt.plot(x3_all, y3_all, '-b')
# plt.show() # 显示图像
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
if np.mod(i, 100) == 0: # 当运动明显时,把图画出来
print(i0)
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
i0 += 1
plt.clf() # 清空

View File

@@ -1,110 +1,110 @@
import numpy as np
import matplotlib.pyplot as plt
import os
# os.chdir('E:/data') # 设置路径
# 万有引力常数
G = 1
# 三体的质量
m1 = 3 # 绿色
m2 = 100 # 红色
m3 = 10 # 蓝色
# 三体的初始位置
x1 = 0 # 绿色
y1 = -100
x2 = 0 # 红色
y2 = 0
x3 = 0 # 蓝色
y3 = 50
# 三体的初始速度
v1_x = 1 # 绿色
v1_y = 0
v2_x = 0 # 红色
v2_y = 0
v3_x = 2 # 蓝色
v3_y = 0
# 步长
t = 0.05
plt.ion() # 开启交互模式
observation_max = 100 # 观测坐标范围初始值
x1_all = [x1] # 轨迹初始值
y1_all = [y1]
x2_all = [x2]
y2_all = [y2]
x3_all = [x3]
y3_all = [y3]
i0 = 0
for i in range(100000000000):
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
# 对物体1的计算
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度用上万有引力公式
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
v1_x = v1_x + a1_x*t # 物体1的速度
v1_y = v1_y + a1_y*t # 物体1的速度
x1 = x1 + v1_x*t # 物体1的水平位置
y1 = y1 + v1_y*t # 物体1的垂直位置
x1_all = np.append(x1_all, x1) # 记录轨迹
y1_all = np.append(y1_all, y1) # 记录轨迹
# 对物体2的计算
a2_1 = G*m1/(distance12**2)
a2_3 = G*m3/(distance23**2)
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
v2_x = v2_x + a2_x*t
v2_y = v2_y + a2_y*t
x2 = x2 + v2_x*t
y2 = y2 + v2_y*t
x2_all = np.append(x2_all, x2)
y2_all = np.append(y2_all, y2)
# 对物体3的计算
a3_1 = G*m1/(distance13**2)
a3_2 = G*m2/(distance23**2)
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
v3_x = v3_x + a3_x*t
v3_y = v3_y + a3_y*t
x3 = x3 + v3_x*t
y3 = y3 + v3_y*t
x3_all = np.append(x3_all, x3)
y3_all = np.append(y3_all, y3)
# 选择观测坐标
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
while True:
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内视线范围减半
else:
break
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,画出来的面积越大。视线范围越宽,球看起来越小。
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
plt.plot(x1_all, y1_all, '-g') # 画轨迹
plt.plot(x2_all, y2_all, '-r')
plt.plot(x3_all, y3_all, '-b')
# plt.show() # 显示图像
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
if np.mod(i, 200) == 0:
print(i0)
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
i0 += 1
import numpy as np
import matplotlib.pyplot as plt
import os
# os.chdir('E:/data') # 设置路径
# 万有引力常数
G = 1
# 三体的质量
m1 = 3 # 绿色
m2 = 100 # 红色
m3 = 10 # 蓝色
# 三体的初始位置
x1 = 0 # 绿色
y1 = -100
x2 = 0 # 红色
y2 = 0
x3 = 0 # 蓝色
y3 = 50
# 三体的初始速度
v1_x = 1 # 绿色
v1_y = 0
v2_x = 0 # 红色
v2_y = 0
v3_x = 2 # 蓝色
v3_y = 0
# 步长
t = 0.05
plt.ion() # 开启交互模式
observation_max = 100 # 观测坐标范围初始值
x1_all = [x1] # 轨迹初始值
y1_all = [y1]
x2_all = [x2]
y2_all = [y2]
x3_all = [x3]
y3_all = [y3]
i0 = 0
for i in range(100000000000):
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
# 对物体1的计算
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度用上万有引力公式
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
v1_x = v1_x + a1_x*t # 物体1的速度
v1_y = v1_y + a1_y*t # 物体1的速度
x1 = x1 + v1_x*t # 物体1的水平位置
y1 = y1 + v1_y*t # 物体1的垂直位置
x1_all = np.append(x1_all, x1) # 记录轨迹
y1_all = np.append(y1_all, y1) # 记录轨迹
# 对物体2的计算
a2_1 = G*m1/(distance12**2)
a2_3 = G*m3/(distance23**2)
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
v2_x = v2_x + a2_x*t
v2_y = v2_y + a2_y*t
x2 = x2 + v2_x*t
y2 = y2 + v2_y*t
x2_all = np.append(x2_all, x2)
y2_all = np.append(y2_all, y2)
# 对物体3的计算
a3_1 = G*m1/(distance13**2)
a3_2 = G*m2/(distance23**2)
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
v3_x = v3_x + a3_x*t
v3_y = v3_y + a3_y*t
x3 = x3 + v3_x*t
y3 = y3 + v3_y*t
x3_all = np.append(x3_all, x3)
y3_all = np.append(y3_all, y3)
# 选择观测坐标
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
while True:
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内视线范围减半
else:
break
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,画出来的面积越大。视线范围越宽,球看起来越小。
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
plt.plot(x1_all, y1_all, '-g') # 画轨迹
plt.plot(x2_all, y2_all, '-r')
plt.plot(x3_all, y3_all, '-b')
# plt.show() # 显示图像
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
if np.mod(i, 200) == 0:
print(i0)
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
i0 += 1
plt.clf() # 清空

View File

@@ -1,110 +1,110 @@
import numpy as np
import matplotlib.pyplot as plt
import os
# os.chdir('E:/data') # 设置路径
# 万有引力常数
G = 1
# 三体的质量
m1 = 3 # 绿色
m2 = 100 # 红色
m3 = 10 # 蓝色
# 三体的初始位置
x1 = 0 # 绿色
y1 = -100
x2 = 0 # 红色
y2 = 0
x3 = 0 # 蓝色
y3 = 50
# 三体的初始速度
v1_x = 1 # 绿色
v1_y = 0
v2_x = 0 # 红色
v2_y = 0
v3_x = 2 # 蓝色
v3_y = 0
# 步长
t = 0.1
plt.ion() # 开启交互模式
observation_max = 100 # 观测坐标范围初始值
x1_all = [x1] # 轨迹初始值
y1_all = [y1]
x2_all = [x2]
y2_all = [y2]
x3_all = [x3]
y3_all = [y3]
i0 = 0
for i in range(100000000000):
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
# 对物体1的计算
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度用上万有引力公式
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
v1_x = v1_x + a1_x*t # 物体1的速度
v1_y = v1_y + a1_y*t # 物体1的速度
x1 = x1 + v1_x*t # 物体1的水平位置
y1 = y1 + v1_y*t # 物体1的垂直位置
x1_all = np.append(x1_all, x1) # 记录轨迹
y1_all = np.append(y1_all, y1) # 记录轨迹
# 对物体2的计算
a2_1 = G*m1/(distance12**2)
a2_3 = G*m3/(distance23**2)
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
v2_x = v2_x + a2_x*t
v2_y = v2_y + a2_y*t
x2 = x2 + v2_x*t
y2 = y2 + v2_y*t
x2_all = np.append(x2_all, x2)
y2_all = np.append(y2_all, y2)
# 对物体3的计算
a3_1 = G*m1/(distance13**2)
a3_2 = G*m2/(distance23**2)
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
v3_x = v3_x + a3_x*t
v3_y = v3_y + a3_y*t
x3 = x3 + v3_x*t
y3 = y3 + v3_y*t
x3_all = np.append(x3_all, x3)
y3_all = np.append(y3_all, y3)
# 选择观测坐标
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
while True:
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内视线范围减半
else:
break
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,画出来的面积越大。视线范围越宽,球看起来越小。
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
plt.plot(x1_all, y1_all, '-g') # 画轨迹
plt.plot(x2_all, y2_all, '-r')
plt.plot(x3_all, y3_all, '-b')
# plt.show() # 显示图像
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
if np.mod(i, 100) == 0:
print(i0)
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
i0 += 1
import numpy as np
import matplotlib.pyplot as plt
import os
# os.chdir('E:/data') # 设置路径
# 万有引力常数
G = 1
# 三体的质量
m1 = 3 # 绿色
m2 = 100 # 红色
m3 = 10 # 蓝色
# 三体的初始位置
x1 = 0 # 绿色
y1 = -100
x2 = 0 # 红色
y2 = 0
x3 = 0 # 蓝色
y3 = 50
# 三体的初始速度
v1_x = 1 # 绿色
v1_y = 0
v2_x = 0 # 红色
v2_y = 0
v3_x = 2 # 蓝色
v3_y = 0
# 步长
t = 0.1
plt.ion() # 开启交互模式
observation_max = 100 # 观测坐标范围初始值
x1_all = [x1] # 轨迹初始值
y1_all = [y1]
x2_all = [x2]
y2_all = [y2]
x3_all = [x3]
y3_all = [y3]
i0 = 0
for i in range(100000000000):
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
# 对物体1的计算
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度用上万有引力公式
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
v1_x = v1_x + a1_x*t # 物体1的速度
v1_y = v1_y + a1_y*t # 物体1的速度
x1 = x1 + v1_x*t # 物体1的水平位置
y1 = y1 + v1_y*t # 物体1的垂直位置
x1_all = np.append(x1_all, x1) # 记录轨迹
y1_all = np.append(y1_all, y1) # 记录轨迹
# 对物体2的计算
a2_1 = G*m1/(distance12**2)
a2_3 = G*m3/(distance23**2)
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
v2_x = v2_x + a2_x*t
v2_y = v2_y + a2_y*t
x2 = x2 + v2_x*t
y2 = y2 + v2_y*t
x2_all = np.append(x2_all, x2)
y2_all = np.append(y2_all, y2)
# 对物体3的计算
a3_1 = G*m1/(distance13**2)
a3_2 = G*m2/(distance23**2)
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
v3_x = v3_x + a3_x*t
v3_y = v3_y + a3_y*t
x3 = x3 + v3_x*t
y3 = y3 + v3_y*t
x3_all = np.append(x3_all, x3)
y3_all = np.append(y3_all, y3)
# 选择观测坐标
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
while True:
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内视线范围减半
else:
break
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,画出来的面积越大。视线范围越宽,球看起来越小。
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
plt.plot(x1_all, y1_all, '-g') # 画轨迹
plt.plot(x2_all, y2_all, '-r')
plt.plot(x3_all, y3_all, '-b')
# plt.show() # 显示图像
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
if np.mod(i, 100) == 0:
print(i0)
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
i0 += 1
plt.clf() # 清空

View File

@@ -1,113 +1,113 @@
import numpy as np
import matplotlib.pyplot as plt
import os
# os.chdir('E:/data') # 设置路径
# 万有引力常数
G = 1
# 三体的质量
m1 = 15 # 绿色
m2 = 12 # 红色
m3 = 8 # 蓝色
# 三体的初始位置
x1 = 300 # 绿色
y1 = 50
x2 = -100 # 红色
y2 = -200
x3 = -100 # 蓝色
y3 = 150
# 三体的初始速度
v1_x = 0 # 绿色
v1_y = 0
v2_x = 0 # 红色
v2_y = 0
v3_x = 0 # 蓝色
v3_y = 0
# 步长
t = 0.05
plt.ion() # 开启交互模式
observation_max = 100 # 视线范围初始值
x1_all = [x1] # 轨迹初始值
y1_all = [y1]
x2_all = [x2]
y2_all = [y2]
x3_all = [x3]
y3_all = [y3]
i0 = 0
for i in range(1000000):
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
# 对物体1的计算
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度用上万有引力公式
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
v1_x = v1_x + a1_x*t # 物体1的速度
v1_y = v1_y + a1_y*t # 物体1的速度
x1 = x1 + v1_x*t # 物体1的水平位置
y1 = y1 + v1_y*t # 物体1的垂直位置
x1_all = np.append(x1_all, x1) # 记录轨迹
y1_all = np.append(y1_all, y1) # 记录轨迹
# 对物体2的计算
a2_1 = G*m1/(distance12**2)
a2_3 = G*m3/(distance23**2)
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
v2_x = v2_x + a2_x*t
v2_y = v2_y + a2_y*t
x2 = x2 + v2_x*t
y2 = y2 + v2_y*t
x2_all = np.append(x2_all, x2)
y2_all = np.append(y2_all, y2)
# 对物体3的计算
a3_1 = G*m1/(distance13**2)
a3_2 = G*m2/(distance23**2)
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
v3_x = v3_x + a3_x*t
v3_y = v3_y + a3_y*t
x3 = x3 + v3_x*t
y3 = y3 + v3_y*t
x3_all = np.append(x3_all, x3)
y3_all = np.append(y3_all, y3)
# 选择观测坐标
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
while True:
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内视线范围减半
else:
break
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
plt.plot(x1_all, y1_all, '-g') # 画轨迹
plt.plot(x2_all, y2_all, '-r')
plt.plot(x3_all, y3_all, '-b')
# plt.show() # 显示图像
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
if np.mod(i, 1000) == 0: # 当运动明显时,把图画出来
print(i0)
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
i0 += 1
plt.clf() # 清空
import numpy as np
import matplotlib.pyplot as plt
import os
# os.chdir('E:/data') # 设置路径
# 万有引力常数
G = 1
# 三体的质量
m1 = 15 # 绿色
m2 = 12 # 红色
m3 = 8 # 蓝色
# 三体的初始位置
x1 = 300 # 绿色
y1 = 50
x2 = -100 # 红色
y2 = -200
x3 = -100 # 蓝色
y3 = 150
# 三体的初始速度
v1_x = 0 # 绿色
v1_y = 0
v2_x = 0 # 红色
v2_y = 0
v3_x = 0 # 蓝色
v3_y = 0
# 步长
t = 0.05
plt.ion() # 开启交互模式
observation_max = 100 # 视线范围初始值
x1_all = [x1] # 轨迹初始值
y1_all = [y1]
x2_all = [x2]
y2_all = [y2]
x3_all = [x3]
y3_all = [y3]
i0 = 0
for i in range(1000000):
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
# 对物体1的计算
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度用上万有引力公式
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
v1_x = v1_x + a1_x*t # 物体1的速度
v1_y = v1_y + a1_y*t # 物体1的速度
x1 = x1 + v1_x*t # 物体1的水平位置
y1 = y1 + v1_y*t # 物体1的垂直位置
x1_all = np.append(x1_all, x1) # 记录轨迹
y1_all = np.append(y1_all, y1) # 记录轨迹
# 对物体2的计算
a2_1 = G*m1/(distance12**2)
a2_3 = G*m3/(distance23**2)
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
v2_x = v2_x + a2_x*t
v2_y = v2_y + a2_y*t
x2 = x2 + v2_x*t
y2 = y2 + v2_y*t
x2_all = np.append(x2_all, x2)
y2_all = np.append(y2_all, y2)
# 对物体3的计算
a3_1 = G*m1/(distance13**2)
a3_2 = G*m2/(distance23**2)
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
v3_x = v3_x + a3_x*t
v3_y = v3_y + a3_y*t
x3 = x3 + v3_x*t
y3 = y3 + v3_y*t
x3_all = np.append(x3_all, x3)
y3_all = np.append(y3_all, y3)
# 选择观测坐标
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
while True:
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内视线范围减半
else:
break
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
plt.plot(x1_all, y1_all, '-g') # 画轨迹
plt.plot(x2_all, y2_all, '-r')
plt.plot(x3_all, y3_all, '-b')
# plt.show() # 显示图像
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
if np.mod(i, 1000) == 0: # 当运动明显时,把图画出来
print(i0)
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
i0 += 1
plt.clf() # 清空

View File

@@ -1,113 +1,113 @@
import numpy as np
import matplotlib.pyplot as plt
import os
# os.chdir('E:/data') # 设置路径
# 万有引力常数
G = 1
# 三体的质量
m1 = 15 # 绿色
m2 = 12 # 红色
m3 = 8 # 蓝色
# 三体的初始位置
x1 = 300 # 绿色
y1 = 50
x2 = -100 # 红色
y2 = -200
x3 = -100 # 蓝色
y3 = 150
# 三体的初始速度
v1_x = 0 # 绿色
v1_y = 0
v2_x = 0 # 红色
v2_y = 0
v3_x = 0 # 蓝色
v3_y = 0
# 步长
t = 0.1
plt.ion() # 开启交互模式
observation_max = 100 # 视线范围初始值
x1_all = [x1] # 轨迹初始值
y1_all = [y1]
x2_all = [x2]
y2_all = [y2]
x3_all = [x3]
y3_all = [y3]
i0 = 0
for i in range(1000000):
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
# 对物体1的计算
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度用上万有引力公式
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
v1_x = v1_x + a1_x*t # 物体1的速度
v1_y = v1_y + a1_y*t # 物体1的速度
x1 = x1 + v1_x*t # 物体1的水平位置
y1 = y1 + v1_y*t # 物体1的垂直位置
x1_all = np.append(x1_all, x1) # 记录轨迹
y1_all = np.append(y1_all, y1) # 记录轨迹
# 对物体2的计算
a2_1 = G*m1/(distance12**2)
a2_3 = G*m3/(distance23**2)
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
v2_x = v2_x + a2_x*t
v2_y = v2_y + a2_y*t
x2 = x2 + v2_x*t
y2 = y2 + v2_y*t
x2_all = np.append(x2_all, x2)
y2_all = np.append(y2_all, y2)
# 对物体3的计算
a3_1 = G*m1/(distance13**2)
a3_2 = G*m2/(distance23**2)
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
v3_x = v3_x + a3_x*t
v3_y = v3_y + a3_y*t
x3 = x3 + v3_x*t
y3 = y3 + v3_y*t
x3_all = np.append(x3_all, x3)
y3_all = np.append(y3_all, y3)
# 选择观测坐标
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
while True:
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内视线范围减半
else:
break
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
plt.plot(x1_all, y1_all, '-g') # 画轨迹
plt.plot(x2_all, y2_all, '-r')
plt.plot(x3_all, y3_all, '-b')
# plt.show() # 显示图像
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
if np.mod(i, 500) == 0: # 当运动明显时,把图画出来
print(i0)
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
i0 += 1
plt.clf() # 清空
import numpy as np
import matplotlib.pyplot as plt
import os
# os.chdir('E:/data') # 设置路径
# 万有引力常数
G = 1
# 三体的质量
m1 = 15 # 绿色
m2 = 12 # 红色
m3 = 8 # 蓝色
# 三体的初始位置
x1 = 300 # 绿色
y1 = 50
x2 = -100 # 红色
y2 = -200
x3 = -100 # 蓝色
y3 = 150
# 三体的初始速度
v1_x = 0 # 绿色
v1_y = 0
v2_x = 0 # 红色
v2_y = 0
v3_x = 0 # 蓝色
v3_y = 0
# 步长
t = 0.1
plt.ion() # 开启交互模式
observation_max = 100 # 视线范围初始值
x1_all = [x1] # 轨迹初始值
y1_all = [y1]
x2_all = [x2]
y2_all = [y2]
x3_all = [x3]
y3_all = [y3]
i0 = 0
for i in range(1000000):
distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离
distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离
distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离
# 对物体1的计算
a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度用上万有引力公式
a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度
a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度
a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度
v1_x = v1_x + a1_x*t # 物体1的速度
v1_y = v1_y + a1_y*t # 物体1的速度
x1 = x1 + v1_x*t # 物体1的水平位置
y1 = y1 + v1_y*t # 物体1的垂直位置
x1_all = np.append(x1_all, x1) # 记录轨迹
y1_all = np.append(y1_all, y1) # 记录轨迹
# 对物体2的计算
a2_1 = G*m1/(distance12**2)
a2_3 = G*m3/(distance23**2)
a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23
a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23
v2_x = v2_x + a2_x*t
v2_y = v2_y + a2_y*t
x2 = x2 + v2_x*t
y2 = y2 + v2_y*t
x2_all = np.append(x2_all, x2)
y2_all = np.append(y2_all, y2)
# 对物体3的计算
a3_1 = G*m1/(distance13**2)
a3_2 = G*m2/(distance23**2)
a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23
a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23
v3_x = v3_x + a3_x*t
v3_y = v3_y + a3_y*t
x3 = x3 + v3_x*t
y3 = y3 + v3_y*t
x3_all = np.append(x3_all, x3)
y3_all = np.append(y3_all, y3)
# 选择观测坐标
axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方
axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方
while True:
if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\
np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max:
observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍
elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\
np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10:
observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内视线范围减半
else:
break
plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max])
plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。
plt.plot(x2, y2, 'or', markersize=m2*100/observation_max)
plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max)
plt.plot(x1_all, y1_all, '-g') # 画轨迹
plt.plot(x2_all, y2_all, '-r')
plt.plot(x3_all, y3_all, '-b')
# plt.show() # 显示图像
# plt.pause(0.00001) # 暂停0.00001,防止画图过快
if np.mod(i, 500) == 0: # 当运动明显时,把图画出来
print(i0)
plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画
i0 += 1
plt.clf() # 清空

View File

@@ -1,73 +1,73 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/1145
"""
import numpy as np
import random
import time
def integral(): # 直接数值积分
integral_value = 0
for x in np.arange(0, 1, 1/10**7):
integral_value = integral_value + x**2*(1/10**7) # 对x^2在0和1之间积分
return integral_value
def MC_1(): # 蒙特卡洛求定积分1投点法
n = 10**7
x_min, x_max = 0.0, 1.0
y_min, y_max = 0.0, 1.0
count = 0
for i in range(0, n):
x = random.uniform(x_min, x_max)
y = random.uniform(y_min, y_max)
# x*x > y表示该点位于曲线的下面。所求的积分值即为曲线下方的面积与正方形面积的比。
if x * x > y:
count += 1
integral_value = count / n
return integral_value
def MC_2(): # 蒙特卡洛求定积分2期望法
n = 10**7
x_min, x_max = 0.0, 1.0
integral_value = 0
for i in range(n):
x = random.uniform(x_min, x_max)
integral_value = integral_value + (1-0)*x**2
integral_value = integral_value/n
return integral_value
print('【计算时间】')
start_clock = time.perf_counter() # 或者用time.clock()
a00 = 1/3 # 理论值
end_clock = time.perf_counter()
print('理论值(解析):', end_clock-start_clock)
start_clock = time.perf_counter()
a0 = integral() # 直接数值积分
end_clock = time.perf_counter()
print('直接数值积分:', end_clock-start_clock)
start_clock = time.perf_counter()
a1 = MC_1() # 用蒙特卡洛求积分投点法
end_clock = time.perf_counter()
print('用蒙特卡洛求积分_投点法', end_clock-start_clock)
start_clock = time.perf_counter()
a2 = MC_2()
end_clock = time.perf_counter()
print('用蒙特卡洛求积分_期望法', end_clock-start_clock, '\n')
print('【计算结果】')
print('理论值(解析):', a00)
print('直接数值积分:', a0)
print('用蒙特卡洛求积分_投点法', a1)
print('用蒙特卡洛求积分_期望法', a2, '\n')
print('【计算误差】')
print('理论值(解析):', 0)
print('直接数值积分:', abs(a0-1/3))
print('用蒙特卡洛求积分_投点法', abs(a1-1/3))
print('用蒙特卡洛求积分_期望法', abs(a2-1/3))
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/1145
"""
import numpy as np
import random
import time
def integral(): # 直接数值积分
integral_value = 0
for x in np.arange(0, 1, 1/10**7):
integral_value = integral_value + x**2*(1/10**7) # 对x^2在0和1之间积分
return integral_value
def MC_1(): # 蒙特卡洛求定积分1投点法
n = 10**7
x_min, x_max = 0.0, 1.0
y_min, y_max = 0.0, 1.0
count = 0
for i in range(0, n):
x = random.uniform(x_min, x_max)
y = random.uniform(y_min, y_max)
# x*x > y表示该点位于曲线的下面。所求的积分值即为曲线下方的面积与正方形面积的比。
if x * x > y:
count += 1
integral_value = count / n
return integral_value
def MC_2(): # 蒙特卡洛求定积分2期望法
n = 10**7
x_min, x_max = 0.0, 1.0
integral_value = 0
for i in range(n):
x = random.uniform(x_min, x_max)
integral_value = integral_value + (1-0)*x**2
integral_value = integral_value/n
return integral_value
print('【计算时间】')
start_clock = time.perf_counter() # 或者用time.clock()
a00 = 1/3 # 理论值
end_clock = time.perf_counter()
print('理论值(解析):', end_clock-start_clock)
start_clock = time.perf_counter()
a0 = integral() # 直接数值积分
end_clock = time.perf_counter()
print('直接数值积分:', end_clock-start_clock)
start_clock = time.perf_counter()
a1 = MC_1() # 用蒙特卡洛求积分投点法
end_clock = time.perf_counter()
print('用蒙特卡洛求积分_投点法', end_clock-start_clock)
start_clock = time.perf_counter()
a2 = MC_2()
end_clock = time.perf_counter()
print('用蒙特卡洛求积分_期望法', end_clock-start_clock, '\n')
print('【计算结果】')
print('理论值(解析):', a00)
print('直接数值积分:', a0)
print('用蒙特卡洛求积分_投点法', a1)
print('用蒙特卡洛求积分_期望法', a2, '\n')
print('【计算误差】')
print('理论值(解析):', 0)
print('直接数值积分:', abs(a0-1/3))
print('用蒙特卡洛求积分_投点法', abs(a1-1/3))
print('用蒙特卡洛求积分_期望法', abs(a2-1/3))

View File

@@ -1,61 +1,61 @@
import numpy as np
import matplotlib.pyplot as plt
import time
time_1 = np.array([])
time_2 = np.array([])
time_3 = np.array([])
n_all = np.arange(2,5000,200) # 测试的范围
start_all = time.process_time()
for n in n_all:
print(n)
matrix_1 = np.zeros((n,n))
matrix_2 = np.zeros((n,n))
for i0 in range(n):
for j0 in range(n):
matrix_1[i0,j0] = np.random.uniform(-10, 10)
for i0 in range(n):
for j0 in range(n):
matrix_2[i0,j0] = np.random.uniform(-10, 10)
start = time.process_time()
matrix_3 = np.dot(matrix_1, matrix_2) # 矩阵乘积
end = time.process_time()
time_1 = np.append(time_1, [end-start], axis=0)
start = time.process_time()
matrix_4 = np.linalg.inv(matrix_1) # 矩阵求逆
end = time.process_time()
time_2 = np.append(time_2, [end-start], axis=0)
start = time.process_time()
eigenvalue, eigenvector = np.linalg.eig(matrix_1) # 求矩阵本征值
end = time.process_time()
time_3 = np.append(time_3, [end-start], axis=0)
end_all = time.process_time()
print('总共运行时间:', (end_all-start_all)/60, '')
plt.subplot(131)
plt.xlabel('n^3/10^9')
plt.ylabel('时间(秒)')
plt.title('矩阵乘积')
plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_1, 'o-')
plt.subplot(132)
plt.xlabel('n^3/10^9')
plt.title('矩阵求逆')
plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_2, 'o-')
plt.subplot(133)
plt.xlabel('n^3/10^9')
plt.title('求矩阵本征值')
plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_3, 'o-')
plt.rcParams['font.sans-serif'] = ['SimHei'] # 在画图中正常显示中文
plt.rcParams['axes.unicode_minus'] = False # 中文化后,加上这个使正常显示负号
import numpy as np
import matplotlib.pyplot as plt
import time
time_1 = np.array([])
time_2 = np.array([])
time_3 = np.array([])
n_all = np.arange(2,5000,200) # 测试的范围
start_all = time.process_time()
for n in n_all:
print(n)
matrix_1 = np.zeros((n,n))
matrix_2 = np.zeros((n,n))
for i0 in range(n):
for j0 in range(n):
matrix_1[i0,j0] = np.random.uniform(-10, 10)
for i0 in range(n):
for j0 in range(n):
matrix_2[i0,j0] = np.random.uniform(-10, 10)
start = time.process_time()
matrix_3 = np.dot(matrix_1, matrix_2) # 矩阵乘积
end = time.process_time()
time_1 = np.append(time_1, [end-start], axis=0)
start = time.process_time()
matrix_4 = np.linalg.inv(matrix_1) # 矩阵求逆
end = time.process_time()
time_2 = np.append(time_2, [end-start], axis=0)
start = time.process_time()
eigenvalue, eigenvector = np.linalg.eig(matrix_1) # 求矩阵本征值
end = time.process_time()
time_3 = np.append(time_3, [end-start], axis=0)
end_all = time.process_time()
print('总共运行时间:', (end_all-start_all)/60, '')
plt.subplot(131)
plt.xlabel('n^3/10^9')
plt.ylabel('时间(秒)')
plt.title('矩阵乘积')
plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_1, 'o-')
plt.subplot(132)
plt.xlabel('n^3/10^9')
plt.title('矩阵求逆')
plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_2, 'o-')
plt.subplot(133)
plt.xlabel('n^3/10^9')
plt.title('求矩阵本征值')
plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_3, 'o-')
plt.rcParams['font.sans-serif'] = ['SimHei'] # 在画图中正常显示中文
plt.rcParams['axes.unicode_minus'] = False # 中文化后,加上这个使正常显示负号
plt.show()

View File

@@ -1,73 +1,73 @@
(* Content-type: application/vnd.wolfram.mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 12.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 158, 7]
NotebookDataLength[ 2028, 65]
NotebookOptionsPosition[ 1687, 50]
NotebookOutlinePosition[ 2075, 67]
CellTagsIndexPosition[ 2032, 64]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[
RowBox[{"\[IndentingNewLine]",
RowBox[{
RowBox[{"Clear", "[", "\"\<`*\>\"", "]"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{"A", "=",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"3", ",", "2", ",",
RowBox[{"-", "1"}]}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{"-", "2"}], ",",
RowBox[{"-", "2"}], ",", "2"}], "}"}], ",", " ",
RowBox[{"{",
RowBox[{"3", ",", "6", ",",
RowBox[{"-", "1"}]}], "}"}]}], "}"}]}], ";"}], "\[IndentingNewLine]",
RowBox[{"MatrixForm", "[", "A", "]"}], "\n",
RowBox[{"eigenvalue", "=",
RowBox[{"MatrixForm", "[",
RowBox[{"Eigenvalues", "[", "A", "]"}], "]"}]}], "\n",
RowBox[{"eigenvector", "=",
RowBox[{"MatrixForm", "[",
RowBox[{"Eigenvectors", "[", "A", "]"}], "]"}]}]}]}]], "Input",
CellChangeTimes->{{3.8249089321894894`*^9, 3.8249090194456663`*^9}, {
3.8249090545199647`*^9, 3.824909158471919*^9}, {3.8249092372038407`*^9,
3.824909243121014*^9}},
CellLabel->"In[24]:=",ExpressionUUID->"54dc89aa-0cf7-4c91-9e21-ea7b96cf97e8"]
},
WindowSize->{1128, 568},
WindowMargins->{{Automatic, 375}, {Automatic, 189}},
Magnification:>1.2 Inherited,
FrontEndVersion->"12.0 for Microsoft Windows (64-bit) (2019\:5e744\:67088\
\:65e5)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)
(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[558, 20, 1125, 28, 238, "Input",ExpressionUUID->"54dc89aa-0cf7-4c91-9e21-ea7b96cf97e8"]
}
]
*)
(* Content-type: application/vnd.wolfram.mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 12.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 158, 7]
NotebookDataLength[ 2028, 65]
NotebookOptionsPosition[ 1687, 50]
NotebookOutlinePosition[ 2075, 67]
CellTagsIndexPosition[ 2032, 64]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[
RowBox[{"\[IndentingNewLine]",
RowBox[{
RowBox[{"Clear", "[", "\"\<`*\>\"", "]"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{"A", "=",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"3", ",", "2", ",",
RowBox[{"-", "1"}]}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{"-", "2"}], ",",
RowBox[{"-", "2"}], ",", "2"}], "}"}], ",", " ",
RowBox[{"{",
RowBox[{"3", ",", "6", ",",
RowBox[{"-", "1"}]}], "}"}]}], "}"}]}], ";"}], "\[IndentingNewLine]",
RowBox[{"MatrixForm", "[", "A", "]"}], "\n",
RowBox[{"eigenvalue", "=",
RowBox[{"MatrixForm", "[",
RowBox[{"Eigenvalues", "[", "A", "]"}], "]"}]}], "\n",
RowBox[{"eigenvector", "=",
RowBox[{"MatrixForm", "[",
RowBox[{"Eigenvectors", "[", "A", "]"}], "]"}]}]}]}]], "Input",
CellChangeTimes->{{3.8249089321894894`*^9, 3.8249090194456663`*^9}, {
3.8249090545199647`*^9, 3.824909158471919*^9}, {3.8249092372038407`*^9,
3.824909243121014*^9}},
CellLabel->"In[24]:=",ExpressionUUID->"54dc89aa-0cf7-4c91-9e21-ea7b96cf97e8"]
},
WindowSize->{1128, 568},
WindowMargins->{{Automatic, 375}, {Automatic, 189}},
Magnification:>1.2 Inherited,
FrontEndVersion->"12.0 for Microsoft Windows (64-bit) (2019\:5e744\:67088\
\:65e5)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)
(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[558, 20, 1125, 28, 238, "Input",ExpressionUUID->"54dc89aa-0cf7-4c91-9e21-ea7b96cf97e8"]
}
]
*)

View File

@@ -1,3 +1,3 @@
clc;clear all;
A = [3, 2, -1; -2, -2, 2; 3, 6, -1]
clc;clear all;
A = [3, 2, -1; -2, -2, 2; 3, 6, -1]
[V,D] = eig(A)

View File

@@ -1,40 +1,40 @@
program main
use lapack95
implicit none
integer i,j,info
complex*16 A(3,3), eigenvalues(3), eigenvectors(3,3)
A(1,1)=(3.d0, 0.d0)
A(1,2)=(2.d0, 0.d0)
A(1,3)=(-1.d0, 0.d0)
A(2,1)=(-2.d0, 0.d0)
A(2,2)=(-2.d0, 0.d0)
A(2,3)=(2.d0, 0.d0)
A(3,1)=(3.d0, 0.d0)
A(3,2)=(6.d0, 0.d0)
A(3,3)=(-1.d0, 0.d0)
write(*,*) 'matrix:'
do i=1,3
do j=1,3
write(*,"(f10.4, '+1i*',f7.4)",advance='no') A(i,j) !
enddo
write(*,*) ''
enddo
call geev(A=A, W=eigenvalues, VR=eigenvectors, INFO=info)
write(*,*) 'eigenvectors:'
do i=1,3
do j=1,3
write(*,"(f10.4, '+1i*',f7.4)",advance='no') eigenvectors(i,j) !
enddo
write(*,*) ''
enddo
write(*,*) 'eigenvalues:'
do i=1,3
write(*,"(f10.4, '+1i*',f7.4)",advance='no') eigenvalues(i)
enddo
write(*,*) ''
write(*,*) ''
program main
use lapack95
implicit none
integer i,j,info
complex*16 A(3,3), eigenvalues(3), eigenvectors(3,3)
A(1,1)=(3.d0, 0.d0)
A(1,2)=(2.d0, 0.d0)
A(1,3)=(-1.d0, 0.d0)
A(2,1)=(-2.d0, 0.d0)
A(2,2)=(-2.d0, 0.d0)
A(2,3)=(2.d0, 0.d0)
A(3,1)=(3.d0, 0.d0)
A(3,2)=(6.d0, 0.d0)
A(3,3)=(-1.d0, 0.d0)
write(*,*) 'matrix:'
do i=1,3
do j=1,3
write(*,"(f10.4, '+1i*',f7.4)",advance='no') A(i,j) !
enddo
write(*,*) ''
enddo
call geev(A=A, W=eigenvalues, VR=eigenvectors, INFO=info)
write(*,*) 'eigenvectors:'
do i=1,3
do j=1,3
write(*,"(f10.4, '+1i*',f7.4)",advance='no') eigenvectors(i,j) !
enddo
write(*,*) ''
enddo
write(*,*) 'eigenvalues:'
do i=1,3
write(*,"(f10.4, '+1i*',f7.4)",advance='no') eigenvalues(i)
enddo
write(*,*) ''
write(*,*) ''
end program

View File

@@ -1,21 +1,21 @@
import numpy as np
A = np.array([[3, 2+1j, -1], [2-1j, -2, 6], [-1, 6, 1]])
eigenvalue, eigenvector = np.linalg.eig(A)
print('矩阵:\n', A)
print('特征值:\n', eigenvalue)
print('特征向量:\n', eigenvector)
print('\n判断是否正交:\n', np.dot(eigenvector.transpose().conj(), eigenvector))
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose().conj()))
print('特征向量矩阵的列向量模方和:')
for i in range(3):
print(np.abs(eigenvector[0, i])**2+np.abs(eigenvector[1, i])**2+np.abs(eigenvector[2, i])**2)
print('特征向量矩阵的行向量模方和:')
for i in range(3):
print(np.abs(eigenvector[i, 0])**2+np.abs(eigenvector[i, 1])**2+np.abs(eigenvector[i, 2])**2)
print('\n对角化验证:')
print(np.dot(np.dot(eigenvector.transpose().conj(), A), eigenvector))
import numpy as np
A = np.array([[3, 2+1j, -1], [2-1j, -2, 6], [-1, 6, 1]])
eigenvalue, eigenvector = np.linalg.eig(A)
print('矩阵:\n', A)
print('特征值:\n', eigenvalue)
print('特征向量:\n', eigenvector)
print('\n判断是否正交:\n', np.dot(eigenvector.transpose().conj(), eigenvector))
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose().conj()))
print('特征向量矩阵的列向量模方和:')
for i in range(3):
print(np.abs(eigenvector[0, i])**2+np.abs(eigenvector[1, i])**2+np.abs(eigenvector[2, i])**2)
print('特征向量矩阵的行向量模方和:')
for i in range(3):
print(np.abs(eigenvector[i, 0])**2+np.abs(eigenvector[i, 1])**2+np.abs(eigenvector[i, 2])**2)
print('\n对角化验证:')
print(np.dot(np.dot(eigenvector.transpose().conj(), A), eigenvector))
print(np.dot(np.dot(eigenvector, A), eigenvector.transpose().conj()))

View File

@@ -1,18 +1,18 @@
import numpy as np
A = np.array([[3, 2, -1], [-2, -2, 2], [3, 6, -1]])
eigenvalue, eigenvector = np.linalg.eig(A)
print('矩阵:\n', A)
print('特征值:\n', eigenvalue)
print('特征向量:\n', eigenvector)
print('特征值为-4对应的特征向量理论值:\n', np.array([1/3, -2/3, 1])/np.sqrt((1/3)**2+(-2/3)**2+1**2))
print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
print('特征向量矩阵的列向量模方和:')
for i in range(3):
print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2)
print('特征向量矩阵的行向量模方和:')
for i in range(3):
import numpy as np
A = np.array([[3, 2, -1], [-2, -2, 2], [3, 6, -1]])
eigenvalue, eigenvector = np.linalg.eig(A)
print('矩阵:\n', A)
print('特征值:\n', eigenvalue)
print('特征向量:\n', eigenvector)
print('特征值为-4对应的特征向量理论值:\n', np.array([1/3, -2/3, 1])/np.sqrt((1/3)**2+(-2/3)**2+1**2))
print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
print('特征向量矩阵的列向量模方和:')
for i in range(3):
print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2)
print('特征向量矩阵的行向量模方和:')
for i in range(3):
print(eigenvector[i, 0]**2+eigenvector[i, 1]**2+eigenvector[i, 2]**2)

View File

@@ -1,21 +1,21 @@
import numpy as np
A = np.array([[3, 2, -1], [2, -2, 6], [-1, 6, 1]])
eigenvalue, eigenvector = np.linalg.eig(A)
print('矩阵:\n', A)
print('特征值:\n', eigenvalue)
print('特征向量:\n', eigenvector)
print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
print('特征向量矩阵的列向量模方和:')
for i in range(3):
print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2)
print('特征向量矩阵的行向量模方和:')
for i in range(3):
print(eigenvector[i, 0]**2+eigenvector[i, 1]**2+eigenvector[i, 2]**2)
print('\n对角化验证:')
print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector))
import numpy as np
A = np.array([[3, 2, -1], [2, -2, 6], [-1, 6, 1]])
eigenvalue, eigenvector = np.linalg.eig(A)
print('矩阵:\n', A)
print('特征值:\n', eigenvalue)
print('特征向量:\n', eigenvector)
print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
print('特征向量矩阵的列向量模方和:')
for i in range(3):
print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2)
print('特征向量矩阵的行向量模方和:')
for i in range(3):
print(eigenvector[i, 0]**2+eigenvector[i, 1]**2+eigenvector[i, 2]**2)
print('\n对角化验证:')
print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector))
print(np.dot(np.dot(eigenvector, A), eigenvector.transpose()))

View File

@@ -1,32 +1,32 @@
import numpy as np
A = np.array([[0, 1, 1, -1], [1, 0, -1, 1], [1, -1, 0, 1], [-1, 1, 1, 0]])
eigenvalue, eigenvector = np.linalg.eig(A)
print('矩阵:\n', A)
print('特征值:\n', eigenvalue)
print('特征向量:\n', eigenvector)
print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
print('特征向量矩阵的列向量模方和:')
for i in range(4):
print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2+eigenvector[3, i]**2)
print('特征向量矩阵的行向量模方和:')
for i in range(4):
print(eigenvector[i, 0]**2+eigenvector[i, 1]**2+eigenvector[i, 2]**2+eigenvector[i, 3]**2)
print('\n对角化验证:')
print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector))
print(np.dot(np.dot(eigenvector, A), eigenvector.transpose()))
print('\n特征向量理论值:')
T = np.array([[1/np.sqrt(2), 1/np.sqrt(6), -1/np.sqrt(12), 1/2], [1/np.sqrt(2), -1/np.sqrt(6), 1/np.sqrt(12), -1/2], [0, 2/np.sqrt(6), 1/np.sqrt(12), -1/2], [0, 0, 3/np.sqrt(12), 1/2]])
print(T)
print('\n判断是否正交:\n', np.dot(T.transpose(), T))
print('判断是否正交:\n', np.dot(T, T.transpose()))
print('\n对角化验证:')
print(np.dot(np.dot(T.transpose(), A), T))
import numpy as np
A = np.array([[0, 1, 1, -1], [1, 0, -1, 1], [1, -1, 0, 1], [-1, 1, 1, 0]])
eigenvalue, eigenvector = np.linalg.eig(A)
print('矩阵:\n', A)
print('特征值:\n', eigenvalue)
print('特征向量:\n', eigenvector)
print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
print('特征向量矩阵的列向量模方和:')
for i in range(4):
print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2+eigenvector[3, i]**2)
print('特征向量矩阵的行向量模方和:')
for i in range(4):
print(eigenvector[i, 0]**2+eigenvector[i, 1]**2+eigenvector[i, 2]**2+eigenvector[i, 3]**2)
print('\n对角化验证:')
print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector))
print(np.dot(np.dot(eigenvector, A), eigenvector.transpose()))
print('\n特征向量理论值:')
T = np.array([[1/np.sqrt(2), 1/np.sqrt(6), -1/np.sqrt(12), 1/2], [1/np.sqrt(2), -1/np.sqrt(6), 1/np.sqrt(12), -1/2], [0, 2/np.sqrt(6), 1/np.sqrt(12), -1/2], [0, 0, 3/np.sqrt(12), 1/2]])
print(T)
print('\n判断是否正交:\n', np.dot(T.transpose(), T))
print('判断是否正交:\n', np.dot(T, T.transpose()))
print('\n对角化验证:')
print(np.dot(np.dot(T.transpose(), A), T))
print(np.dot(np.dot(T, A), T.transpose()))

View File

@@ -1,44 +1,44 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10890
"""
import numpy as np
def main():
A = np.array([[0, 1, 1, -1], [1, 0, -1, 1], [1, -1, 0, 1], [-1, 1, 1, 0]])
eigenvalue, eigenvector = np.linalg.eig(A)
print('矩阵:\n', A)
print('特征值:\n', eigenvalue)
print('特征向量:\n', eigenvector)
print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
print('对角化验证:')
print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector))
# 施密斯正交化
eigenvector = Schmidt_orthogonalization(eigenvector)
print('\n施密斯正交化后,特征向量:\n', eigenvector)
print('施密斯正交化后,判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
print('施密斯正交化后,判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
print('施密斯正交化后,对角化验证:')
print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector))
def Schmidt_orthogonalization(eigenvector):
num = eigenvector.shape[1]
for i in range(num):
for i0 in range(i):
eigenvector[:, i] = eigenvector[:, i] - eigenvector[:, i0]*np.dot(eigenvector[:, i].transpose().conj(), eigenvector[:, i0])/(np.dot(eigenvector[:, i0].transpose().conj(),eigenvector[:, i0]))
eigenvector[:, i] = eigenvector[:, i]/np.linalg.norm(eigenvector[:, i])
return eigenvector
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10890
"""
import numpy as np
def main():
A = np.array([[0, 1, 1, -1], [1, 0, -1, 1], [1, -1, 0, 1], [-1, 1, 1, 0]])
eigenvalue, eigenvector = np.linalg.eig(A)
print('矩阵:\n', A)
print('特征值:\n', eigenvalue)
print('特征向量:\n', eigenvector)
print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
print('对角化验证:')
print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector))
# 施密斯正交化
eigenvector = Schmidt_orthogonalization(eigenvector)
print('\n施密斯正交化后,特征向量:\n', eigenvector)
print('施密斯正交化后,判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector))
print('施密斯正交化后,判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose()))
print('施密斯正交化后,对角化验证:')
print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector))
def Schmidt_orthogonalization(eigenvector):
num = eigenvector.shape[1]
for i in range(num):
for i0 in range(i):
eigenvector[:, i] = eigenvector[:, i] - eigenvector[:, i0]*np.dot(eigenvector[:, i].transpose().conj(), eigenvector[:, i0])/(np.dot(eigenvector[:, i0].transpose().conj(),eigenvector[:, i0]))
eigenvector[:, i] = eigenvector[:, i]/np.linalg.norm(eigenvector[:, i])
return eigenvector
if __name__ == '__main__':
main()

View File

@@ -1,101 +1,101 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/948
"""
import numpy as np
import matplotlib.pyplot as plt
import copy
import time
def matrix_00(width=10): # 不赋值时默认为10
h00 = np.zeros((width, width))
for width0 in range(width-1):
h00[width0, width0+1] = 1
h00[width0+1, width0] = 1
return h00
def matrix_01(width=10): # 不赋值时默认为10
h01 = np.identity(width)
return h01
def main():
start_time = time.time()
h00 = matrix_00(width=5)
h01 = matrix_01(width=5)
fermi_energy_array = np.arange(-4, 4, .01)
plot_conductance_energy(fermi_energy_array, h00, h01)
end_time = time.time()
print('运行时间=', end_time-start_time)
def plot_conductance_energy(fermi_energy_array, h00, h01): # 画电导与费米能关系图
dim = fermi_energy_array.shape[0]
cond = np.zeros(dim)
i0 = 0
for fermi_energy0 in fermi_energy_array:
cond0 = np.real(conductance(fermi_energy0 + 1e-12j, h00, h01))
cond[i0] = cond0
i0 += 1
plt.plot(fermi_energy_array, cond, '-k')
plt.show()
def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵T。dim是传递矩阵h00和h01的维度
transfer = np.zeros((2*dim, 2*dim), dtype=complex)
transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00) # np.dot()等效于np.matmul()
transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj())
transfer[dim:2*dim, 0:dim] = np.identity(dim)
transfer[dim:2*dim, dim:2*dim] = 0 # a:b代表 a <= x < b左闭右开
return transfer # 返回转移矩阵
def green_function_lead(fermi_energy, h00, h01, dim): # 电极的表面格林函数
transfer = transfer_matrix(fermi_energy, h00, h01, dim)
eigenvalue, eigenvector = np.linalg.eig(transfer)
ind = np.argsort(np.abs(eigenvalue))
temp = np.zeros((2*dim, 2*dim), dtype=complex)
i0 = 0
for ind0 in ind:
temp[:, i0] = eigenvector[:, ind0]
i0 += 1
s1 = temp[dim:2*dim, 0:dim]
s2 = temp[0:dim, 0:dim]
s3 = temp[dim:2*dim, dim:2*dim]
s4 = temp[0:dim, dim:2*dim]
right_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01, s2), np.linalg.inv(s1)))
left_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), s3), np.linalg.inv(s4)))
return right_lead_surface, left_lead_surface # 返回右电极的表面格林函数和左电极的表面格林函数
def self_energy_lead(fermi_energy, h00, h01, dim): # 电极的自能
right_lead_surface, left_lead_surface = green_function_lead(fermi_energy, h00, h01, dim)
right_self_energy = np.dot(np.dot(h01, right_lead_surface), h01.transpose().conj())
left_self_energy = np.dot(np.dot(h01.transpose().conj(), left_lead_surface), h01)
return right_self_energy, left_self_energy # 返回右边电极自能和左边电极自能
def conductance(fermi_energy, h00, h01, nx=300): # 计算电导
dim = h00.shape[0]
right_self_energy, left_self_energy = self_energy_lead(fermi_energy, h00, h01, dim)
for ix in range(nx):
if ix == 0:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-left_self_energy)
green_0n_n = copy.deepcopy(green_nn_n) # 如果直接用等于两个变量会指向相同的id改变一个值另外一个值可能会发生改变容易出错所以要用上这个COPY
elif ix != nx-1:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
else:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)-right_self_energy)
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
gamma_right = (right_self_energy - right_self_energy.transpose().conj())*(0+1j)
gamma_left = (left_self_energy - left_self_energy.transpose().conj())*(0+1j)
transmission = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
return transmission # 返回电导值
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/948
"""
import numpy as np
import matplotlib.pyplot as plt
import copy
import time
def matrix_00(width=10): # 不赋值时默认为10
h00 = np.zeros((width, width))
for width0 in range(width-1):
h00[width0, width0+1] = 1
h00[width0+1, width0] = 1
return h00
def matrix_01(width=10): # 不赋值时默认为10
h01 = np.identity(width)
return h01
def main():
start_time = time.time()
h00 = matrix_00(width=5)
h01 = matrix_01(width=5)
fermi_energy_array = np.arange(-4, 4, .01)
plot_conductance_energy(fermi_energy_array, h00, h01)
end_time = time.time()
print('运行时间=', end_time-start_time)
def plot_conductance_energy(fermi_energy_array, h00, h01): # 画电导与费米能关系图
dim = fermi_energy_array.shape[0]
cond = np.zeros(dim)
i0 = 0
for fermi_energy0 in fermi_energy_array:
cond0 = np.real(conductance(fermi_energy0 + 1e-12j, h00, h01))
cond[i0] = cond0
i0 += 1
plt.plot(fermi_energy_array, cond, '-k')
plt.show()
def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵T。dim是传递矩阵h00和h01的维度
transfer = np.zeros((2*dim, 2*dim), dtype=complex)
transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00) # np.dot()等效于np.matmul()
transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj())
transfer[dim:2*dim, 0:dim] = np.identity(dim)
transfer[dim:2*dim, dim:2*dim] = 0 # a:b代表 a <= x < b左闭右开
return transfer # 返回转移矩阵
def green_function_lead(fermi_energy, h00, h01, dim): # 电极的表面格林函数
transfer = transfer_matrix(fermi_energy, h00, h01, dim)
eigenvalue, eigenvector = np.linalg.eig(transfer)
ind = np.argsort(np.abs(eigenvalue))
temp = np.zeros((2*dim, 2*dim), dtype=complex)
i0 = 0
for ind0 in ind:
temp[:, i0] = eigenvector[:, ind0]
i0 += 1
s1 = temp[dim:2*dim, 0:dim]
s2 = temp[0:dim, 0:dim]
s3 = temp[dim:2*dim, dim:2*dim]
s4 = temp[0:dim, dim:2*dim]
right_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01, s2), np.linalg.inv(s1)))
left_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), s3), np.linalg.inv(s4)))
return right_lead_surface, left_lead_surface # 返回右电极的表面格林函数和左电极的表面格林函数
def self_energy_lead(fermi_energy, h00, h01, dim): # 电极的自能
right_lead_surface, left_lead_surface = green_function_lead(fermi_energy, h00, h01, dim)
right_self_energy = np.dot(np.dot(h01, right_lead_surface), h01.transpose().conj())
left_self_energy = np.dot(np.dot(h01.transpose().conj(), left_lead_surface), h01)
return right_self_energy, left_self_energy # 返回右边电极自能和左边电极自能
def conductance(fermi_energy, h00, h01, nx=300): # 计算电导
dim = h00.shape[0]
right_self_energy, left_self_energy = self_energy_lead(fermi_energy, h00, h01, dim)
for ix in range(nx):
if ix == 0:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-left_self_energy)
green_0n_n = copy.deepcopy(green_nn_n) # 如果直接用等于两个变量会指向相同的id改变一个值另外一个值可能会发生改变容易出错所以要用上这个COPY
elif ix != nx-1:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
else:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)-right_self_energy)
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
gamma_right = (right_self_energy - right_self_energy.transpose().conj())*(0+1j)
gamma_left = (left_self_energy - left_self_energy.transpose().conj())*(0+1j)
transmission = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
return transmission # 返回电导值
if __name__ == '__main__':
main()

View File

@@ -1,56 +1,56 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/2033
"""
import kwant
import matplotlib.pyplot as plt
def main():
L = 3
W = 2
lat = kwant.lattice.square(a=1, norbs=1) # 定义lattice
print('\nlat:\n', lat)
syst = kwant.Builder() # 定义中心区的Builder
print('\nsyst:\n', syst)
syst_finalized = syst.finalized()
hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量
print('\nhamiltonian_1定义:\n', hamiltonian)
syst[(lat(x, y) for x in range(L) for y in range(W))] = 0 # 晶格初始化为0
kwant.plot(syst) # 画出syst的示意图
syst_finalized = syst.finalized()
hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量
print('\nhamiltonian_2初始化:\n', hamiltonian)
syst[lat.neighbors()] = 1 # 添加最近邻跃迁
kwant.plot(syst) # 画出syst的示意图
syst_finalized = syst.finalized()
hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量
print('\nhamiltonian_3最近邻赋值:\n', hamiltonian)
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0))) # 定义电极的Builder
lead[(lat(0, j) for j in range(W))] = 0 # 电极晶格初始化
lead[lat.neighbors()] = 1 # 添加最近邻跃迁
syst.attach_lead(lead) # 中心区加上左电极
syst.attach_lead(lead.reversed()) # 用reversed()方法得到右电极
# 画出syst的示意图
kwant.plot(syst)
# 查看哈密顿量加了电极后并不影响syst哈密顿量
syst_finalized = syst.finalized()
hamiltonian = syst_finalized.hamiltonian_submatrix()
print('\nhamiltonian_4加了电极后:\n', hamiltonian)
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/2033
"""
import kwant
import matplotlib.pyplot as plt
def main():
L = 3
W = 2
lat = kwant.lattice.square(a=1, norbs=1) # 定义lattice
print('\nlat:\n', lat)
syst = kwant.Builder() # 定义中心区的Builder
print('\nsyst:\n', syst)
syst_finalized = syst.finalized()
hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量
print('\nhamiltonian_1定义:\n', hamiltonian)
syst[(lat(x, y) for x in range(L) for y in range(W))] = 0 # 晶格初始化为0
kwant.plot(syst) # 画出syst的示意图
syst_finalized = syst.finalized()
hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量
print('\nhamiltonian_2初始化:\n', hamiltonian)
syst[lat.neighbors()] = 1 # 添加最近邻跃迁
kwant.plot(syst) # 画出syst的示意图
syst_finalized = syst.finalized()
hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量
print('\nhamiltonian_3最近邻赋值:\n', hamiltonian)
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0))) # 定义电极的Builder
lead[(lat(0, j) for j in range(W))] = 0 # 电极晶格初始化
lead[lat.neighbors()] = 1 # 添加最近邻跃迁
syst.attach_lead(lead) # 中心区加上左电极
syst.attach_lead(lead.reversed()) # 用reversed()方法得到右电极
# 画出syst的示意图
kwant.plot(syst)
# 查看哈密顿量加了电极后并不影响syst哈密顿量
syst_finalized = syst.finalized()
hamiltonian = syst_finalized.hamiltonian_submatrix()
print('\nhamiltonian_4加了电极后:\n', hamiltonian)
if __name__ == '__main__':
main()

View File

@@ -1,94 +1,94 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/2033
"""
import kwant
import numpy as np
from matplotlib import pyplot
def make_system():
a = 1 # 晶格常数
lat = kwant.lattice.square(a) # 创建晶格,方格子
syst = kwant.Builder() # 建立中心体系
t = 1.0 # hopping值
W = 5 # 中心体系宽度
L = 40 # 中心体系长度
# 给中心体系赋值
for i in range(L):
for j in range(W):
syst[lat(i, j)] = 0
if j > 0:
syst[lat(i, j), lat(i, j-1)] = -t # hopping in y-direction
if i > 0:
syst[lat(i, j), lat(i-1, j)] = -t # hopping in x-direction
sym_left_lead = kwant.TranslationalSymmetry((-a, 0)) # 电极的平移对称性,(-a, 0)代表远离中心区的方向,向左
left_lead = kwant.Builder(sym_left_lead) # 建立左电极体系
# 给电极体系赋值
for j in range(W):
left_lead[lat(0, j)] = 0
if j > 0:
left_lead[lat(0, j), lat(0, j - 1)] = -t
left_lead[lat(1, j), lat(0, j)] = -t # 这里写一个即可,因为平移对称性已经声明了
syst.attach_lead(left_lead) # 把左电极接在中心区
sym_right_lead = kwant.TranslationalSymmetry((a, 0))
right_lead = kwant.Builder(sym_right_lead)
for j in range(W):
right_lead[lat(0, j)] = 0
if j > 0:
right_lead[lat(0, j), lat(0, j - 1)] = -t
right_lead[lat(1, j), lat(0, j)] = -t
syst.attach_lead(right_lead) # 把右电极接在中心区
kwant.plot(syst) # 把电极-中心区-电极图画出来,通过图像可以看出有没有写错
syst = syst.finalized() # 结束体系的制作。这个语句不可以省。这个语句是把Builder对象转换成可计算的对象。
return syst
def make_system_with_less_code():
a = 1 # 晶格常数
lat = kwant.lattice.square(a) # 创建晶格,方格子
syst = kwant.Builder() # 建立中心体系
t = 1.0 # hopping值
W = 5 # 中心体系宽度
L = 40 # 中心体系长度
# 中心区
syst[(lat(x, y) for x in range(L) for y in range(W))] = 0
syst[lat.neighbors()] = -t # 用neighbors()方法
# 电极
lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0)))
lead[(lat(0, j) for j in range(W))] = 0
lead[lat.neighbors()] = -t # 用neighbors()方法
syst.attach_lead(lead) # 左电极
syst.attach_lead(lead.reversed()) # 用reversed()方法得到右电极
kwant.plot(syst) # 把电极-中心区-电极图画出来,通过图像可以看出有没有写错
syst = syst.finalized() # 结束体系的制作。这个语句不可以省。这个语句是把Builder对象转换成可计算的对象。
return syst
def main():
syst = make_system()
# syst = make_system_with_less_code() # 和上面的一样,只是用更少的代码写
energies = np.linspace(-4, 4, 200)
data = []
for energy in energies:
smatrix = kwant.smatrix(syst, energy) # compute the transmission probability from lead 0 to lead 1
data.append(smatrix.transmission(1, 0))
pyplot.plot(energies, data)
pyplot.xlabel("energy [t]")
pyplot.ylabel("conductance [e^2/h]")
pyplot.show()
# pyplot.savefig('conductance' + '.eps')
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/2033
"""
import kwant
import numpy as np
from matplotlib import pyplot
def make_system():
a = 1 # 晶格常数
lat = kwant.lattice.square(a) # 创建晶格,方格子
syst = kwant.Builder() # 建立中心体系
t = 1.0 # hopping值
W = 5 # 中心体系宽度
L = 40 # 中心体系长度
# 给中心体系赋值
for i in range(L):
for j in range(W):
syst[lat(i, j)] = 0
if j > 0:
syst[lat(i, j), lat(i, j-1)] = -t # hopping in y-direction
if i > 0:
syst[lat(i, j), lat(i-1, j)] = -t # hopping in x-direction
sym_left_lead = kwant.TranslationalSymmetry((-a, 0)) # 电极的平移对称性,(-a, 0)代表远离中心区的方向,向左
left_lead = kwant.Builder(sym_left_lead) # 建立左电极体系
# 给电极体系赋值
for j in range(W):
left_lead[lat(0, j)] = 0
if j > 0:
left_lead[lat(0, j), lat(0, j - 1)] = -t
left_lead[lat(1, j), lat(0, j)] = -t # 这里写一个即可,因为平移对称性已经声明了
syst.attach_lead(left_lead) # 把左电极接在中心区
sym_right_lead = kwant.TranslationalSymmetry((a, 0))
right_lead = kwant.Builder(sym_right_lead)
for j in range(W):
right_lead[lat(0, j)] = 0
if j > 0:
right_lead[lat(0, j), lat(0, j - 1)] = -t
right_lead[lat(1, j), lat(0, j)] = -t
syst.attach_lead(right_lead) # 把右电极接在中心区
kwant.plot(syst) # 把电极-中心区-电极图画出来,通过图像可以看出有没有写错
syst = syst.finalized() # 结束体系的制作。这个语句不可以省。这个语句是把Builder对象转换成可计算的对象。
return syst
def make_system_with_less_code():
a = 1 # 晶格常数
lat = kwant.lattice.square(a) # 创建晶格,方格子
syst = kwant.Builder() # 建立中心体系
t = 1.0 # hopping值
W = 5 # 中心体系宽度
L = 40 # 中心体系长度
# 中心区
syst[(lat(x, y) for x in range(L) for y in range(W))] = 0
syst[lat.neighbors()] = -t # 用neighbors()方法
# 电极
lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0)))
lead[(lat(0, j) for j in range(W))] = 0
lead[lat.neighbors()] = -t # 用neighbors()方法
syst.attach_lead(lead) # 左电极
syst.attach_lead(lead.reversed()) # 用reversed()方法得到右电极
kwant.plot(syst) # 把电极-中心区-电极图画出来,通过图像可以看出有没有写错
syst = syst.finalized() # 结束体系的制作。这个语句不可以省。这个语句是把Builder对象转换成可计算的对象。
return syst
def main():
syst = make_system()
# syst = make_system_with_less_code() # 和上面的一样,只是用更少的代码写
energies = np.linspace(-4, 4, 200)
data = []
for energy in energies:
smatrix = kwant.smatrix(syst, energy) # compute the transmission probability from lead 0 to lead 1
data.append(smatrix.transmission(1, 0))
pyplot.plot(energies, data)
pyplot.xlabel("energy [t]")
pyplot.ylabel("conductance [e^2/h]")
pyplot.show()
# pyplot.savefig('conductance' + '.eps')
if __name__ == '__main__':
main()

View File

@@ -1,240 +1,240 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6352
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import copy
import time
# import os
# os.chdir('D:/data')
def main():
start_time = time.time()
h00 = matrix_00() # 方格子模型
h01 = matrix_01() # 方格子模型
fermi_energy = 0.1
write_transmission_matrix(fermi_energy, h00, h01) # 输出无散射的散射矩阵
end_time = time.time()
print('运行时间=', end_time - start_time, '')
def matrix_00(width=4):
h00 = np.zeros((width, width))
for width0 in range(width-1):
h00[width0, width0+1] = 1
h00[width0+1, width0] = 1
return h00
def matrix_01(width=4):
h01 = np.identity(width)
return h01
def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵
transfer = np.zeros((2*dim, 2*dim))*(0+0j)
transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00)
transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj())
transfer[dim:2*dim, 0:dim] = np.identity(dim)
transfer[dim:2*dim, dim:2*dim] = 0
return transfer
def complex_wave_vector(fermi_energy, h00, h01, dim): # 获取通道的复数波矢并按照波矢的实部Re(k)排序
transfer = transfer_matrix(fermi_energy, h00, h01, dim)
eigenvalue, eigenvector = np.linalg.eig(transfer)
k_channel = np.log(eigenvalue)/1j
ind = np.argsort(np.real(k_channel))
k_channel = np.sort(k_channel)
temp = np.zeros((2*dim, 2*dim))*(1+0j)
temp2 = np.zeros((2*dim))*(1+0j)
i0 = 0
for ind0 in ind:
temp[:, i0] = eigenvector[:, ind0]
temp2[i0] = eigenvalue[ind0]
i0 += 1
eigenvalue = copy.deepcopy(temp2)
temp = normalization_of_eigenvector(temp[0:dim, :], dim)
velocity = np.zeros((2*dim))*(1+0j)
for dim0 in range(2*dim):
velocity[dim0] = eigenvalue[dim0]*np.dot(np.dot(temp[0:dim, :].transpose().conj(), h01),temp[0:dim, :])[dim0, dim0]
velocity = -2*np.imag(velocity)
eigenvector = copy.deepcopy(temp)
return k_channel, velocity, eigenvalue, eigenvector # 返回通道的对应的波矢、费米速度、本征值、本征态
def normalization_of_eigenvector(eigenvector, dim): # 波函数归一化
factor = np.zeros(2*dim)*(1+0j)
for dim0 in range(dim):
factor = factor+np.square(np.abs(eigenvector[dim0, :]))
for dim0 in range(2*dim):
eigenvector[:, dim0] = eigenvector[:, dim0]/np.sqrt(factor[dim0])
return eigenvector
def calculation_of_lambda_u_f(fermi_energy, h00, h01, dim): # 对所有通道包括active和evanescent进行分类并计算F
k_channel, velocity, eigenvalue, eigenvector = complex_wave_vector(fermi_energy, h00, h01, dim)
ind_right_active = 0; ind_right_evanescent = 0; ind_left_active = 0; ind_left_evanescent = 0
k_right = np.zeros(dim)*(1+0j); k_left = np.zeros(dim)*(1+0j)
velocity_right = np.zeros(dim)*(1+0j); velocity_left = np.zeros(dim)*(1+0j)
lambda_right = np.zeros(dim)*(1+0j); lambda_left = np.zeros(dim)*(1+0j)
u_right = np.zeros((dim, dim))*(1+0j); u_left = np.zeros((dim, dim))*(1+0j)
for dim0 in range(2*dim):
if_active = if_active_channel(k_channel[dim0])
direction = direction_of_channel(velocity[dim0], k_channel[dim0])
if direction == 1: # 向右运动的通道
if if_active == 1: # 可传播通道active channel
k_right[ind_right_active] = k_channel[dim0]
velocity_right[ind_right_active] = velocity[dim0]
lambda_right[ind_right_active] = eigenvalue[dim0]
u_right[:, ind_right_active] = eigenvector[:, dim0]
ind_right_active += 1
else: # 衰减通道evanescent channel
k_right[dim-1-ind_right_evanescent] = k_channel[dim0]
velocity_right[dim-1-ind_right_evanescent] = velocity[dim0]
lambda_right[dim-1-ind_right_evanescent] = eigenvalue[dim0]
u_right[:, dim-1-ind_right_evanescent] = eigenvector[:, dim0]
ind_right_evanescent += 1
else: # 向左运动的通道
if if_active == 1: # 可传播通道active channel
k_left[ind_left_active] = k_channel[dim0]
velocity_left[ind_left_active] = velocity[dim0]
lambda_left[ind_left_active] = eigenvalue[dim0]
u_left[:, ind_left_active] = eigenvector[:, dim0]
ind_left_active += 1
else: # 衰减通道evanescent channel
k_left[dim-1-ind_left_evanescent] = k_channel[dim0]
velocity_left[dim-1-ind_left_evanescent] = velocity[dim0]
lambda_left[dim-1-ind_left_evanescent] = eigenvalue[dim0]
u_left[:, dim-1-ind_left_evanescent] = eigenvector[:, dim0]
ind_left_evanescent += 1
lambda_matrix_right = np.diag(lambda_right)
lambda_matrix_left = np.diag(lambda_left)
f_right = np.dot(np.dot(u_right, lambda_matrix_right), np.linalg.inv(u_right))
f_left = np.dot(np.dot(u_left, lambda_matrix_left), np.linalg.inv(u_left))
return k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active
# 分别返回向右和向左的运动的波矢k、费米速度velocity、F值、U值、可向右传播的通道数
def if_active_channel(k_channel): # 判断是可传播通道还是衰减通道
if np.abs(np.imag(k_channel)) < 1e-7:
if_active = 1
else:
if_active = 0
return if_active
def direction_of_channel(velocity, k_channel): # 判断通道对应的费米速度方向
if if_active_channel(k_channel) == 1:
direction = np.sign(velocity)
else:
direction = np.sign(np.imag(k_channel))
return direction
def calculation_of_green_function(fermi_energy, h00, h01, dim, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 计算格林函数
k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active = calculation_of_lambda_u_f(fermi_energy, h00, h01, dim)
right_self_energy = np.dot(h01, f_right)
left_self_energy = np.dot(h01.transpose().conj(), np.linalg.inv(f_left))
nx = 300
for nx0 in range(nx):
if nx0 == 0:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-left_self_energy)
green_00_n = copy.deepcopy(green_nn_n)
green_0n_n = copy.deepcopy(green_nn_n)
green_n0_n = copy.deepcopy(green_nn_n)
elif nx0 != nx-1:
if scatter_type == 0: # 无散射
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
elif scatter_type == 1: # 势垒散射
h00_scatter = h00 + scatter_intensity * np.identity(dim)
if int(nx/2)-int(scatter_length/2) <= nx0 < int(nx/2)+int((scatter_length+1)/2):
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00_scatter - np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
else:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
else:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-right_self_energy-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
green_00_n = green_00_n+np.dot(np.dot(np.dot(np.dot(green_0n_n, h01), green_nn_n), h01.transpose().conj()), green_n0_n)
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
green_n0_n = np.dot(np.dot(green_nn_n, h01.transpose().conj()), green_n0_n)
return green_00_n, green_n0_n, k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active
def transmission_with_detailed_modes(fermi_energy, h00, h01, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 计算散射矩阵
dim = h00.shape[0]
green_00_n, green_n0_n, k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active = calculation_of_green_function(fermi_energy, h00, h01, dim, scatter_type, scatter_intensity, scatter_length)
temp = np.dot(h01.transpose().conj(), np.linalg.inv(f_right)-np.linalg.inv(f_left))
transmission_matrix = np.dot(np.dot(np.linalg.inv(u_right), np.dot(green_n0_n, temp)), u_right)
reflection_matrix = np.dot(np.dot(np.linalg.inv(u_left), np.dot(green_00_n, temp)-np.identity(dim)), u_right)
for dim0 in range(dim):
for dim1 in range(dim):
if_active = if_active_channel(k_right[dim0])*if_active_channel(k_right[dim1])
if if_active == 1:
transmission_matrix[dim0, dim1] = np.sqrt(np.abs(velocity_right[dim0]/velocity_right[dim1])) * transmission_matrix[dim0, dim1]
reflection_matrix[dim0, dim1] = np.sqrt(np.abs(velocity_left[dim0] / velocity_right[dim1]))*reflection_matrix[dim0, dim1]
else:
transmission_matrix[dim0, dim1] = 0
reflection_matrix[dim0, dim1] = 0
sum_of_tran_refl_array = np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)+np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)
for sum_of_tran_refl in sum_of_tran_refl_array:
if sum_of_tran_refl > 1.001:
print('错误警告:散射矩阵的计算结果不归一! Error Alert: scattering matrix is not normalized!')
return transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active
def write_transmission_matrix(fermi_energy, h00, h01, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 输出
transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active, \
= transmission_with_detailed_modes(fermi_energy, h00, h01, scatter_type, scatter_intensity, scatter_length)
dim = h00.shape[0]
np.set_printoptions(suppress=True) # 取消科学计数法输出
print('\n可传播的通道数向右active_channel (right) = ', ind_right_active)
print('衰减的通道数(向右) evanescent_channel (right) = ', dim-ind_right_active, '\n')
print('向右可传播的通道数对应的波矢 k_right:\n', np.real(k_right[0:ind_right_active]))
print('向左可传播的通道数对应的波矢 k_left:\n', np.real(k_left[0:ind_right_active]), '\n')
print('向右可传播的通道数对应的费米速度 velocity_right:\n', np.real(velocity_right[0:ind_right_active]))
print('向左可传播的通道数对应的费米速度 velocity_left:\n', np.real(velocity_left[0:ind_right_active]), '\n')
print('透射矩阵 transmission_matrix:\n', np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])))
print('反射矩阵 reflection_matrix:\n', np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), '\n')
print('透射矩阵列求和 total transmission of channels =\n', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))
print('反射矩阵列求和 total reflection of channels =\n',np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))
print('透射以及反射矩阵列求和 sum of transmission and reflection of channels =\n', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0) + np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))
print('总电导 total conductance = ', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active]))), '\n')
# 下面把以上信息写入文件中
with open('a.txt', 'w') as f:
f.write('Active_channel (right or left) = ' + str(ind_right_active) + '\n')
f.write('Evanescent_channel (right or left) = ' + str(dim - ind_right_active) + '\n\n')
f.write('Channel K Velocity\n')
for ind0 in range(ind_right_active):
f.write(' '+str(ind0 + 1) + ' | '+str(np.real(k_right[ind0]))+' ' + str(np.real(velocity_right[ind0]))+'\n')
f.write('\n')
for ind0 in range(ind_right_active):
f.write(' -' + str(ind0 + 1) + ' | ' + str(np.real(k_left[ind0])) + ' ' + str(np.real(velocity_left[ind0])) + '\n')
f.write('\n\nScattering_matrix:\n ')
for ind0 in range(ind_right_active):
f.write(str(ind0+1)+' ')
f.write('\n')
for ind1 in range(ind_right_active):
f.write(' '+str(ind1+1)+' ')
for ind2 in range(ind_right_active):
f.write('%f' % np.square(np.abs(transmission_matrix[ind1, ind2]))+' ')
f.write('\n')
f.write('\n')
for ind1 in range(ind_right_active):
f.write(' -'+str(ind1+1)+' ')
for ind2 in range(ind_right_active):
f.write('%f' % np.square(np.abs(reflection_matrix[ind1, ind2]))+' ')
f.write('\n')
f.write('\n')
f.write('Total transmission of channels:\n'+str(np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))+'\n')
f.write('Total conductance = '+str(np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active]))))+'\n')
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6352
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import copy
import time
# import os
# os.chdir('D:/data')
def main():
start_time = time.time()
h00 = matrix_00() # 方格子模型
h01 = matrix_01() # 方格子模型
fermi_energy = 0.1
write_transmission_matrix(fermi_energy, h00, h01) # 输出无散射的散射矩阵
end_time = time.time()
print('运行时间=', end_time - start_time, '')
def matrix_00(width=4):
h00 = np.zeros((width, width))
for width0 in range(width-1):
h00[width0, width0+1] = 1
h00[width0+1, width0] = 1
return h00
def matrix_01(width=4):
h01 = np.identity(width)
return h01
def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵
transfer = np.zeros((2*dim, 2*dim))*(0+0j)
transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00)
transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj())
transfer[dim:2*dim, 0:dim] = np.identity(dim)
transfer[dim:2*dim, dim:2*dim] = 0
return transfer
def complex_wave_vector(fermi_energy, h00, h01, dim): # 获取通道的复数波矢并按照波矢的实部Re(k)排序
transfer = transfer_matrix(fermi_energy, h00, h01, dim)
eigenvalue, eigenvector = np.linalg.eig(transfer)
k_channel = np.log(eigenvalue)/1j
ind = np.argsort(np.real(k_channel))
k_channel = np.sort(k_channel)
temp = np.zeros((2*dim, 2*dim))*(1+0j)
temp2 = np.zeros((2*dim))*(1+0j)
i0 = 0
for ind0 in ind:
temp[:, i0] = eigenvector[:, ind0]
temp2[i0] = eigenvalue[ind0]
i0 += 1
eigenvalue = copy.deepcopy(temp2)
temp = normalization_of_eigenvector(temp[0:dim, :], dim)
velocity = np.zeros((2*dim))*(1+0j)
for dim0 in range(2*dim):
velocity[dim0] = eigenvalue[dim0]*np.dot(np.dot(temp[0:dim, :].transpose().conj(), h01),temp[0:dim, :])[dim0, dim0]
velocity = -2*np.imag(velocity)
eigenvector = copy.deepcopy(temp)
return k_channel, velocity, eigenvalue, eigenvector # 返回通道的对应的波矢、费米速度、本征值、本征态
def normalization_of_eigenvector(eigenvector, dim): # 波函数归一化
factor = np.zeros(2*dim)*(1+0j)
for dim0 in range(dim):
factor = factor+np.square(np.abs(eigenvector[dim0, :]))
for dim0 in range(2*dim):
eigenvector[:, dim0] = eigenvector[:, dim0]/np.sqrt(factor[dim0])
return eigenvector
def calculation_of_lambda_u_f(fermi_energy, h00, h01, dim): # 对所有通道包括active和evanescent进行分类并计算F
k_channel, velocity, eigenvalue, eigenvector = complex_wave_vector(fermi_energy, h00, h01, dim)
ind_right_active = 0; ind_right_evanescent = 0; ind_left_active = 0; ind_left_evanescent = 0
k_right = np.zeros(dim)*(1+0j); k_left = np.zeros(dim)*(1+0j)
velocity_right = np.zeros(dim)*(1+0j); velocity_left = np.zeros(dim)*(1+0j)
lambda_right = np.zeros(dim)*(1+0j); lambda_left = np.zeros(dim)*(1+0j)
u_right = np.zeros((dim, dim))*(1+0j); u_left = np.zeros((dim, dim))*(1+0j)
for dim0 in range(2*dim):
if_active = if_active_channel(k_channel[dim0])
direction = direction_of_channel(velocity[dim0], k_channel[dim0])
if direction == 1: # 向右运动的通道
if if_active == 1: # 可传播通道active channel
k_right[ind_right_active] = k_channel[dim0]
velocity_right[ind_right_active] = velocity[dim0]
lambda_right[ind_right_active] = eigenvalue[dim0]
u_right[:, ind_right_active] = eigenvector[:, dim0]
ind_right_active += 1
else: # 衰减通道evanescent channel
k_right[dim-1-ind_right_evanescent] = k_channel[dim0]
velocity_right[dim-1-ind_right_evanescent] = velocity[dim0]
lambda_right[dim-1-ind_right_evanescent] = eigenvalue[dim0]
u_right[:, dim-1-ind_right_evanescent] = eigenvector[:, dim0]
ind_right_evanescent += 1
else: # 向左运动的通道
if if_active == 1: # 可传播通道active channel
k_left[ind_left_active] = k_channel[dim0]
velocity_left[ind_left_active] = velocity[dim0]
lambda_left[ind_left_active] = eigenvalue[dim0]
u_left[:, ind_left_active] = eigenvector[:, dim0]
ind_left_active += 1
else: # 衰减通道evanescent channel
k_left[dim-1-ind_left_evanescent] = k_channel[dim0]
velocity_left[dim-1-ind_left_evanescent] = velocity[dim0]
lambda_left[dim-1-ind_left_evanescent] = eigenvalue[dim0]
u_left[:, dim-1-ind_left_evanescent] = eigenvector[:, dim0]
ind_left_evanescent += 1
lambda_matrix_right = np.diag(lambda_right)
lambda_matrix_left = np.diag(lambda_left)
f_right = np.dot(np.dot(u_right, lambda_matrix_right), np.linalg.inv(u_right))
f_left = np.dot(np.dot(u_left, lambda_matrix_left), np.linalg.inv(u_left))
return k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active
# 分别返回向右和向左的运动的波矢k、费米速度velocity、F值、U值、可向右传播的通道数
def if_active_channel(k_channel): # 判断是可传播通道还是衰减通道
if np.abs(np.imag(k_channel)) < 1e-7:
if_active = 1
else:
if_active = 0
return if_active
def direction_of_channel(velocity, k_channel): # 判断通道对应的费米速度方向
if if_active_channel(k_channel) == 1:
direction = np.sign(velocity)
else:
direction = np.sign(np.imag(k_channel))
return direction
def calculation_of_green_function(fermi_energy, h00, h01, dim, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 计算格林函数
k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active = calculation_of_lambda_u_f(fermi_energy, h00, h01, dim)
right_self_energy = np.dot(h01, f_right)
left_self_energy = np.dot(h01.transpose().conj(), np.linalg.inv(f_left))
nx = 300
for nx0 in range(nx):
if nx0 == 0:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-left_self_energy)
green_00_n = copy.deepcopy(green_nn_n)
green_0n_n = copy.deepcopy(green_nn_n)
green_n0_n = copy.deepcopy(green_nn_n)
elif nx0 != nx-1:
if scatter_type == 0: # 无散射
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
elif scatter_type == 1: # 势垒散射
h00_scatter = h00 + scatter_intensity * np.identity(dim)
if int(nx/2)-int(scatter_length/2) <= nx0 < int(nx/2)+int((scatter_length+1)/2):
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00_scatter - np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
else:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
else:
green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-right_self_energy-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01))
green_00_n = green_00_n+np.dot(np.dot(np.dot(np.dot(green_0n_n, h01), green_nn_n), h01.transpose().conj()), green_n0_n)
green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n)
green_n0_n = np.dot(np.dot(green_nn_n, h01.transpose().conj()), green_n0_n)
return green_00_n, green_n0_n, k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active
def transmission_with_detailed_modes(fermi_energy, h00, h01, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 计算散射矩阵
dim = h00.shape[0]
green_00_n, green_n0_n, k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active = calculation_of_green_function(fermi_energy, h00, h01, dim, scatter_type, scatter_intensity, scatter_length)
temp = np.dot(h01.transpose().conj(), np.linalg.inv(f_right)-np.linalg.inv(f_left))
transmission_matrix = np.dot(np.dot(np.linalg.inv(u_right), np.dot(green_n0_n, temp)), u_right)
reflection_matrix = np.dot(np.dot(np.linalg.inv(u_left), np.dot(green_00_n, temp)-np.identity(dim)), u_right)
for dim0 in range(dim):
for dim1 in range(dim):
if_active = if_active_channel(k_right[dim0])*if_active_channel(k_right[dim1])
if if_active == 1:
transmission_matrix[dim0, dim1] = np.sqrt(np.abs(velocity_right[dim0]/velocity_right[dim1])) * transmission_matrix[dim0, dim1]
reflection_matrix[dim0, dim1] = np.sqrt(np.abs(velocity_left[dim0] / velocity_right[dim1]))*reflection_matrix[dim0, dim1]
else:
transmission_matrix[dim0, dim1] = 0
reflection_matrix[dim0, dim1] = 0
sum_of_tran_refl_array = np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)+np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)
for sum_of_tran_refl in sum_of_tran_refl_array:
if sum_of_tran_refl > 1.001:
print('错误警告:散射矩阵的计算结果不归一! Error Alert: scattering matrix is not normalized!')
return transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active
def write_transmission_matrix(fermi_energy, h00, h01, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 输出
transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active, \
= transmission_with_detailed_modes(fermi_energy, h00, h01, scatter_type, scatter_intensity, scatter_length)
dim = h00.shape[0]
np.set_printoptions(suppress=True) # 取消科学计数法输出
print('\n可传播的通道数向右active_channel (right) = ', ind_right_active)
print('衰减的通道数(向右) evanescent_channel (right) = ', dim-ind_right_active, '\n')
print('向右可传播的通道数对应的波矢 k_right:\n', np.real(k_right[0:ind_right_active]))
print('向左可传播的通道数对应的波矢 k_left:\n', np.real(k_left[0:ind_right_active]), '\n')
print('向右可传播的通道数对应的费米速度 velocity_right:\n', np.real(velocity_right[0:ind_right_active]))
print('向左可传播的通道数对应的费米速度 velocity_left:\n', np.real(velocity_left[0:ind_right_active]), '\n')
print('透射矩阵 transmission_matrix:\n', np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])))
print('反射矩阵 reflection_matrix:\n', np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), '\n')
print('透射矩阵列求和 total transmission of channels =\n', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))
print('反射矩阵列求和 total reflection of channels =\n',np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))
print('透射以及反射矩阵列求和 sum of transmission and reflection of channels =\n', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0) + np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))
print('总电导 total conductance = ', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active]))), '\n')
# 下面把以上信息写入文件中
with open('a.txt', 'w') as f:
f.write('Active_channel (right or left) = ' + str(ind_right_active) + '\n')
f.write('Evanescent_channel (right or left) = ' + str(dim - ind_right_active) + '\n\n')
f.write('Channel K Velocity\n')
for ind0 in range(ind_right_active):
f.write(' '+str(ind0 + 1) + ' | '+str(np.real(k_right[ind0]))+' ' + str(np.real(velocity_right[ind0]))+'\n')
f.write('\n')
for ind0 in range(ind_right_active):
f.write(' -' + str(ind0 + 1) + ' | ' + str(np.real(k_left[ind0])) + ' ' + str(np.real(velocity_left[ind0])) + '\n')
f.write('\n\nScattering_matrix:\n ')
for ind0 in range(ind_right_active):
f.write(str(ind0+1)+' ')
f.write('\n')
for ind1 in range(ind_right_active):
f.write(' '+str(ind1+1)+' ')
for ind2 in range(ind_right_active):
f.write('%f' % np.square(np.abs(transmission_matrix[ind1, ind2]))+' ')
f.write('\n')
f.write('\n')
for ind1 in range(ind_right_active):
f.write(' -'+str(ind1+1)+' ')
for ind2 in range(ind_right_active):
f.write('%f' % np.square(np.abs(reflection_matrix[ind1, ind2]))+' ')
f.write('\n')
f.write('\n')
f.write('Total transmission of channels:\n'+str(np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))+'\n')
f.write('Total conductance = '+str(np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active]))))+'\n')
if __name__ == '__main__':
main()

View File

@@ -1,180 +1,180 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6075
"""
import numpy as np
import matplotlib.pyplot as plt
import copy
import time
def get_lead_h00(width):
h00 = np.zeros((width, width))
for i0 in range(width-1):
h00[i0, i0+1] = 1
h00[i0+1, i0] = 1
return h00
def get_lead_h01(width):
h01 = np.identity(width)
return h01
def get_center_hamiltonian(Nx, Ny):
h = np.zeros((Nx*Ny, Nx*Ny))
for x0 in range(Nx-1):
for y0 in range(Ny):
h[x0*Ny+y0, (x0+1)*Ny+y0] = 1 # x方向的跃迁
h[(x0+1)*Ny+y0, x0*Ny+y0] = 1
for x0 in range(Nx):
for y0 in range(Ny-1):
h[x0*Ny+y0, x0*Ny+y0+1] = 1 # y方向的跃迁
h[x0*Ny+y0+1, x0*Ny+y0] = 1
return h
def main():
start_time = time.time()
width = 5
length = 50
fermi_energy_array = np.arange(-4, 4, .01)
# 中心区的哈密顿量
H_center = get_center_hamiltonian(Nx=length, Ny=width)
# 电极的h00和h01
lead_h00 = get_lead_h00(width)
lead_h01 = get_lead_h01(width)
transmission_12_array = []
transmission_13_array = []
transmission_14_array = []
transmission_15_array = []
transmission_16_array = []
transmission_1_all_array = []
for fermi_energy in fermi_energy_array:
print(fermi_energy)
# 表面格林函数
right_lead_surface, left_lead_surface = surface_green_function_lead(fermi_energy + 1e-9j, lead_h00, lead_h01, dim=width)
# 由于镜面对称以及xy各项同性因此这里六个电极的表面格林函数具有相同的形式
lead_1 = copy.deepcopy(right_lead_surface) # 镜面对称使得lead_1=lead_4
lead_2 = copy.deepcopy(right_lead_surface) # xy各向同性使得lead_2=lead_4
lead_3 = copy.deepcopy(right_lead_surface)
lead_4 = copy.deepcopy(right_lead_surface)
lead_5 = copy.deepcopy(right_lead_surface)
lead_6 = copy.deepcopy(right_lead_surface)
# 几何形状如下所示:
# lead2 lead3
# lead1(L) lead4(R)
# lead6 lead5
# 电极到中心区的跃迁矩阵
H_lead_1_to_center = np.zeros((width, width*length), dtype=complex)
H_lead_2_to_center = np.zeros((width, width*length), dtype=complex)
H_lead_3_to_center = np.zeros((width, width*length), dtype=complex)
H_lead_4_to_center = np.zeros((width, width*length), dtype=complex)
H_lead_5_to_center = np.zeros((width, width*length), dtype=complex)
H_lead_6_to_center = np.zeros((width, width*length), dtype=complex)
move = 0 # the step of leads 2,3,6,5 moving to center
for i0 in range(width):
H_lead_1_to_center[i0, i0] = 1
H_lead_2_to_center[i0, width*(move+i0)+(width-1)] = 1
H_lead_3_to_center[i0, width*(length-move-1-i0)+(width-1)] = 1
H_lead_4_to_center[i0, width*(length-1)+i0] = 1
H_lead_5_to_center[i0, width*(length-move-1-i0)+0] = 1
H_lead_6_to_center[i0, width*(move+i0)+0] = 1
# 自能
self_energy_1 = np.dot(np.dot(H_lead_1_to_center.transpose().conj(), lead_1), H_lead_1_to_center)
self_energy_2 = np.dot(np.dot(H_lead_2_to_center.transpose().conj(), lead_2), H_lead_2_to_center)
self_energy_3 = np.dot(np.dot(H_lead_3_to_center.transpose().conj(), lead_3), H_lead_3_to_center)
self_energy_4 = np.dot(np.dot(H_lead_4_to_center.transpose().conj(), lead_4), H_lead_4_to_center)
self_energy_5 = np.dot(np.dot(H_lead_5_to_center.transpose().conj(), lead_5), H_lead_5_to_center)
self_energy_6 = np.dot(np.dot(H_lead_6_to_center.transpose().conj(), lead_6), H_lead_6_to_center)
# 整体格林函数
green = np.linalg.inv(fermi_energy*np.eye(width*length)-H_center-self_energy_1-self_energy_2-self_energy_3-self_energy_4-self_energy_5-self_energy_6)
# Gamma矩阵
gamma_1 = 1j*(self_energy_1-self_energy_1.transpose().conj())
gamma_2 = 1j*(self_energy_2-self_energy_2.transpose().conj())
gamma_3 = 1j*(self_energy_3-self_energy_3.transpose().conj())
gamma_4 = 1j*(self_energy_4-self_energy_4.transpose().conj())
gamma_5 = 1j*(self_energy_5-self_energy_5.transpose().conj())
gamma_6 = 1j*(self_energy_6-self_energy_6.transpose().conj())
# Transmission
transmission_12 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_2), green.transpose().conj()))
transmission_13 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_3), green.transpose().conj()))
transmission_14 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_4), green.transpose().conj()))
transmission_15 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_5), green.transpose().conj()))
transmission_16 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_6), green.transpose().conj()))
transmission_12_array.append(np.real(transmission_12))
transmission_13_array.append(np.real(transmission_13))
transmission_14_array.append(np.real(transmission_14))
transmission_15_array.append(np.real(transmission_15))
transmission_16_array.append(np.real(transmission_16))
transmission_1_all_array.append(np.real(transmission_12+transmission_13+transmission_14+transmission_15+transmission_16))
Plot_Line(fermi_energy_array, transmission_12_array, xlabel='Fermi energy', ylabel='Transmission_12', title='', filename='a')
Plot_Line(fermi_energy_array, transmission_13_array, xlabel='Fermi energy', ylabel='Transmission_13', title='', filename='a')
Plot_Line(fermi_energy_array, transmission_14_array, xlabel='Fermi energy', ylabel='Transmission_14', title='', filename='a')
Plot_Line(fermi_energy_array, transmission_15_array, xlabel='Fermi energy', ylabel='Transmission_15', title='', filename='a')
Plot_Line(fermi_energy_array, transmission_16_array, xlabel='Fermi energy', ylabel='Transmission_16', title='', filename='a')
Plot_Line(fermi_energy_array, transmission_1_all_array, xlabel='Fermi energy', ylabel='Transmission_1_all', title='', filename='a')
end_time = time.time()
print('运行时间=', end_time-start_time)
def Plot_Line(x, y, xlabel='x', ylabel='y', title='', filename='a'):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.20, left=0.18)
ax.plot(x, y, '-')
ax.grid()
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
ax.tick_params(labelsize=20)
labels = ax.get_xticklabels() + ax.get_yticklabels()
[label.set_fontname('Times New Roman') for label in labels]
# plt.savefig(filename+'.jpg', dpi=300)
plt.show()
plt.close('all')
def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵T
transfer = np.zeros((2*dim, 2*dim))*(0+0j)
transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00)
transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj())
transfer[dim:2*dim, 0:dim] = np.identity(dim)
transfer[dim:2*dim, dim:2*dim] = 0
return transfer # 返回转移矩阵
def surface_green_function_lead(fermi_energy, h00, h01, dim): # 电极的表面格林函数
transfer = transfer_matrix(fermi_energy, h00, h01, dim)
eigenvalue, eigenvector = np.linalg.eig(transfer)
ind = np.argsort(np.abs(eigenvalue))
temp = np.zeros((2*dim, 2*dim))*(1+0j)
i0 = 0
for ind0 in ind:
temp[:, i0] = eigenvector[:, ind0]
i0 += 1
s1 = temp[dim:2*dim, 0:dim]
s2 = temp[0:dim, 0:dim]
s3 = temp[dim:2*dim, dim:2*dim]
s4 = temp[0:dim, dim:2*dim]
right_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01, s2), np.linalg.inv(s1)))
left_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), s3), np.linalg.inv(s4)))
return right_lead_surface, left_lead_surface # 返回右电极的表面格林函数和左电极的表面格林函数
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6075
"""
import numpy as np
import matplotlib.pyplot as plt
import copy
import time
def get_lead_h00(width):
h00 = np.zeros((width, width))
for i0 in range(width-1):
h00[i0, i0+1] = 1
h00[i0+1, i0] = 1
return h00
def get_lead_h01(width):
h01 = np.identity(width)
return h01
def get_center_hamiltonian(Nx, Ny):
h = np.zeros((Nx*Ny, Nx*Ny))
for x0 in range(Nx-1):
for y0 in range(Ny):
h[x0*Ny+y0, (x0+1)*Ny+y0] = 1 # x方向的跃迁
h[(x0+1)*Ny+y0, x0*Ny+y0] = 1
for x0 in range(Nx):
for y0 in range(Ny-1):
h[x0*Ny+y0, x0*Ny+y0+1] = 1 # y方向的跃迁
h[x0*Ny+y0+1, x0*Ny+y0] = 1
return h
def main():
start_time = time.time()
width = 5
length = 50
fermi_energy_array = np.arange(-4, 4, .01)
# 中心区的哈密顿量
H_center = get_center_hamiltonian(Nx=length, Ny=width)
# 电极的h00和h01
lead_h00 = get_lead_h00(width)
lead_h01 = get_lead_h01(width)
transmission_12_array = []
transmission_13_array = []
transmission_14_array = []
transmission_15_array = []
transmission_16_array = []
transmission_1_all_array = []
for fermi_energy in fermi_energy_array:
print(fermi_energy)
# 表面格林函数
right_lead_surface, left_lead_surface = surface_green_function_lead(fermi_energy + 1e-9j, lead_h00, lead_h01, dim=width)
# 由于镜面对称以及xy各项同性因此这里六个电极的表面格林函数具有相同的形式
lead_1 = copy.deepcopy(right_lead_surface) # 镜面对称使得lead_1=lead_4
lead_2 = copy.deepcopy(right_lead_surface) # xy各向同性使得lead_2=lead_4
lead_3 = copy.deepcopy(right_lead_surface)
lead_4 = copy.deepcopy(right_lead_surface)
lead_5 = copy.deepcopy(right_lead_surface)
lead_6 = copy.deepcopy(right_lead_surface)
# 几何形状如下所示:
# lead2 lead3
# lead1(L) lead4(R)
# lead6 lead5
# 电极到中心区的跃迁矩阵
H_lead_1_to_center = np.zeros((width, width*length), dtype=complex)
H_lead_2_to_center = np.zeros((width, width*length), dtype=complex)
H_lead_3_to_center = np.zeros((width, width*length), dtype=complex)
H_lead_4_to_center = np.zeros((width, width*length), dtype=complex)
H_lead_5_to_center = np.zeros((width, width*length), dtype=complex)
H_lead_6_to_center = np.zeros((width, width*length), dtype=complex)
move = 0 # the step of leads 2,3,6,5 moving to center
for i0 in range(width):
H_lead_1_to_center[i0, i0] = 1
H_lead_2_to_center[i0, width*(move+i0)+(width-1)] = 1
H_lead_3_to_center[i0, width*(length-move-1-i0)+(width-1)] = 1
H_lead_4_to_center[i0, width*(length-1)+i0] = 1
H_lead_5_to_center[i0, width*(length-move-1-i0)+0] = 1
H_lead_6_to_center[i0, width*(move+i0)+0] = 1
# 自能
self_energy_1 = np.dot(np.dot(H_lead_1_to_center.transpose().conj(), lead_1), H_lead_1_to_center)
self_energy_2 = np.dot(np.dot(H_lead_2_to_center.transpose().conj(), lead_2), H_lead_2_to_center)
self_energy_3 = np.dot(np.dot(H_lead_3_to_center.transpose().conj(), lead_3), H_lead_3_to_center)
self_energy_4 = np.dot(np.dot(H_lead_4_to_center.transpose().conj(), lead_4), H_lead_4_to_center)
self_energy_5 = np.dot(np.dot(H_lead_5_to_center.transpose().conj(), lead_5), H_lead_5_to_center)
self_energy_6 = np.dot(np.dot(H_lead_6_to_center.transpose().conj(), lead_6), H_lead_6_to_center)
# 整体格林函数
green = np.linalg.inv(fermi_energy*np.eye(width*length)-H_center-self_energy_1-self_energy_2-self_energy_3-self_energy_4-self_energy_5-self_energy_6)
# Gamma矩阵
gamma_1 = 1j*(self_energy_1-self_energy_1.transpose().conj())
gamma_2 = 1j*(self_energy_2-self_energy_2.transpose().conj())
gamma_3 = 1j*(self_energy_3-self_energy_3.transpose().conj())
gamma_4 = 1j*(self_energy_4-self_energy_4.transpose().conj())
gamma_5 = 1j*(self_energy_5-self_energy_5.transpose().conj())
gamma_6 = 1j*(self_energy_6-self_energy_6.transpose().conj())
# Transmission
transmission_12 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_2), green.transpose().conj()))
transmission_13 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_3), green.transpose().conj()))
transmission_14 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_4), green.transpose().conj()))
transmission_15 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_5), green.transpose().conj()))
transmission_16 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_6), green.transpose().conj()))
transmission_12_array.append(np.real(transmission_12))
transmission_13_array.append(np.real(transmission_13))
transmission_14_array.append(np.real(transmission_14))
transmission_15_array.append(np.real(transmission_15))
transmission_16_array.append(np.real(transmission_16))
transmission_1_all_array.append(np.real(transmission_12+transmission_13+transmission_14+transmission_15+transmission_16))
Plot_Line(fermi_energy_array, transmission_12_array, xlabel='Fermi energy', ylabel='Transmission_12', title='', filename='a')
Plot_Line(fermi_energy_array, transmission_13_array, xlabel='Fermi energy', ylabel='Transmission_13', title='', filename='a')
Plot_Line(fermi_energy_array, transmission_14_array, xlabel='Fermi energy', ylabel='Transmission_14', title='', filename='a')
Plot_Line(fermi_energy_array, transmission_15_array, xlabel='Fermi energy', ylabel='Transmission_15', title='', filename='a')
Plot_Line(fermi_energy_array, transmission_16_array, xlabel='Fermi energy', ylabel='Transmission_16', title='', filename='a')
Plot_Line(fermi_energy_array, transmission_1_all_array, xlabel='Fermi energy', ylabel='Transmission_1_all', title='', filename='a')
end_time = time.time()
print('运行时间=', end_time-start_time)
def Plot_Line(x, y, xlabel='x', ylabel='y', title='', filename='a'):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.20, left=0.18)
ax.plot(x, y, '-')
ax.grid()
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
ax.tick_params(labelsize=20)
labels = ax.get_xticklabels() + ax.get_yticklabels()
[label.set_fontname('Times New Roman') for label in labels]
# plt.savefig(filename+'.jpg', dpi=300)
plt.show()
plt.close('all')
def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵T
transfer = np.zeros((2*dim, 2*dim))*(0+0j)
transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00)
transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj())
transfer[dim:2*dim, 0:dim] = np.identity(dim)
transfer[dim:2*dim, dim:2*dim] = 0
return transfer # 返回转移矩阵
def surface_green_function_lead(fermi_energy, h00, h01, dim): # 电极的表面格林函数
transfer = transfer_matrix(fermi_energy, h00, h01, dim)
eigenvalue, eigenvector = np.linalg.eig(transfer)
ind = np.argsort(np.abs(eigenvalue))
temp = np.zeros((2*dim, 2*dim))*(1+0j)
i0 = 0
for ind0 in ind:
temp[:, i0] = eigenvector[:, ind0]
i0 += 1
s1 = temp[dim:2*dim, 0:dim]
s2 = temp[0:dim, 0:dim]
s3 = temp[dim:2*dim, dim:2*dim]
s4 = temp[0:dim, dim:2*dim]
right_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01, s2), np.linalg.inv(s1)))
left_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), s3), np.linalg.inv(s4)))
return right_lead_surface, left_lead_surface # 返回右电极的表面格林函数和左电极的表面格林函数
if __name__ == '__main__':
main()

View File

@@ -1,50 +1,50 @@
% This code is supported by the website: https://www.guanjihuan.com
% The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3932
%
clear;clc;
n=100; %
delta=1e-9; %
C=0;
for kx=-pi:(1/n):pi
for ky=-pi:(1/n):pi
VV=get_vector(HH(kx,ky));
Vkx=get_vector(HH(kx+delta,ky)); % kx
Vky=get_vector(HH(kx,ky+delta)); % ky
Vkxky=get_vector(HH(kx+delta,ky+delta)); % kxky
if sum((abs(Vkx-VV)))>0.01 %
Vkx=-Vkx;
end
if sum((abs(Vky-VV)))>0.01
Vky=-Vky;
end
if sum(abs(Vkxky-VV))>0.01
Vkxky=-Vkxky;
end
% berry connection
Ax=VV'*(Vkx-VV)/delta; % Berry connection Ax
Ay=VV'*(Vky-VV)/delta; % Berry connection Ay
Ax_delta_ky=Vky'*(Vkxky-Vky)/delta; % kyberry connection Ax
Ay_delta_kx=Vkx'*(Vkxky-Vkx)/delta; % kxberry connection Ay
% berry curvature
F=((Ay_delta_kx-Ay)-(Ax_delta_ky-Ax))/delta;
% chern number
C=C+F*(1/n)^2;
end
end
C=C/(2*pi*1i)
function vector_new = get_vector(H)
[vector,eigenvalue] = eig(H);
[eigenvalue, index]=sort(diag(eigenvalue), 'descend');
vector_new = vector(:, index(2));
end
function H=HH(kx,ky)
H(1,2)=2*cos(kx)-1i*2*cos(ky);
H(2,1)=2*cos(kx)+1i*2*cos(ky);
H(1,1)=-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky);
H(2,2)=-(-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky));
% This code is supported by the website: https://www.guanjihuan.com
% The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3932
%
clear;clc;
n=100; %
delta=1e-9; %
C=0;
for kx=-pi:(1/n):pi
for ky=-pi:(1/n):pi
VV=get_vector(HH(kx,ky));
Vkx=get_vector(HH(kx+delta,ky)); % kx
Vky=get_vector(HH(kx,ky+delta)); % ky
Vkxky=get_vector(HH(kx+delta,ky+delta)); % kxky
if sum((abs(Vkx-VV)))>0.01 %
Vkx=-Vkx;
end
if sum((abs(Vky-VV)))>0.01
Vky=-Vky;
end
if sum(abs(Vkxky-VV))>0.01
Vkxky=-Vkxky;
end
% berry connection
Ax=VV'*(Vkx-VV)/delta; % Berry connection Ax
Ay=VV'*(Vky-VV)/delta; % Berry connection Ay
Ax_delta_ky=Vky'*(Vkxky-Vky)/delta; % kyberry connection Ax
Ay_delta_kx=Vkx'*(Vkxky-Vkx)/delta; % kxberry connection Ay
% berry curvature
F=((Ay_delta_kx-Ay)-(Ax_delta_ky-Ax))/delta;
% chern number
C=C+F*(1/n)^2;
end
end
C=C/(2*pi*1i)
function vector_new = get_vector(H)
[vector,eigenvalue] = eig(H);
[eigenvalue, index]=sort(diag(eigenvalue), 'descend');
vector_new = vector(:, index(2));
end
function H=HH(kx,ky)
H(1,2)=2*cos(kx)-1i*2*cos(ky);
H(2,1)=2*cos(kx)+1i*2*cos(ky);
H(1,1)=-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky);
H(2,2)=-(-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky));
end

View File

@@ -1,69 +1,69 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3932
"""
import numpy as np
from math import *
import time
def hamiltonian(kx, ky): # 量子反常霍尔QAH模型该参数对应的陈数为2
t1 = 1.0
t2 = 1.0
t3 = 0.5
m = -1.0
matrix = np.zeros((2, 2), dtype=complex)
matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky)
matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky)
matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)
matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky))
return matrix
def main():
start_time = time.time()
n = 100 # 积分密度
delta = 1e-9 # 求导的偏离量
chern_number = 0 # 陈数初始化
for kx in np.arange(-pi, pi, 2*pi/n):
for ky in np.arange(-pi, pi, 2*pi/n):
H = hamiltonian(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
# print(np.argsort(np.real(eigenvalue))[0]) # 排序索引(从小到大)
# print(eigenvalue) # 排序前的本征值
# print(np.sort(np.real(eigenvalue))) # 排序后的本征值(从小到大)
H_delta_kx = hamiltonian(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
# 价带的波函数的贝里联络(berry connection) # 求导后内积
A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Axx分量
A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ayy分量
A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax
A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay
# 贝里曲率(berry curvature)
F = (A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta
# 陈数(chern number)
chern_number = chern_number + F*(2*pi/n)**2
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number)
end_time = time.time()
print('运行时间(min)=', (end_time-start_time)/60)
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3932
"""
import numpy as np
from math import *
import time
def hamiltonian(kx, ky): # 量子反常霍尔QAH模型该参数对应的陈数为2
t1 = 1.0
t2 = 1.0
t3 = 0.5
m = -1.0
matrix = np.zeros((2, 2), dtype=complex)
matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky)
matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky)
matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)
matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky))
return matrix
def main():
start_time = time.time()
n = 100 # 积分密度
delta = 1e-9 # 求导的偏离量
chern_number = 0 # 陈数初始化
for kx in np.arange(-pi, pi, 2*pi/n):
for ky in np.arange(-pi, pi, 2*pi/n):
H = hamiltonian(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
# print(np.argsort(np.real(eigenvalue))[0]) # 排序索引(从小到大)
# print(eigenvalue) # 排序前的本征值
# print(np.sort(np.real(eigenvalue))) # 排序后的本征值(从小到大)
H_delta_kx = hamiltonian(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
# 价带的波函数的贝里联络(berry connection) # 求导后内积
A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Axx分量
A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ayy分量
A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax
A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay
# 贝里曲率(berry curvature)
F = (A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta
# 陈数(chern number)
chern_number = chern_number + F*(2*pi/n)**2
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number)
end_time = time.time()
print('运行时间(min)=', (end_time-start_time)/60)
if __name__ == '__main__':
main()

View File

@@ -1,107 +1,107 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3932
"""
import numpy as np
from math import *
import time
import cmath
def hamiltonian(kx, ky): # 量子反常霍尔QAH模型该参数对应的陈数为2
t1 = 1.0
t2 = 1.0
t3 = 0.5
m = -1.0
matrix = np.zeros((2, 2), dtype=complex)
matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky)
matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky)
matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)
matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky))
return matrix
def main():
start_time = time.time()
n = 20 # 积分密度
delta = 1e-9 # 求导的偏离量
chern_number = 0 # 陈数初始化
for kx in np.arange(-pi, pi, 2*pi/n):
for ky in np.arange(-pi, pi, 2*pi/n):
H = hamiltonian(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
vector_delta_kx = find_vector_with_the_same_gauge(vector_delta_kx, vector)
vector_delta_ky = find_vector_with_the_same_gauge(vector_delta_ky, vector)
vector_delta_kx_ky = find_vector_with_the_same_gauge(vector_delta_kx_ky, vector)
# 价带的波函数的贝里联络(berry connection) # 求导后内积
A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Axx分量
A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ayy分量
A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax
A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay
# 贝里曲率(berry curvature)
F = (A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta
# 陈数(chern number)
chern_number = chern_number + F*(2*pi/n)**2
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number)
end_time = time.time()
print('运行时间(min)=', (end_time-start_time)/60)
def find_vector_with_the_same_gauge(vector_1, vector_0):
# 寻找近似的同一的规范
phase_1_pre = 0
phase_2_pre = pi
n_test = 10001
for i0 in range(n_test):
test_1 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_1_pre) - vector_0))
test_2 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_2_pre) - vector_0))
if test_1 < 1e-8:
phase = phase_1_pre
# print('Done with i0=', i0)
break
if i0 == n_test-1:
phase = phase_1_pre
print('Gauge Not Found with i0=', i0)
if test_1 < test_2:
if i0 == 0:
phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
else:
phase_1 = phase_1_pre
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
else:
if i0 == 0:
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2
else:
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
phase_2 = phase_2_pre
phase_1_pre = phase_1
phase_2_pre = phase_2
vector_1 = vector_1*cmath.exp(1j*phase)
# print('二分查找找到的规范=', phase)
return vector_1
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3932
"""
import numpy as np
from math import *
import time
import cmath
def hamiltonian(kx, ky): # 量子反常霍尔QAH模型该参数对应的陈数为2
t1 = 1.0
t2 = 1.0
t3 = 0.5
m = -1.0
matrix = np.zeros((2, 2), dtype=complex)
matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky)
matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky)
matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)
matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky))
return matrix
def main():
start_time = time.time()
n = 20 # 积分密度
delta = 1e-9 # 求导的偏离量
chern_number = 0 # 陈数初始化
for kx in np.arange(-pi, pi, 2*pi/n):
for ky in np.arange(-pi, pi, 2*pi/n):
H = hamiltonian(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
vector_delta_kx = find_vector_with_the_same_gauge(vector_delta_kx, vector)
vector_delta_ky = find_vector_with_the_same_gauge(vector_delta_ky, vector)
vector_delta_kx_ky = find_vector_with_the_same_gauge(vector_delta_kx_ky, vector)
# 价带的波函数的贝里联络(berry connection) # 求导后内积
A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Axx分量
A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ayy分量
A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax
A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay
# 贝里曲率(berry curvature)
F = (A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta
# 陈数(chern number)
chern_number = chern_number + F*(2*pi/n)**2
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number)
end_time = time.time()
print('运行时间(min)=', (end_time-start_time)/60)
def find_vector_with_the_same_gauge(vector_1, vector_0):
# 寻找近似的同一的规范
phase_1_pre = 0
phase_2_pre = pi
n_test = 10001
for i0 in range(n_test):
test_1 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_1_pre) - vector_0))
test_2 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_2_pre) - vector_0))
if test_1 < 1e-8:
phase = phase_1_pre
# print('Done with i0=', i0)
break
if i0 == n_test-1:
phase = phase_1_pre
print('Gauge Not Found with i0=', i0)
if test_1 < test_2:
if i0 == 0:
phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
else:
phase_1 = phase_1_pre
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
else:
if i0 == 0:
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2
else:
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
phase_2 = phase_2_pre
phase_1_pre = phase_1
phase_2_pre = phase_2
vector_1 = vector_1*cmath.exp(1j*phase)
# print('二分查找找到的规范=', phase)
return vector_1
if __name__ == '__main__':
main()

View File

@@ -1,40 +1,40 @@
% This code is supported by the website: https://www.guanjihuan.com
% The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4179
%
clear;clc;
n=1000 %
delta=2*pi/n;
C=0;
for kx=-pi:(2*pi/n):pi
for ky=-pi:(2*pi/n):pi
VV=get_vector(HH(kx,ky));
Vkx=get_vector(HH(kx+delta,ky)); % kx
Vky=get_vector(HH(kx,ky+delta)); % ky
Vkxky=get_vector(HH(kx+delta,ky+delta)); % kxky
Ux = VV'*Vkx/abs(VV'*Vkx);
Uy = VV'*Vky/abs(VV'*Vky);
Ux_y = Vky'*Vkxky/abs(Vky'*Vkxky);
Uy_x = Vkx'*Vkxky/abs(Vkx'*Vkxky);
% berry curvature
F=log(Ux*Uy_x*(1/Ux_y)*(1/Uy));
% chern number
C=C+F;
end
end
C=C/(2*pi*1i)
function vector_new = get_vector(H)
[vector,eigenvalue] = eig(H);
[eigenvalue, index]=sort(diag(eigenvalue), 'descend');
vector_new = vector(:, index(2));
end
function H=HH(kx,ky)
H(1,2)=2*cos(kx)-1i*2*cos(ky);
H(2,1)=2*cos(kx)+1i*2*cos(ky);
H(1,1)=-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky);
H(2,2)=-(-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky));
% This code is supported by the website: https://www.guanjihuan.com
% The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4179
%
clear;clc;
n=1000 %
delta=2*pi/n;
C=0;
for kx=-pi:(2*pi/n):pi
for ky=-pi:(2*pi/n):pi
VV=get_vector(HH(kx,ky));
Vkx=get_vector(HH(kx+delta,ky)); % kx
Vky=get_vector(HH(kx,ky+delta)); % ky
Vkxky=get_vector(HH(kx+delta,ky+delta)); % kxky
Ux = VV'*Vkx/abs(VV'*Vkx);
Uy = VV'*Vky/abs(VV'*Vky);
Ux_y = Vky'*Vkxky/abs(Vky'*Vkxky);
Uy_x = Vkx'*Vkxky/abs(Vkx'*Vkxky);
% berry curvature
F=log(Ux*Uy_x*(1/Ux_y)*(1/Uy));
% chern number
C=C+F;
end
end
C=C/(2*pi*1i)
function vector_new = get_vector(H)
[vector,eigenvalue] = eig(H);
[eigenvalue, index]=sort(diag(eigenvalue), 'descend');
vector_new = vector(:, index(2));
end
function H=HH(kx,ky)
H(1,2)=2*cos(kx)-1i*2*cos(ky);
H(2,1)=2*cos(kx)+1i*2*cos(ky);
H(1,1)=-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky);
H(2,2)=-(-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky));
end

View File

@@ -1,65 +1,65 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4179
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入pi, cos等
import cmath
import time
def hamiltonian(kx, ky): # 量子反常霍尔QAH模型该参数对应的陈数为2
t1 = 1.0
t2 = 1.0
t3 = 0.5
m = -1.0
matrix = np.zeros((2, 2))*(1+0j)
matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky)
matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky)
matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)
matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky))
return matrix
def main():
start_time = time.time()
n = 100
delta = 2*pi/n
chern_number = 0 # 陈数初始化
for kx in np.arange(-pi, pi, 2*pi/n):
for ky in np.arange(-pi, pi, 2*pi/n):
H = hamiltonian(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
# 陈数(chern number)
chern_number = chern_number + F
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number)
end_time = time.time()
print('运行时间(min)=', (end_time-start_time)/60)
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4179
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入pi, cos等
import cmath
import time
def hamiltonian(kx, ky): # 量子反常霍尔QAH模型该参数对应的陈数为2
t1 = 1.0
t2 = 1.0
t3 = 0.5
m = -1.0
matrix = np.zeros((2, 2))*(1+0j)
matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky)
matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky)
matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)
matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky))
return matrix
def main():
start_time = time.time()
n = 100
delta = 2*pi/n
chern_number = 0 # 陈数初始化
for kx in np.arange(-pi, pi, 2*pi/n):
for ky in np.arange(-pi, pi, 2*pi/n):
H = hamiltonian(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
# 陈数(chern number)
chern_number = chern_number + F
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number)
end_time = time.time()
print('运行时间(min)=', (end_time-start_time)/60)
if __name__ == '__main__':
main()

View File

@@ -1,94 +1,94 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5133
"""
import numpy as np
from math import * # 引入pi, cos等
import cmath
import time
import functools # 使用偏函数functools.partial()
def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量a为原子间距不赋值的话默认为1/sqrt(3)
# 初始化为零矩阵
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
h2 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term), 用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# # 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
#次近邻项 # 对应陈数为-1
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
# # 次近邻项 # 对应陈数为1
# h2[0, 0] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
# h2[1, 1] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
matrix = h0 + h1 + h2 + h2.transpose().conj()
return matrix
def main():
start_clock = time.perf_counter()
delta = 0.005
chern_number = 0 # 陈数初始化
# 几个坐标中常出现的项
a = 1/sqrt(3)
aa1 = 4*sqrt(3)*pi/9/a
aa2 = 2*sqrt(3)*pi/9/a
bb1 = 2*pi/3/a
hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数
for kx in np.arange(-aa1, aa1, delta):
print(kx)
for ky in np.arange(-bb1, bb1, delta):
if (-aa2<=kx<=aa2) or (kx>aa2 and -(aa1-kx)*tan(pi/3)<=ky<=(aa1-kx)*tan(pi/3)) or (kx<-aa2 and -(kx-(-aa1))*tan(pi/3)<=ky<=(kx-(-aa1))*tan(pi/3)): # 限制在六角格子布里渊区内
H = hamiltonian0(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian0(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian0(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian0(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
# 陈数(chern number)
chern_number = chern_number + F
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number)
end_clock = time.perf_counter()
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5133
"""
import numpy as np
from math import * # 引入pi, cos等
import cmath
import time
import functools # 使用偏函数functools.partial()
def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量a为原子间距不赋值的话默认为1/sqrt(3)
# 初始化为零矩阵
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
h2 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term), 用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# # 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
#次近邻项 # 对应陈数为-1
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
# # 次近邻项 # 对应陈数为1
# h2[0, 0] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
# h2[1, 1] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
matrix = h0 + h1 + h2 + h2.transpose().conj()
return matrix
def main():
start_clock = time.perf_counter()
delta = 0.005
chern_number = 0 # 陈数初始化
# 几个坐标中常出现的项
a = 1/sqrt(3)
aa1 = 4*sqrt(3)*pi/9/a
aa2 = 2*sqrt(3)*pi/9/a
bb1 = 2*pi/3/a
hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数
for kx in np.arange(-aa1, aa1, delta):
print(kx)
for ky in np.arange(-bb1, bb1, delta):
if (-aa2<=kx<=aa2) or (kx>aa2 and -(aa1-kx)*tan(pi/3)<=ky<=(aa1-kx)*tan(pi/3)) or (kx<-aa2 and -(kx-(-aa1))*tan(pi/3)<=ky<=(kx-(-aa1))*tan(pi/3)): # 限制在六角格子布里渊区内
H = hamiltonian0(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian0(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian0(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian0(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
# 陈数(chern number)
chern_number = chern_number + F
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number)
end_clock = time.perf_counter()
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
if __name__ == '__main__':
main()

View File

@@ -1,91 +1,91 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5133
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入pi, cos等
import cmath
import time
import functools # 使用偏函数functools.partial()
def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量a为原子间距不赋值的话默认为1/sqrt(3)
# 初始化为零矩阵
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
h2 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term), 用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# # 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
#次近邻项 # 对应陈数为-1
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
# # 次近邻项 # 对应陈数为1
# h2[0, 0] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
# h2[1, 1] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
matrix = h0 + h1 + h2 + h2.transpose().conj()
return matrix
def main():
start_clock = time.perf_counter()
delta = 0.005
chern_number = 0 # 陈数初始化
# 常出现的项
a = 1/sqrt(3)
bb1 = 2*sqrt(3)*pi/3/a
bb2 = 2*pi/3/a
hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数
for kx in np.arange(0 , bb1, delta):
print(kx)
for ky in np.arange(0, 2*bb2, delta):
H = hamiltonian0(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian0(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian0(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian0(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
# 陈数(chern number)
chern_number = chern_number + F
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number)
end_clock = time.perf_counter()
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5133
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入pi, cos等
import cmath
import time
import functools # 使用偏函数functools.partial()
def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量a为原子间距不赋值的话默认为1/sqrt(3)
# 初始化为零矩阵
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
h2 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term), 用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# # 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
#次近邻项 # 对应陈数为-1
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
# # 次近邻项 # 对应陈数为1
# h2[0, 0] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
# h2[1, 1] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
matrix = h0 + h1 + h2 + h2.transpose().conj()
return matrix
def main():
start_clock = time.perf_counter()
delta = 0.005
chern_number = 0 # 陈数初始化
# 常出现的项
a = 1/sqrt(3)
bb1 = 2*sqrt(3)*pi/3/a
bb2 = 2*pi/3/a
hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数
for kx in np.arange(0 , bb1, delta):
print(kx)
for ky in np.arange(0, 2*bb2, delta):
H = hamiltonian0(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian0(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian0(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian0(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
# 陈数(chern number)
chern_number = chern_number + F
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number)
end_clock = time.perf_counter()
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
if __name__ == '__main__':
main()

View File

@@ -1,99 +1,99 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5133
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入pi, cos等
import cmath
import time
import functools # 使用偏函数functools.partial()
def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量# Haldane哈密顿量a为原子间距不赋值的话默认为1/sqrt(3)
# 初始化为零矩阵
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
h2 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term), 用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# # 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
#次近邻项 # 对应陈数为-1
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
# # 次近邻项 # 对应陈数为1
# h2[0, 0] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
# h2[1, 1] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
matrix = h0 + h1 + h2 + h2.transpose().conj()
return matrix
def main():
start_clock = time.perf_counter()
delta = 0.005
chern_number = 0 # 陈数初始化
# 常出现的项
a = 1/sqrt(3)
bb1 = 2*sqrt(3)*pi/3/a
bb2 = 2*pi/3/a
hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数
for k1 in np.arange(0 , 1, delta):
print(k1)
for k2 in np.arange(0, 1, delta):
# 坐标变换
kx = (k1-k2)*bb1
ky = (k1+k2)*bb2
# 这里乘2或除以2是为了保证“步长与积分个数的乘积刚好为布里渊区面积”
delta_x = delta*bb1*2
delta_y = delta*bb2*2/2
H = hamiltonian0(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian0(kx+delta_x, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian0(kx, ky+delta_y)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian0(kx+delta_x, ky+delta_y)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
# 陈数(chern number)
chern_number = chern_number + F
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number)
end_clock = time.perf_counter()
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5133
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入pi, cos等
import cmath
import time
import functools # 使用偏函数functools.partial()
def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量# Haldane哈密顿量a为原子间距不赋值的话默认为1/sqrt(3)
# 初始化为零矩阵
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
h2 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term), 用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# # 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
#次近邻项 # 对应陈数为-1
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
# # 次近邻项 # 对应陈数为1
# h2[0, 0] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
# h2[1, 1] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
matrix = h0 + h1 + h2 + h2.transpose().conj()
return matrix
def main():
start_clock = time.perf_counter()
delta = 0.005
chern_number = 0 # 陈数初始化
# 常出现的项
a = 1/sqrt(3)
bb1 = 2*sqrt(3)*pi/3/a
bb2 = 2*pi/3/a
hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数
for k1 in np.arange(0 , 1, delta):
print(k1)
for k2 in np.arange(0, 1, delta):
# 坐标变换
kx = (k1-k2)*bb1
ky = (k1+k2)*bb2
# 这里乘2或除以2是为了保证“步长与积分个数的乘积刚好为布里渊区面积”
delta_x = delta*bb1*2
delta_y = delta*bb2*2/2
H = hamiltonian0(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian0(kx+delta_x, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian0(kx, ky+delta_y)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian0(kx+delta_x, ky+delta_y)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
# 陈数(chern number)
chern_number = chern_number + F
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number)
end_clock = time.perf_counter()
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
if __name__ == '__main__':
main()

View File

@@ -1,41 +1,41 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5025
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import time
def hamiltonian(k): # SSH模型
v=0.6
w=1
matrix = np.zeros((2, 2), dtype=complex)
matrix[0,1] = v+w*cmath.exp(-1j*k)
matrix[1,0] = v+w*cmath.exp(1j*k)
return matrix
def main():
start_clock = time.perf_counter()
delta_1 = 1e-9 # 求导的步长(求导的步长可以尽可能短)
delta_2 = 1e-5 # 积分的步长(积分步长和计算时间相关,因此取一个合理值即可)
W = 0 # Winding number初始化
for k in np.arange(-pi, pi, delta_2):
H = hamiltonian(k)
log0 = cmath.log(H[0, 1])
H_delta = hamiltonian(k+delta_1)
log1 = cmath.log(H_delta[0, 1])
W = W + (log1-log0)/delta_1*delta_2 # Winding number
print('Winding number = ', W/2/pi/1j)
end_clock = time.perf_counter()
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5025
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import time
def hamiltonian(k): # SSH模型
v=0.6
w=1
matrix = np.zeros((2, 2), dtype=complex)
matrix[0,1] = v+w*cmath.exp(-1j*k)
matrix[1,0] = v+w*cmath.exp(1j*k)
return matrix
def main():
start_clock = time.perf_counter()
delta_1 = 1e-9 # 求导的步长(求导的步长可以尽可能短)
delta_2 = 1e-5 # 积分的步长(积分步长和计算时间相关,因此取一个合理值即可)
W = 0 # Winding number初始化
for k in np.arange(-pi, pi, delta_2):
H = hamiltonian(k)
log0 = cmath.log(H[0, 1])
H_delta = hamiltonian(k+delta_1)
log1 = cmath.log(H_delta[0, 1])
W = W + (log1-log0)/delta_1*delta_2 # Winding number
print('Winding number = ', W/2/pi/1j)
end_clock = time.perf_counter()
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
if __name__ == '__main__':
main()

View File

@@ -1,42 +1,42 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5025
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
def hamiltonian(k): # SSH模型
v=0.6
w=1
matrix = np.zeros((2, 2), dtype=complex)
matrix[0,1] = v+w*cmath.exp(-1j*k)
matrix[1,0] = v+w*cmath.exp(1j*k)
return matrix
def main():
k = np.linspace(-pi, pi, 100)
plot_bands_one_dimension(k, hamiltonian)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5025
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
def hamiltonian(k): # SSH模型
v=0.6
w=1
matrix = np.zeros((2, 2), dtype=complex)
matrix[0,1] = v+w*cmath.exp(-1j*k)
matrix[1,0] = v+w*cmath.exp(1j*k)
return matrix
def main():
k = np.linspace(-pi, pi, 100)
plot_bands_one_dimension(k, hamiltonian)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,68 +1,68 @@
% This code is supported by the website: https://www.guanjihuan.com
% The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5778
clear;clc;
delta=0.1;
Z2=0;
for kx=-pi:0.1:0
for ky=-pi:0.1:pi
[V1,V2]=get_vector(Hamiltonian(kx,ky));
[Vkx1,Vkx2]=get_vector(Hamiltonian(kx+delta,ky)); % kx
[Vky1,Vky2]=get_vector(Hamiltonian(kx,ky+delta)); % ky
[Vkxky1,Vkxky2]=get_vector(Hamiltonian(kx+delta,ky+delta)); % kxky
Ux = dot_and_det(V1, Vkx1, V2, Vkx2);
Uy = dot_and_det(V1, Vky1, V2, Vky2);
Ux_y = dot_and_det(Vky1, Vkxky1, Vky2, Vkxky2);
Uy_x = dot_and_det(Vkx1, Vkxky1, Vkx2, Vkxky2);
F=imag(log(Ux*Uy_x*(conj(Ux_y))*(conj(Uy))));
A=imag(log(Ux))+imag(log(Uy_x))+imag(log(conj(Ux_y)))+imag(log(conj(Uy)));
Z2 = Z2+(A-F)/(2*pi);
end
end
Z2= mod(Z2, 2)
function dd = dot_and_det(a1,b1,a2,b2) %
x1=a1'*b1;
x2=a2'*b2;
x3=a1'*b2;
x4=a2'*b1;
dd =x1*x2-x3*x4;
end
function [vector_new_1, vector_new_2] = get_vector(H)
[vector,eigenvalue] = eig(H);
[eigenvalue, index]=sort(diag(eigenvalue), 'ascend');
vector_new_2 = vector(:, index(2));
vector_new_1 = vector(:, index(1));
end
function H=Hamiltonian(kx,ky) % BHZ
A=0.3645/5;
B=-0.686/25;
C=0;
D=-0.512/25;
M=-0.01;
H=zeros(4,4);
varepsilon = C-2*D*(2-cos(kx)-cos(ky));
d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky));
d1_d2 = A*(sin(kx)+1j*sin(ky));
H(1, 1) = varepsilon+d3;
H(2, 2) = varepsilon-d3;
H(1, 2) = conj(d1_d2);
H(2, 1) = d1_d2 ;
varepsilon = C-2*D*(2-cos(-kx)-cos(-ky));
d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky));
d1_d2 = A*(sin(-kx)+1j*sin(-ky));
H(3, 3) = varepsilon+d3;
H(4, 4) = varepsilon-d3;
H(3, 4) = d1_d2 ;
H(4, 3) = conj(d1_d2);
% This code is supported by the website: https://www.guanjihuan.com
% The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5778
clear;clc;
delta=0.1;
Z2=0;
for kx=-pi:0.1:0
for ky=-pi:0.1:pi
[V1,V2]=get_vector(Hamiltonian(kx,ky));
[Vkx1,Vkx2]=get_vector(Hamiltonian(kx+delta,ky)); % kx
[Vky1,Vky2]=get_vector(Hamiltonian(kx,ky+delta)); % ky
[Vkxky1,Vkxky2]=get_vector(Hamiltonian(kx+delta,ky+delta)); % kxky
Ux = dot_and_det(V1, Vkx1, V2, Vkx2);
Uy = dot_and_det(V1, Vky1, V2, Vky2);
Ux_y = dot_and_det(Vky1, Vkxky1, Vky2, Vkxky2);
Uy_x = dot_and_det(Vkx1, Vkxky1, Vkx2, Vkxky2);
F=imag(log(Ux*Uy_x*(conj(Ux_y))*(conj(Uy))));
A=imag(log(Ux))+imag(log(Uy_x))+imag(log(conj(Ux_y)))+imag(log(conj(Uy)));
Z2 = Z2+(A-F)/(2*pi);
end
end
Z2= mod(Z2, 2)
function dd = dot_and_det(a1,b1,a2,b2) %
x1=a1'*b1;
x2=a2'*b2;
x3=a1'*b2;
x4=a2'*b1;
dd =x1*x2-x3*x4;
end
function [vector_new_1, vector_new_2] = get_vector(H)
[vector,eigenvalue] = eig(H);
[eigenvalue, index]=sort(diag(eigenvalue), 'ascend');
vector_new_2 = vector(:, index(2));
vector_new_1 = vector(:, index(1));
end
function H=Hamiltonian(kx,ky) % BHZ
A=0.3645/5;
B=-0.686/25;
C=0;
D=-0.512/25;
M=-0.01;
H=zeros(4,4);
varepsilon = C-2*D*(2-cos(kx)-cos(ky));
d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky));
d1_d2 = A*(sin(kx)+1j*sin(ky));
H(1, 1) = varepsilon+d3;
H(2, 2) = varepsilon-d3;
H(1, 2) = conj(d1_d2);
H(2, 1) = d1_d2 ;
varepsilon = C-2*D*(2-cos(-kx)-cos(-ky));
d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky));
d1_d2 = A*(sin(-kx)+1j*sin(-ky));
H(3, 3) = varepsilon+d3;
H(4, 4) = varepsilon-d3;
H(3, 4) = d1_d2 ;
H(4, 3) = conj(d1_d2);
end

View File

@@ -1,88 +1,88 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5778
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入pi, cos等
import cmath
import time
def hamiltonian(kx, ky): # BHZ模型
A=0.3645/5
B=-0.686/25
C=0
D=-0.512/25
M=-0.01
matrix = np.zeros((4, 4))*(1+0j)
varepsilon = C-2*D*(2-cos(kx)-cos(ky))
d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky))
d1_d2 = A*(sin(kx)+1j*sin(ky))
matrix[0, 0] = varepsilon+d3
matrix[1, 1] = varepsilon-d3
matrix[0, 1] = np.conj(d1_d2)
matrix[1, 0] = d1_d2
varepsilon = C-2*D*(2-cos(-kx)-cos(-ky))
d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky))
d1_d2 = A*(sin(-kx)+1j*sin(-ky))
matrix[2, 2] = varepsilon+d3
matrix[3, 3] = varepsilon-d3
matrix[2, 3] = d1_d2
matrix[3, 2] = np.conj(d1_d2)
return matrix
def main():
start_clock = time.perf_counter()
delta = 0.1
Z2 = 0 # Z2数
for kx in np.arange(-pi, 0, delta):
print(kx)
for ky in np.arange(-pi, pi, delta):
H = hamiltonian(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数1
vector2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 价带波函数2
H_delta_kx = hamiltonian(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数1
vector_delta_kx2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离kx的波函数2
H_delta_ky = hamiltonian(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数1
vector_delta_ky2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离ky的波函数2
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数1
vector_delta_kx_ky2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离kx和ky的波函数2
Ux = dot_and_det(vector, vector_delta_kx, vector2, vector_delta_kx2)
Uy = dot_and_det(vector, vector_delta_ky, vector2, vector_delta_ky2)
Ux_y = dot_and_det(vector_delta_ky, vector_delta_kx_ky, vector_delta_ky2, vector_delta_kx_ky2)
Uy_x = dot_and_det(vector_delta_kx, vector_delta_kx_ky, vector_delta_kx2, vector_delta_kx_ky2)
F = np.imag(cmath.log(Ux*Uy_x*np.conj(Ux_y)*np.conj(Uy)))
A = np.imag(cmath.log(Ux))+np.imag(cmath.log(Uy_x))+np.imag(cmath.log(np.conj(Ux_y)))+np.imag(cmath.log(np.conj(Uy)))
Z2 = Z2 + (A-F)/(2*pi)
print('Z2 = ', Z2) # Z2数
end_clock = time.perf_counter()
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
def dot_and_det(a1, b1, a2, b2): # 内积组成的矩阵对应的行列式
x1 = np.dot(np.conj(a1), b1)
x2 = np.dot(np.conj(a2), b2)
x3 = np.dot(np.conj(a1), b2)
x4 = np.dot(np.conj(a2), b1)
return x1*x2-x3*x4
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5778
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入pi, cos等
import cmath
import time
def hamiltonian(kx, ky): # BHZ模型
A=0.3645/5
B=-0.686/25
C=0
D=-0.512/25
M=-0.01
matrix = np.zeros((4, 4))*(1+0j)
varepsilon = C-2*D*(2-cos(kx)-cos(ky))
d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky))
d1_d2 = A*(sin(kx)+1j*sin(ky))
matrix[0, 0] = varepsilon+d3
matrix[1, 1] = varepsilon-d3
matrix[0, 1] = np.conj(d1_d2)
matrix[1, 0] = d1_d2
varepsilon = C-2*D*(2-cos(-kx)-cos(-ky))
d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky))
d1_d2 = A*(sin(-kx)+1j*sin(-ky))
matrix[2, 2] = varepsilon+d3
matrix[3, 3] = varepsilon-d3
matrix[2, 3] = d1_d2
matrix[3, 2] = np.conj(d1_d2)
return matrix
def main():
start_clock = time.perf_counter()
delta = 0.1
Z2 = 0 # Z2数
for kx in np.arange(-pi, 0, delta):
print(kx)
for ky in np.arange(-pi, pi, delta):
H = hamiltonian(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数1
vector2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 价带波函数2
H_delta_kx = hamiltonian(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数1
vector_delta_kx2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离kx的波函数2
H_delta_ky = hamiltonian(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数1
vector_delta_ky2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离ky的波函数2
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数1
vector_delta_kx_ky2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离kx和ky的波函数2
Ux = dot_and_det(vector, vector_delta_kx, vector2, vector_delta_kx2)
Uy = dot_and_det(vector, vector_delta_ky, vector2, vector_delta_ky2)
Ux_y = dot_and_det(vector_delta_ky, vector_delta_kx_ky, vector_delta_ky2, vector_delta_kx_ky2)
Uy_x = dot_and_det(vector_delta_kx, vector_delta_kx_ky, vector_delta_kx2, vector_delta_kx_ky2)
F = np.imag(cmath.log(Ux*Uy_x*np.conj(Ux_y)*np.conj(Uy)))
A = np.imag(cmath.log(Ux))+np.imag(cmath.log(Uy_x))+np.imag(cmath.log(np.conj(Ux_y)))+np.imag(cmath.log(np.conj(Uy)))
Z2 = Z2 + (A-F)/(2*pi)
print('Z2 = ', Z2) # Z2数
end_clock = time.perf_counter()
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
def dot_and_det(a1, b1, a2, b2): # 内积组成的矩阵对应的行列式
x1 = np.dot(np.conj(a1), b1)
x2 = np.dot(np.conj(a2), b2)
x3 = np.dot(np.conj(a1), b2)
x4 = np.dot(np.conj(a2), b1)
return x1*x2-x3*x4
if __name__ == '__main__':
main()

View File

@@ -1,98 +1,98 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5778
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入pi, cos等
import cmath
import time
def hamiltonian1(kx, ky): # Half BHZ for spin up
A=0.3645/5
B=-0.686/25
C=0
D=-0.512/25
M=-0.01
matrix = np.zeros((2, 2))*(1+0j)
varepsilon = C-2*D*(2-cos(kx)-cos(ky))
d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky))
d1_d2 = A*(sin(kx)+1j*sin(ky))
matrix[0, 0] = varepsilon+d3
matrix[1, 1] = varepsilon-d3
matrix[0, 1] = np.conj(d1_d2)
matrix[1, 0] = d1_d2
return matrix
def hamiltonian2(kx, ky): # Half BHZ for spin down
A=0.3645/5
B=-0.686/25
C=0
D=-0.512/25
M=-0.01
matrix = np.zeros((2, 2))*(1+0j)
varepsilon = C-2*D*(2-cos(-kx)-cos(-ky))
d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky))
d1_d2 = A*(sin(-kx)+1j*sin(-ky))
matrix[0, 0] = varepsilon+d3
matrix[1, 1] = varepsilon-d3
matrix[0, 1] = d1_d2
matrix[1, 0] = np.conj(d1_d2)
return matrix
def main():
start_clock = time.perf_counter()
delta = 0.1
for i0 in range(2):
if i0 == 0:
hamiltonian = hamiltonian1
else:
hamiltonian = hamiltonian2
chern_number = 0 # 陈数初始化
for kx in np.arange(-pi, pi, delta):
print(kx)
for ky in np.arange(-pi, pi, delta):
H = hamiltonian(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
# 陈数(chern number)
chern_number = chern_number + F
chern_number = chern_number/(2*pi*1j)
if i0 == 0:
chern_number_up = chern_number
else:
chern_number_down = chern_number
spin_chern_number = (chern_number_up-chern_number_down)/2
print('Chern number for spin up = ', chern_number_up)
print('Chern number for spin down = ', chern_number_down)
print('Spin chern number = ', spin_chern_number)
end_clock = time.perf_counter()
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
if __name__ == '__main__':
main()
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5778
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入pi, cos等
import cmath
import time
def hamiltonian1(kx, ky): # Half BHZ for spin up
A=0.3645/5
B=-0.686/25
C=0
D=-0.512/25
M=-0.01
matrix = np.zeros((2, 2))*(1+0j)
varepsilon = C-2*D*(2-cos(kx)-cos(ky))
d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky))
d1_d2 = A*(sin(kx)+1j*sin(ky))
matrix[0, 0] = varepsilon+d3
matrix[1, 1] = varepsilon-d3
matrix[0, 1] = np.conj(d1_d2)
matrix[1, 0] = d1_d2
return matrix
def hamiltonian2(kx, ky): # Half BHZ for spin down
A=0.3645/5
B=-0.686/25
C=0
D=-0.512/25
M=-0.01
matrix = np.zeros((2, 2))*(1+0j)
varepsilon = C-2*D*(2-cos(-kx)-cos(-ky))
d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky))
d1_d2 = A*(sin(-kx)+1j*sin(-ky))
matrix[0, 0] = varepsilon+d3
matrix[1, 1] = varepsilon-d3
matrix[0, 1] = d1_d2
matrix[1, 0] = np.conj(d1_d2)
return matrix
def main():
start_clock = time.perf_counter()
delta = 0.1
for i0 in range(2):
if i0 == 0:
hamiltonian = hamiltonian1
else:
hamiltonian = hamiltonian2
chern_number = 0 # 陈数初始化
for kx in np.arange(-pi, pi, delta):
print(kx)
for ky in np.arange(-pi, pi, delta):
H = hamiltonian(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
# 陈数(chern number)
chern_number = chern_number + F
chern_number = chern_number/(2*pi*1j)
if i0 == 0:
chern_number_up = chern_number
else:
chern_number_down = chern_number
spin_chern_number = (chern_number_up-chern_number_down)/2
print('Chern number for spin up = ', chern_number_up)
print('Chern number for spin down = ', chern_number_down)
print('Spin chern number = ', spin_chern_number)
end_clock = time.perf_counter()
print('CPU执行时间(min)=', (end_clock-start_clock)/60)
if __name__ == '__main__':
main()

View File

@@ -1,83 +1,83 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6896
"""
import numpy as np
from math import *
import matplotlib.pyplot as plt
import time
import cmath
def hamiltonian(kx,ky,kz): # Weyl semimetal
A = 1
M0 = 1
M1 = 1
H = A*(sin(kx)*sigma_x()+sin(ky)*sigma_y())+(M0-M1*(2*(1-cos(kx))+2*(1-cos(ky))+2*(1-cos(kz))))*sigma_z()
return H
def sigma_x():
return np.array([[0, 1],[1, 0]])
def sigma_y():
return np.array([[0, -1j],[1j, 0]])
def sigma_z():
return np.array([[1, 0],[0, -1]])
def main():
start_time = time.time()
n = 50
delta = 2*pi/n
kz_array = np.arange(-pi, pi, 0.1)
chern_number_array = np.zeros(kz_array.shape[0])
i0 = 0
for kz in kz_array:
print('kz=', kz)
chern_number = 0 # 陈数初始化
for kx in np.arange(-pi, pi, 2*pi/n):
for ky in np.arange(-pi, pi, 2*pi/n):
H = hamiltonian(kx, ky, kz)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian(kx+delta, ky, kz)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian(kx, ky+delta, kz)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta, kz)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
# 陈数(chern number)
chern_number = chern_number + F
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number, '\n')
chern_number_array[i0] = np.real(chern_number)
i0 += 1
end_time = time.time()
print('运行时间(min)=', (end_time-start_time)/60)
plt.plot(kz_array, chern_number_array, 'o-')
plt.xlabel('kz')
plt.ylabel('Chern number')
plt.show()
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6896
"""
import numpy as np
from math import *
import matplotlib.pyplot as plt
import time
import cmath
def hamiltonian(kx,ky,kz): # Weyl semimetal
A = 1
M0 = 1
M1 = 1
H = A*(sin(kx)*sigma_x()+sin(ky)*sigma_y())+(M0-M1*(2*(1-cos(kx))+2*(1-cos(ky))+2*(1-cos(kz))))*sigma_z()
return H
def sigma_x():
return np.array([[0, 1],[1, 0]])
def sigma_y():
return np.array([[0, -1j],[1j, 0]])
def sigma_z():
return np.array([[1, 0],[0, -1]])
def main():
start_time = time.time()
n = 50
delta = 2*pi/n
kz_array = np.arange(-pi, pi, 0.1)
chern_number_array = np.zeros(kz_array.shape[0])
i0 = 0
for kz in kz_array:
print('kz=', kz)
chern_number = 0 # 陈数初始化
for kx in np.arange(-pi, pi, 2*pi/n):
for ky in np.arange(-pi, pi, 2*pi/n):
H = hamiltonian(kx, ky, kz)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数
H_delta_kx = hamiltonian(kx+delta, ky, kz)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数
H_delta_ky = hamiltonian(kx, ky+delta, kz)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta, kz)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数
Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx))
Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky))
Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky))
Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky))
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
# 陈数(chern number)
chern_number = chern_number + F
chern_number = chern_number/(2*pi*1j)
print('Chern number = ', chern_number, '\n')
chern_number_array[i0] = np.real(chern_number)
i0 += 1
end_time = time.time()
print('运行时间(min)=', (end_time-start_time)/60)
plt.plot(kz_array, chern_number_array, 'o-')
plt.xlabel('kz')
plt.ylabel('Chern number')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,66 +1,66 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6896
"""
import numpy as np
from math import *
import matplotlib.pyplot as plt
def main():
k1 = np.arange(-pi, pi, 0.05)
k2 = np.arange(-pi, pi, 0.05)
plot_bands_two_dimension(k1, k2, hamiltonian)
def hamiltonian(kx,kz,ky=0): # Weyl semimetal
A = 1
M0 = 1
M1 = 1
H = A*(sin(kx)*sigma_x()+sin(ky)*sigma_y())+(M0-M1*(2*(1-cos(kx))+2*(1-cos(ky))+2*(1-cos(kz))))*sigma_z()
return H
def sigma_x():
return np.array([[0, 1],[1, 0]])
def sigma_y():
return np.array([[0, -1j],[1j, 0]])
def sigma_z():
return np.array([[1, 0],[0, -1]])
def plot_bands_two_dimension(k1, k2, hamiltonian):
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
dim = hamiltonian(0, 0).shape[0]
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1, dim))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
matrix0 = hamiltonian(k10, k20)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
fig = plt.figure()
ax = fig.gca(projection='3d')
k1, k2 = np.meshgrid(k1, k2)
for dim0 in range(dim):
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
plt.xlabel('kx')
plt.ylabel('kz')
ax.set_zlabel('E')
plt.show()
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6896
"""
import numpy as np
from math import *
import matplotlib.pyplot as plt
def main():
k1 = np.arange(-pi, pi, 0.05)
k2 = np.arange(-pi, pi, 0.05)
plot_bands_two_dimension(k1, k2, hamiltonian)
def hamiltonian(kx,kz,ky=0): # Weyl semimetal
A = 1
M0 = 1
M1 = 1
H = A*(sin(kx)*sigma_x()+sin(ky)*sigma_y())+(M0-M1*(2*(1-cos(kx))+2*(1-cos(ky))+2*(1-cos(kz))))*sigma_z()
return H
def sigma_x():
return np.array([[0, 1],[1, 0]])
def sigma_y():
return np.array([[0, -1j],[1j, 0]])
def sigma_z():
return np.array([[1, 0],[0, -1]])
def plot_bands_two_dimension(k1, k2, hamiltonian):
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
dim = hamiltonian(0, 0).shape[0]
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1, dim))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
matrix0 = hamiltonian(k10, k20)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
fig = plt.figure()
ax = fig.gca(projection='3d')
k1, k2 = np.meshgrid(k1, k2)
for dim0 in range(dim):
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
plt.xlabel('kx')
plt.ylabel('kz')
ax.set_zlabel('E')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -1,159 +1,159 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8536
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import time
def hamiltonian(k1, k2, t1=2.82, a=1/sqrt(3)): # 石墨烯哈密顿量a为原子间距不赋值的话默认为1/sqrt(3)
h = np.zeros((2, 2), dtype=complex)
h[0, 0] = 0.28/2
h[1, 1] = -0.28/2
h[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h[0, 1] = h[1, 0].conj()
return h
def main():
start_time = time.time()
n = 400 # 取点密度
delta = 1e-10 # 求导的偏离量
kx_array = np.linspace(-2*pi, 2*pi, n)
ky_array = np.linspace(-2*pi, 2*pi, n)
for band in range(2):
F_all = np.zeros((ky_array.shape[0], ky_array.shape[0])) # 贝里曲率
j0 = 0
for kx in kx_array:
print(kx)
i0 = 0
for ky in ky_array:
H = hamiltonian(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 价带波函数
# print(np.argsort(np.real(eigenvalue))[0]) # 排序索引(从小到大)
# print(eigenvalue) # 排序前的本征值
# print(np.sort(np.real(eigenvalue))) # 排序后的本征值(从小到大)
H_delta_kx = hamiltonian(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离kx的波函数
# vector_delta_kx = find_vector_with_the_same_gauge(vector_delta_kx, vector) # 如果波函数不连续需要使用这个
H_delta_ky = hamiltonian(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离ky的波函数
# vector_delta_ky = find_vector_with_the_same_gauge(vector_delta_ky, vector) # 如果波函数不连续需要使用这个
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离kx和ky的波函数
# vector_delta_kx_ky = find_vector_with_the_same_gauge(vector_delta_kx_ky, vector) # 如果波函数不连续需要使用这个
# 价带的波函数的贝里联络(berry connection) # 求导后内积
A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Axx分量
A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ayy分量
A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax
A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay
# 贝里曲率(berry curvature)
F = ((A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta)*1j
# print(F)
F_all[i0, j0] = np.real(F)
i0 += 1
j0 += 1
if band==0:
plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='k_x (pi)', ylabel='k_y (pi)', zlabel='Berry curvature', title='Valence Band', rcount=300, ccount=300)
else:
plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='k_x (pi)', ylabel='k_y (pi)', zlabel='Berry curvature', title='Conductance Band', rcount=300, ccount=300)
# import guan
# if band==0:
# guan.plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='kx', ylabel='ky', zlabel='Berry curvature', title='Valence Band', rcount=300, ccount=300)
# else:
# guan.plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='kx', ylabel='ky', zlabel='Berry curvature', title='Conductance Band', rcount=300, ccount=300)
end_time = time.time()
print('运行时间(min)=', (end_time-start_time)/60)
def find_vector_with_the_same_gauge(vector_1, vector_0):
# 寻找近似的同一的规范
phase_1_pre = 0
phase_2_pre = pi
n_test = 10001
for i0 in range(n_test):
test_1 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_1_pre) - vector_0))
test_2 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_2_pre) - vector_0))
if test_1 < 1e-9:
phase = phase_1_pre
# print('Done with i0=', i0)
break
if i0 == n_test-1:
phase = phase_1_pre
print('Gauge Not Found with i0=', i0)
if test_1 < test_2:
if i0 == 0:
phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
else:
phase_1 = phase_1_pre
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
else:
if i0 == 0:
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2
else:
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
phase_2 = phase_2_pre
phase_1_pre = phase_1
phase_2_pre = phase_2
vector_1 = vector_1*cmath.exp(1j*phase)
# print('二分查找找到的规范=', phase)
return vector_1
def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', fontsize=20, labelsize=15, show=1, save=0, filename='a', file_format='.jpg', dpi=300, z_min=None, z_max=None, rcount=100, ccount=100):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
matrix = np.array(matrix)
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
plt.subplots_adjust(bottom=0.1, right=0.65)
x_array, y_array = np.meshgrid(x_array, y_array)
if len(matrix.shape) == 2:
surf = ax.plot_surface(x_array, y_array, matrix, rcount=rcount, ccount=ccount, cmap=cm.coolwarm, linewidth=0, antialiased=False)
elif len(matrix.shape) == 3:
for i0 in range(matrix.shape[2]):
surf = ax.plot_surface(x_array, y_array, matrix[:,:,i0], rcount=rcount, ccount=ccount, cmap=cm.coolwarm, linewidth=0, antialiased=False)
ax.set_title(title, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_zlabel(zlabel, fontsize=fontsize, fontfamily='Times New Roman')
ax.zaxis.set_major_locator(LinearLocator(5))
ax.zaxis.set_major_formatter('{x:.2f}')
if z_min!=None or z_max!=None:
if z_min==None:
z_min=matrix.min()
if z_max==None:
z_max=matrix.max()
ax.set_zlim(z_min, z_max)
ax.tick_params(labelsize=labelsize)
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
[label.set_fontname('Times New Roman') for label in labels]
cax = plt.axes([0.8, 0.1, 0.05, 0.8])
cbar = fig.colorbar(surf, cax=cax)
cbar.ax.tick_params(labelsize=labelsize)
for l in cbar.ax.yaxis.get_ticklabels():
l.set_family('Times New Roman')
if save == 1:
plt.savefig(filename+file_format, dpi=dpi)
if show == 1:
plt.show()
plt.close('all')
if __name__ == '__main__':
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8536
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import time
def hamiltonian(k1, k2, t1=2.82, a=1/sqrt(3)): # 石墨烯哈密顿量a为原子间距不赋值的话默认为1/sqrt(3)
h = np.zeros((2, 2), dtype=complex)
h[0, 0] = 0.28/2
h[1, 1] = -0.28/2
h[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h[0, 1] = h[1, 0].conj()
return h
def main():
start_time = time.time()
n = 400 # 取点密度
delta = 1e-10 # 求导的偏离量
kx_array = np.linspace(-2*pi, 2*pi, n)
ky_array = np.linspace(-2*pi, 2*pi, n)
for band in range(2):
F_all = np.zeros((ky_array.shape[0], ky_array.shape[0])) # 贝里曲率
j0 = 0
for kx in kx_array:
print(kx)
i0 = 0
for ky in ky_array:
H = hamiltonian(kx, ky)
eigenvalue, eigenvector = np.linalg.eig(H)
vector = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 价带波函数
# print(np.argsort(np.real(eigenvalue))[0]) # 排序索引(从小到大)
# print(eigenvalue) # 排序前的本征值
# print(np.sort(np.real(eigenvalue))) # 排序后的本征值(从小到大)
H_delta_kx = hamiltonian(kx+delta, ky)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx)
vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离kx的波函数
# vector_delta_kx = find_vector_with_the_same_gauge(vector_delta_kx, vector) # 如果波函数不连续需要使用这个
H_delta_ky = hamiltonian(kx, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_ky)
vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离ky的波函数
# vector_delta_ky = find_vector_with_the_same_gauge(vector_delta_ky, vector) # 如果波函数不连续需要使用这个
H_delta_kx_ky = hamiltonian(kx+delta, ky+delta)
eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky)
vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离kx和ky的波函数
# vector_delta_kx_ky = find_vector_with_the_same_gauge(vector_delta_kx_ky, vector) # 如果波函数不连续需要使用这个
# 价带的波函数的贝里联络(berry connection) # 求导后内积
A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Axx分量
A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ayy分量
A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax
A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay
# 贝里曲率(berry curvature)
F = ((A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta)*1j
# print(F)
F_all[i0, j0] = np.real(F)
i0 += 1
j0 += 1
if band==0:
plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='k_x (pi)', ylabel='k_y (pi)', zlabel='Berry curvature', title='Valence Band', rcount=300, ccount=300)
else:
plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='k_x (pi)', ylabel='k_y (pi)', zlabel='Berry curvature', title='Conductance Band', rcount=300, ccount=300)
# import guan
# if band==0:
# guan.plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='kx', ylabel='ky', zlabel='Berry curvature', title='Valence Band', rcount=300, ccount=300)
# else:
# guan.plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='kx', ylabel='ky', zlabel='Berry curvature', title='Conductance Band', rcount=300, ccount=300)
end_time = time.time()
print('运行时间(min)=', (end_time-start_time)/60)
def find_vector_with_the_same_gauge(vector_1, vector_0):
# 寻找近似的同一的规范
phase_1_pre = 0
phase_2_pre = pi
n_test = 10001
for i0 in range(n_test):
test_1 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_1_pre) - vector_0))
test_2 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_2_pre) - vector_0))
if test_1 < 1e-9:
phase = phase_1_pre
# print('Done with i0=', i0)
break
if i0 == n_test-1:
phase = phase_1_pre
print('Gauge Not Found with i0=', i0)
if test_1 < test_2:
if i0 == 0:
phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
else:
phase_1 = phase_1_pre
phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2
else:
if i0 == 0:
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2
else:
phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2
phase_2 = phase_2_pre
phase_1_pre = phase_1
phase_2_pre = phase_2
vector_1 = vector_1*cmath.exp(1j*phase)
# print('二分查找找到的规范=', phase)
return vector_1
def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', fontsize=20, labelsize=15, show=1, save=0, filename='a', file_format='.jpg', dpi=300, z_min=None, z_max=None, rcount=100, ccount=100):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
matrix = np.array(matrix)
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
plt.subplots_adjust(bottom=0.1, right=0.65)
x_array, y_array = np.meshgrid(x_array, y_array)
if len(matrix.shape) == 2:
surf = ax.plot_surface(x_array, y_array, matrix, rcount=rcount, ccount=ccount, cmap=cm.coolwarm, linewidth=0, antialiased=False)
elif len(matrix.shape) == 3:
for i0 in range(matrix.shape[2]):
surf = ax.plot_surface(x_array, y_array, matrix[:,:,i0], rcount=rcount, ccount=ccount, cmap=cm.coolwarm, linewidth=0, antialiased=False)
ax.set_title(title, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_zlabel(zlabel, fontsize=fontsize, fontfamily='Times New Roman')
ax.zaxis.set_major_locator(LinearLocator(5))
ax.zaxis.set_major_formatter('{x:.2f}')
if z_min!=None or z_max!=None:
if z_min==None:
z_min=matrix.min()
if z_max==None:
z_max=matrix.max()
ax.set_zlim(z_min, z_max)
ax.tick_params(labelsize=labelsize)
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
[label.set_fontname('Times New Roman') for label in labels]
cax = plt.axes([0.8, 0.1, 0.05, 0.8])
cbar = fig.colorbar(surf, cax=cax)
cbar.ax.tick_params(labelsize=labelsize)
for l in cbar.ax.yaxis.get_ticklabels():
l.set_family('Times New Roman')
if save == 1:
plt.savefig(filename+file_format, dpi=dpi)
if show == 1:
plt.show()
plt.close('all')
if __name__ == '__main__':
main()

Some files were not shown because too many files have changed in this diff Show More