I’m working on a linear variational problem for a general PIB and I keep encountering the same problem, and I know its a rather simple solution. Any suggestions?
JavaScript
x
42
42
1
import numpy as np
2
3
import scipy.integrate as sp
4
#Parameters
5
alpha = 0.1
6
L = 10.0
7
N = 5
8
x = np.linspace(0,L,1000)
9
#Matrix elements linear combination components
10
def f(x,n,L):
11
return(np.sqrt(2./L)*np.sin(n*np.pi*x/L))
12
def f1(x,m,L):
13
return( np.sqrt(2./L)*np.sin(m*np.pi*x/L))
14
15
#Linear Potential
16
def V(x):
17
return( alpha*x)
18
#Matrix element functions to integrate
19
def Int_1(x,n,m,L):
20
return(f1(x,m,L)*f(x,n,L)+f1(x,m,L)*V(x)*f(x,n,L))
21
def Int_2(x,m,n,L):
22
return(f1(x,m,L)*V(x)*f(x,n,L))
23
# Tring to integrate the matrix components
24
def c(m,n,L):
25
return(sp.quad(Int_1,0,L, args = (m,n,L), limit = 100)[0])
26
def c1(m,n,L):
27
return(sp.quad(Int_2,0,L, args = (m,n,L), limit = 100)[0])
28
# Generating the matrix
29
def cal_Hmn(m,n):
30
if m == n:
31
c(m,n,L)
32
elif(m+n)%2 ==1:
33
c1(m,n,L)
34
else:
35
return(0)
36
37
#Filling the Matrix
38
H = np.zeros((N,N), float)
39
for i in range(N):
40
for j in range(N):
41
H[i,j] = cal_Hmn(i+1, j+1)
42
The problem is 100% in the integration of the matrix elements, but I cannot figure out how to rectify it.
Thanks!
Advertisement
Answer
It runs for me:
JavaScript
1
2
1
print(H)
2
returns
JavaScript
1
6
1
[[nan nan 0. nan 0.]
2
[nan nan nan 0. nan]
3
[ 0. nan nan nan 0.]
4
[nan 0. nan nan nan]
5
[ 0. nan 0. nan nan]]
6
Try updating your packages
I am using PyCharm and Python 3.8
JP