#### Solving Schrodinger equation: ValueError: setting an array element with a sequence.

``````Traceback (most recent call last):
File "C:/Users/Utente/Desktop/schrodinge.py", line 43, in <module>
out=odeint(schrodinger,init,x,(E,))
File "C:\Users\Utente\AppData\Local\Programs\Python\Python37-32\lib\site-packages\scipy\integrate\odepack.py", line 233, in odeint
int(bool(tfirst)))
File "C:/Users/Utente/Desktop/schrodinge.py", line 18, in schrodinger
return np.array([g0,g1])
ValueError: setting an array element with a sequence.
``````

``````    import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint

def schrodinger(state,x,k):
''' system of 1st order differential equations to integrate.
The Schrodinger equation for a free particle with wave vector,
k**2 = 2m(E-U)/hbar**2

args:
state - array: psi[0] - Psi(x),  psi[1]= d/dx Psi(x).  Wave function and it's derivative.
'''
g0 = state[1]
g1 = -2*(E-Vx)*state[0]
return np.array([g0,g1])

L = 25
U0 = (L/2)**2
x1= np.arange(0., L, 0.01)
x2= np.arange(-L, 0, 0.01)
x3= np.arange(L, 2*L, 0.01)

V1 = 0*x1
V2 = U0 - (x1-(L/2))**2

Vx = np.concatenate((V1,V2,V1))
x = np.concatenate((x2,x1,x3))

fig = plt.figure(num=1, figsize=(10,6))
fig.clf()

ax1.plot(x,Vx)

init=[1.,0] # the initial condition, [ Psi, d/dx Psi] at x=0.
E_values = [U0/2,U0,2*U0]

for E in E_values:
out=odeint(schrodinger,init,x,(E,))
ax2.plot(x,out[:,0])

fig.canvas.draw()

fig.show()
``````

3 如何解决ValueError：设置具有序列的数组元素？

4 如何解决“ ValueError：设置具有序列的数组元素”？

5 薛定inger方程 解决方案存在问题

2018-11-19 12:56:53 0 13   odeint
6 改变薛定inger方程的比例

2016-11-10 02:11:53 1 81   scaling
8 如何解决这种类型的错误“ ValueError：设置具有序列的数组元素”？

2020-07-20 13:08:49 0 53   k-means
9 工作和解决ValueError在数据帧上设置具有序列的数组元素

10 ValueError：设置具有序列Keras的数组元素

2017-10-17 15:52:36 1 1295   hybrid