Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我收到这个错误“无法取消打包不可iterable的非类型对象”?_Python_Numerical Analysis - Fatal编程技术网

Python 为什么我收到这个错误“无法取消打包不可iterable的非类型对象”?

Python 为什么我收到这个错误“无法取消打包不可iterable的非类型对象”?,python,numerical-analysis,Python,Numerical Analysis,我用高斯求积来计算一个积分,我得到了这个误差。。。我以前用过这个,效果很好。我错过了一些简单的东西吗 def gaussxw(N): #Initial approximation to roots of Legendre polynomial a = linspace(3,4*N-1,N)/(4*N+2) z=cos(pi*a+1/(8*N*N*tan(a))) #Find roots using Newton's method

我用高斯求积来计算一个积分,我得到了这个误差。。。我以前用过这个,效果很好。我错过了一些简单的东西吗

def gaussxw(N):
        #Initial approximation to roots of Legendre polynomial
        a = linspace(3,4*N-1,N)/(4*N+2)
        z=cos(pi*a+1/(8*N*N*tan(a)))
        #Find roots using Newton's method
        epsilon=1e-15
        delta=1.0
        while delta>epsilon:
                p0=ones(N,float)
                p1=copy(z)
                for k in range(1,N):
                        p0,p1 = p1,((2*k+1)*z*p1-k*p0)/(k+1)
                dp = (N+1)*(p0-z*p1)/(1-z*z)
                dz = p1/dp
                z-=dz
                delta=max(abs(dz))

         #Calculate the weights
        w = 2*(N+1)*(N+1)/(N*N*(1-z*z)*dp*dp)

def uncertainty(z,wavefunctionmod):
        return 2*(z**2*abs(wavefunctionmod)**2)/(1-z)**4
def wavefunctionmod(z,Hmod):          #Creating the wavefunction
        return (Hmod*e**(-(z/(1-z))**2/2))/sqrt((2**n)*factorial(n)*sqrt(pi))
def Hmod(n,z):             #Function to create the hermite polynomial for some value of 'n'
        Hermite=[]
        Hermite.append(1)
        Hermite.append(2*(z/(1-z)))
        for j in range(1,n):
            Hermite.append(2*(z/(1-z))*Hermite[j]-2*(j)*Hermite[j-1])
        return Hermite[n]

n=int(input("Please enter in a value for n:"))
N=100
a = 0.0
b = 1.0

z,w=gaussxw(N)
zp=0.5*(b-a)*z+0.5*(b+a)
wp=0.5*(b-a)*w
#Perform the integration
s=0.0
for k in range(N):
        s+=wp[k]*uncertainty(zp[k],wavefunctionmod(zp[k],Hmod(n,zp[k])))
print(s)

Please enter in a value for n:5
Traceback (most recent call last):
File "Problem3.py", line 132, in <module>
z,w=gaussxw(N)
gaussxw不返回值,这意味着它将隐式返回None


然后,您尝试将此None值解包到z,w z,w=gaussxwN中,由于没有两个值要解包,因此该错误将失败。

请共享整个错误消息以及。gaussxw函数不返回任何内容,因此它将隐式返回None。然后尝试解包:z,w=gaussxwN,因此出现错误。。。