numpy.linalg.eig 创建的特征向量有点而不是数据
eigenvectors created by numpy.linalg.eig have dots instead of data
我想计算 20k*20k 矩阵的复特征向量(薛定谔方程的 Psi 函数),但总是得到这样的结果:
[ 2.99009782e-09 -1.12381299e-08 -2.82346868e-08 ..., 6.20967928e-34
-4.80675528e-34 -3.84848719e-35]
[ 4.07337553e-08 -1.45976681e-07 -3.47961439e-07 ..., 7.43558322e-34
-5.74815572e-34 -4.61317607e-35]
[ 5.51921102e-07 -1.88491289e-06 -4.26000711e-06 ..., 9.29535407e-34
-7.15304083e-34 -5.78846547e-35]
据我了解只是把部分数据换成了点,很奇怪。在文件中保存数据可能有问题?附上我的代码:
import numpy as np
import math
import scipy.linalg as la
from numpy.linalg import eigvalsh
def potential(i):
return -1/(10*(math.cos((i/2-5)*math.pi/10)-1)*(math.cos((i/2-5)*math.pi/10)-1)+1)
def element(i,j):
if i==j:
return 0.1524+potential(i)
if abs(i-j)==1:
return -0.1524/2
return 0
I = 1j
a=[]
for i in range(0,2000):
b=[]
for j in range(0,2000):
b.append(element(i,j))
a.append(b)
arr = np.array(a)
print('matrix created')
eigvals, eigvecs = la.eig(arr)
print('eigenvalues and eigenvectors calculated')
eigvals = eigvals.real
f = open('Energies.txt', 'w')
for element in eigvals:
f.write(str(element)+'\n')
print("eigenvalues stored")
f = open('Psi_functions.txt', 'w')
for element in eigvecs:
f.write(str(element)+'\n')
np.savetxt('Energies.txt', eigvals)
np.savetxt('Psi_functions.txt', eigvecs)
使用np.loadtxt
加载它们:
eigvals2 = np.loadtxt('Energies.txt')
eigvecs2 = np.loadtxt('Psi_functions.txt')
>>> (eigvals == eigvals2).all()
True
>>> (eigvecs == eigvecs2).all()
True
您可以使用:
for element in eigvecs:
for e in element:
f.write(str(e)+' ')
f.write('\n')
但要注意文件的大小,大约有 100 MB。
我想计算 20k*20k 矩阵的复特征向量(薛定谔方程的 Psi 函数),但总是得到这样的结果:
[ 2.99009782e-09 -1.12381299e-08 -2.82346868e-08 ..., 6.20967928e-34
-4.80675528e-34 -3.84848719e-35]
[ 4.07337553e-08 -1.45976681e-07 -3.47961439e-07 ..., 7.43558322e-34
-5.74815572e-34 -4.61317607e-35]
[ 5.51921102e-07 -1.88491289e-06 -4.26000711e-06 ..., 9.29535407e-34
-7.15304083e-34 -5.78846547e-35]
据我了解只是把部分数据换成了点,很奇怪。在文件中保存数据可能有问题?附上我的代码:
import numpy as np
import math
import scipy.linalg as la
from numpy.linalg import eigvalsh
def potential(i):
return -1/(10*(math.cos((i/2-5)*math.pi/10)-1)*(math.cos((i/2-5)*math.pi/10)-1)+1)
def element(i,j):
if i==j:
return 0.1524+potential(i)
if abs(i-j)==1:
return -0.1524/2
return 0
I = 1j
a=[]
for i in range(0,2000):
b=[]
for j in range(0,2000):
b.append(element(i,j))
a.append(b)
arr = np.array(a)
print('matrix created')
eigvals, eigvecs = la.eig(arr)
print('eigenvalues and eigenvectors calculated')
eigvals = eigvals.real
f = open('Energies.txt', 'w')
for element in eigvals:
f.write(str(element)+'\n')
print("eigenvalues stored")
f = open('Psi_functions.txt', 'w')
for element in eigvecs:
f.write(str(element)+'\n')
np.savetxt('Energies.txt', eigvals)
np.savetxt('Psi_functions.txt', eigvecs)
使用np.loadtxt
加载它们:
eigvals2 = np.loadtxt('Energies.txt')
eigvecs2 = np.loadtxt('Psi_functions.txt')
>>> (eigvals == eigvals2).all()
True
>>> (eigvecs == eigvecs2).all()
True
您可以使用:
for element in eigvecs:
for e in element:
f.write(str(e)+' ')
f.write('\n')
但要注意文件的大小,大约有 100 MB。