##### python odeint keeps giving me size of array error
 python odeint keeps giving me size of array error kiyoshi7 Silly Frenchman Posts: 43 Threads: 16 Joined: Oct 2016 Reputation: 0 Nov-01-2018, 01:49 AM hi I'm trying to run the following code to solve Schrodinger equation in a infinite well with a barrier in themiddle but when I try to run the code I keep getting this error: ``````Error:Traceback (most recent call last): File "C:/.../Desktop/S2.py", line 45, in psi_b.append(Wave_function(e1)) # for each energy e1 find the the psi(x) at x = b File "C:/Users/Daniel/Desktop/S2.py", line 28, in Wave_function psi = odeint(SE, psi0, x) File "C:...\Python36-32\lib\site-packages\scipy\integrate\odepack.py", line 233, in odeint int(bool(tfirst))) RuntimeError: The size of the array returned by func (2) does not match the size of y0 (4) .``````can someone tell me where I am getting it wronge on this script? the original code that I am trying to modify is here https://helentronica.com/2014/09/04/quan...he-python/ this is the part that I am trying to run ```from pylab import * from scipy.integrate import odeint from scipy.optimize import brentq def V(x): """ Potential function in the finite square well. Width is L and value is global variable Vo """ L = 1 if abs(x) > L: return 0 else: return Vo def SE(psi, x): state0 = psi[1] state1 = 2.0*(V(x) - E)*psi[0] return array([state0, state1]) def Wave_function(energy): """ Calculates wave function psi for the given value of energy E and returns value at point b """ global psi global E E = energy psi = odeint(SE, psi0, x) return psi[-3,-2,-1,0] N = 1000 # number of points to take psi = np.array([0, 0, 0, 0, 0, 0]) E = 0.0 # global variable Energy needed for Sch.Eq, changed in function "Wave function" psi0 = np.array([0,1,1,0]) b = 0 # point outside of well where we need to check if the function diverges a = 1 a2 = a*2 ba = a2+1 x = linspace(-b, ba, N) # x-axis Vo = 20 en = linspace(0, Vo, 100) # vector of energies where we look for the stable states psi_b = [] # vector of wave function at x = b for all of the energies in en for e1 in en: psi_b.append(Wave_function(e1)) # for each energy e1 find the the psi(x) at x = b E_zeroes = find_all_zeroes(en, psi_b) # now find the energies where psi(b) = 0 ``` Reply Posts: 1,129 Threads: 40 Joined: Sep 2016 Reputation: 46 Nov-01-2018, 02:03 AM (This post was last modified: Nov-01-2018, 02:03 AM by j.crater.) According to error message, it seems like the array sizes aren't matching ```# line 18: return array([state0, state1]) # array of size 2 # line 35: psi0 = np.array([0,1,1,0]) # array of size 4 # line 28: psi = odeint(SE, psi0, x) # array returned by SE (line 18) and psi0 should probably be of same size ```And looking at the original code, the author has psi0 of size 2. Reply

 Possibly Related Threads… Thread Author Replies Views Last Post cannot reshape array of size 0 into shape Roro 2 1,242 Jun-14-2020, 11:28 AM Last Post: Roro Mukhanov equation + odeint Messier087 0 426 Mar-28-2020, 04:03 PM Last Post: Messier087 Odeint to solve Mukhanov equation Messier087 4 549 Feb-17-2020, 05:05 PM Last Post: Messier087 TensorFlow get error - array with more than one element is ambiguous vokoyo 3 1,181 Nov-07-2019, 01:12 PM Last Post: ThomasL How to get the size of a numpy array? mcgrim 2 907 Mar-23-2019, 02:25 PM Last Post: perfringo odeint to solve Schrodinger equation kiyoshi7 14 5,385 Nov-23-2018, 11:49 AM Last Post: kiyoshi7 The size of the array returned by func (1) does not match usmankhan 0 2,176 Jan-16-2018, 12:27 PM Last Post: usmankhan error in script "Expected 2D array, got 1D array instead:" drogontargaryen 0 15,823 Aug-07-2017, 04:32 PM Last Post: drogontargaryen

Forum Jump:

### User Panel Messages

##### Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020