IndexError: index 3 is out of bounds for axis 0 with size 2

1
D[i][j+1] = - u_med[i+1]/(delta_r[i]*delta_r[i+1])
     

IndexError: index 3 is out of bounds for axis 0 with size 2

I already had another problem with this code and I asked here , but the problem now is this.

I'm working with the one-dimensional Schrödinger equation on a variable grid ... So I'm writing it in matrix form, with a symmetric tridiagonal N x N matrix.

I tried to use np.zeros because before I was giving another error because I was trying to access values in empty lists.

When I try to write np.zeros ((n, n)), it gives the following error:

D[i][j+1] = - u_med[i+1]/(delta_r[i]*delta_r[i+1])
     

ValueError: setting an array element with a sequence.

How can I reverse this?

n = 51
D = np.zeros((n,2))
for i in range(2,n):
  for j in range(2,n):
    if i == j:
      D[i][j+1] = - u_med[i+1]/(delta_r[i]*delta_r[i+1])
      t1 = u_med[i+1]/(delta_r[i]*delta_r[i])
      t2 = u_med[i]/(delta_r[i]*delta_r[i])
      D[i][j]= t1 + t2 + V[i]
      D[i+1][j]= - u_med[i+1]/(delta_r[i]*delta_r[i+1])
    
asked by anonymous 08.05.2018 / 06:39

0 answers