用Python绘制概率密度函数

2024-10-04 05:33:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要在Python中画出与时间无关的薛定谔方程的概率密度函数。我需要用方程的特征值和特征向量(特征函数)来做这个。在

我没有问题解决的特征值和特征向量,但我不知道如何绘制他们,我尝试了许多不同的方法。也许我误解了这个问题?在

每个能级(n)应绘制一次图形。我有两个列表,一个是特征向量,一个是特征值(只有每一个的实分量)。这两个列表都是按照相对于特征值的数字顺序排序的,这样特征向量的列表被排序以便eigvects[0]与{}相关联。在

以下是我的代码的相关部分:

from __future__ import division
import numpy as np
from scipy import linalg
from math import trunc
import matplotlib.pyplot as plt

#infite square well from 0 to 1

upper=1
lower=0

#step size t

t=10


...  #in this omitted block, the gradient is computed


#D is the gradient 

D*=1/(dx*dx)

#hamiltonian operator

H=-.5*D

#solves the eigenvalues and eigenvectors

eigs=linalg.eig(H)

eigvals=np.real(eigs[0])
eigvects=np.real(eigs[1])


... #in this omitted block, the two lists are sorted


plt.plot(range(0,n),eigvects[0]) #I thought this would graph the probability density function for the first energy level, but it just graphs nonsense
plt.show()

我已经确认了我的特征值和特征向量是正确的。在

我试着让图形看起来像这样(不是格式,只是曲线):

enter image description here

我不需要为我编写代码,我只想知道在绘制这些图形时从何处开始。谢谢!在

根据评论中的一个问题,这里是一个eigvals的示例列表和t=3时的eigvects示例列表:

^{pr2}$

Tags: thefromimport图形列表排序np绘制