<jupyter_start><jupyter_text>Dead boundary condition<jupyter_code>def Ham_dbc_minus(M):
    T = -(np.diag(np.ones(shape=(M-1,)), -1) + np.diag(np.ones(shape=(M-1,)),  1))# DBC
    H=T
    return H

def Ham_dbc_plus(M):
    T = (np.diag(np.ones(shape=(M-1,)), -1) + np.diag(np.ones(shape=(M-1,)),  1))# DBC
    H=T
    return H
print Ham_dbc_minus(5)
print Ham_dbc_plus(5)
M=100
w_dbc_plus,v_dbc_plus=LA.eigh(Ham_dbc_plus(M))
w_dbc_minus,v_dbc_minus=LA.eigh(Ham_dbc_minus(M))
x=np.arange(M)
p=np.pi
k_index=np.linspace(-p/5, p/5)
plt.plot(x, w_dbc.real, 'b.', label='numerical')
plt.plot(x, -2*np.cos(p*x/(M)), 'r', label=r'$-2\cos(\pi n/L)$')
#plt.plot(x, 2*np.sort((np.cos(2*p*x/M))), 'k-',label=r'sorted,$-2\cos(2 \pi n/L)$')
plt.legend(loc='best')
plt.title("Eigenvalue of Free particle")
w_dbc_minus[0], w_dbc_plus[0]
x=np.arange(M)
N=1./np.sqrt(M/2)
#plt.plot(x,(v_dbc_plus[:,0]).real, 'b', label='+GS')
plt.plot(x,(v_dbc_minus[:,0]).real, 'b', label='GS')
plt.plot(x,N*np.cos(2*p - 2*p*x/(M+1)), 'r-', label='$anal$')
#plt.plot(x,-N*np.cos(2*(p)*x/(M+1)), label=r'$N \cos(2\pi n/N)$')
#plt.plot(x, N*np.sin(np.pi*x/(M+1))*np.cos(x), 'r', label='Anal')
#plt.plot(x,N*np.ones(len(x)))
plt.legend(loc='best')
plt.title("Groundstate of Free particle (DBC) ")
plt.ylabel(r"$Re(\psi_n)$", fontsize=14)
plt.xlabel(r"lattice site $n$", fontsize=14)<jupyter_output><empty_output><jupyter_text>Periodic boundary condition: eigenstates ( N even)<jupyter_code>def Ham_pbc_minus(M):
    T = -(np.diag(np.ones(shape=(M-1,)), -1) + np.diag(np.ones(shape=(M-1,)),  1))
    T[0][M-1]=-1.0 # PBC
    T[M-1][0]=-1.0 
    H=T
    return H

def Ham_pbc_plus(M):
    T = (np.diag(np.ones(shape=(M-1,)), -1) + np.diag(np.ones(shape=(M-1,)),  1))
    T[0][M-1]=1.0 # PBC
    T[M-1][0]=1.0
    H=T
    return H
M=100
w_pbc_minus,v_pbc_minus=LA.eigh(Ham_pbc_minus(M))
w_pbc_plus,v_pbc_plus=LA.eigh(Ham_pbc_plus(M))

p=np.pi
x=np.linspace(-p, p,100)

plt.ylim([-1.2,1.2])
plt.plot(x,-np.cos(x), 'b-')
plt.plot(p,1, 'o' ,mfc='w')
x = [-p, -p/2, 0, p/2, p]
labels = ['$-\pi$', '-$\pi/2$', '0', '$\pi/2$', '$\pi$']
plt.xticks(x, labels, fontsize=12)
plt.ylabel(r"$\epsilon(k)$", fontsize=14)
plt.xlabel('k')
plt.axhline(0, color='black', linestyle='dashed')
#plt.savefig('minus_energy.eps')

p=np.pi
x=np.linspace(-p, p,100)

plt.ylim([-1.2,1.2])
plt.plot(x,np.cos(x), 'b-')
plt.plot(p,-1, 'o' ,mfc='w')
x = [-p, -p/2, 0, p/2, p]
labels = ['$-\pi$', '-$\pi/2$', '0', '$\pi/2$', '$\pi$']
plt.xticks(x, labels, fontsize=12)
plt.ylabel(r"$\epsilon(k)$", fontsize=14)
plt.xlabel('k')
plt.axhline(0, color='black', linestyle='dashed')
plt.savefig('plus_energy.eps')
x=np.arange(M)
N=np.sqrt(2./M)
p=np.pi
plt.plot(x,np.real(v_pbc_minus[:,0]), 'b-', label='$GS$')
plt.plot(x,np.real(v_pbc_minus[:,1]), 'r-', label='$1ES^+$')
plt.plot(x,np.real(v_pbc_minus[:,2]), 'm-', label='$1ES^-$')
plt.plot(x,np.real(v_pbc_minus[:,3]), 'g-', label='$2ES^+$')
plt.plot(x,np.real(v_pbc_minus[:,4]), 'c-', label='$2ES^-$')
plt.legend(loc='upper right')
plt.ylabel(r"$\psi_n$", fontsize=18)
plt.axhline(0, color='black', linestyle='dashed')
plt.xlabel(r"lattice site $n$", fontsize=14)
plt.ticklabel_format(useOffset=False)

art=[]
lgd=plt.legend(loc=9, bbox_to_anchor=(1.15, 1.0), ncol=1)
art.append(lgd)
plt.savefig("pbc_minus_even.eps", additional_artists=art,bbox_inches="tight")

x=np.arange(M)
N=np.sqrt(2./M)
p=np.pi
plt.plot(x,np.real(v_pbc_plus[:,0]), 'k-', label='$GS$')
plt.plot(x,np.real(v_pbc_plus[:,1]), 'm-', label='$1ES^+$')
plt.plot(x,np.real(v_pbc_plus[:,2]), 'c-', label='$1ES^-$')
#plt.plot(x,np.real(v_pbc_minus[:,3]), 'g-', label='$2ES^+$')
#plt.plot(x,np.real(v_pbc_minus[:,4]), 'c-', label='$2ES^-$')
#plt.legend(loc='upper right')
plt.ylabel(r"$\psi_n$", fontsize=18)
plt.axhline(0, color='black', linestyle='dashed')
plt.xlabel(r"lattice site $n$", fontsize=14)
plt.ticklabel_format(useOffset=False)

art=[]
lgd=plt.legend(loc=9, bbox_to_anchor=(1.15, 1.0), ncol=1)
art.append(lgd)
plt.savefig("pbc_minus_plus.eps", additional_artists=art,bbox_inches="tight")

x=np.arange(M)
N=np.sqrt(2./M)
p=np.pi
plt.xlim([0,120])
plt.plot(x,np.real(v_pbc_minus[:,1]), 'r-', label='1ES')
plt.plot(x,-N*np.cos(2*p*x/M), label=r'$-N \cos(2\pi n/N)$')
plt.legend(loc='upper right')
plt.ylabel(r"$\psi_n$", fontsize=18)
plt.axhline(0, color='black', linestyle='dashed')
plt.xlabel(r"lattice site $n$", fontsize=14)
x=np.arange(M)
N=np.sqrt(2./M)
p=np.pi
plt.xlim([0,120])
plt.plot(x,np.real(v_pbc_minus[:,5]), 'r-', label='1ES')
plt.plot(x,-N*np.cos(6*p*x/M), label=r'$anal$')
plt.legend(loc='upper right')
plt.ylabel(r"$\psi_n$", fontsize=18)
plt.axhline(0, color='black', linestyle='dashed')
plt.xlabel(r"lattice site $n$", fontsize=14)<jupyter_output><empty_output><jupyter_text>Periodic boundary condition: eigenstates ( N odd)<jupyter_code>def Ham_pbc_minus(M):
    T = -(np.diag(np.ones(shape=(M-1,)), -1) + np.diag(np.ones(shape=(M-1,)),  1))
    T[0][M-1]=-1.0 # PBC
    T[M-1][0]=-1.0 
    H=T
    return H

def Ham_pbc_plus(M):
    T = (np.diag(np.ones(shape=(M-1,)), -1) + np.diag(np.ones(shape=(M-1,)),  1))
    T[0][M-1]=1.0 # PBC
    T[M-1][0]=1.0
    H=T
    return H
M=101
w_pbc_minus,v_pbc_minus=LA.eigh(Ham_pbc_minus(M))
w_pbc_plus,v_pbc_plus=LA.eigh(Ham_pbc_plus(M))
x=np.arange(M)
N=np.sqrt(2./M)
p=np.pi
plt.plot(x,np.real(v_pbc_plus[:,0]), 'b-', label='$GS$')
#plt.plot(x,N*np.sin(2*p - 2*p*x/(M+1)), 'r-', label='$anal$')
#plt.plot(x,N*np.sin(p*x/(M-1))*np.cos(x), 'r-', label='$anal$')
#plt.plot(x,np.real(v_pbc_minus[:,1]), 'r-', label='$1ES^+$')
#plt.plot(x,np.real(v_pbc_minus[:,2]), 'm-', label='$1ES^-$')
#plt.plot(x,np.real(v_pbc_minus[:,3]), 'g-', label='$2ES^+$')
#plt.plot(x,np.real(v_pbc_minus[:,4]), 'c-', label='$2ES^-$')
plt.legend(loc='upper right')
plt.ylabel(r"$\psi_n$", fontsize=18)
plt.axhline(0, color='black', linestyle='dashed')
plt.xlabel(r"lattice site $n$", fontsize=14)
plt.ticklabel_format(useOffset=False)
plt.savefig('gs_odd.eps')
#art=[]
#lgd=plt.legend(loc=9, bbox_to_anchor=(1.15, 1.0), ncol=1)
#art.append(lgd)
#plt.savefig("pbc_minus_even.eps", additional_artists=art,bbox_inches="tight")

print v_pbc_plus[:,0][0], v_pbc_plus[:,0][-1] 
print v_pbc_plus[:,1][0], v_pbc_plus[:,1][-1] 

#print 1./N*v_pbc_minus[:,1] 
print (1./N)*v_pbc_minus[0][0:11]
N
n=np.arange(M)
p=np.pi
k_index=np.linspace(-p/5, p/5)
plt.plot(n, w_pbc_plus.real, 'b.', label='numerical')
plt.plot(n, 2*np.cos(p*n/M+ p/.2), 'r', label=r'$-2\cos(\pi n/L)$')
plt.legend(loc='best')
plt.title("Eigenvalue of Free particle")<jupyter_output><empty_output><jupyter_text>Sanity check<jupyter_code>M=1000
print Ham_pbc_plus(M) 
w_pbc_plus,v_pbc_plus=LA.eigh(Ham_pbc_plus(M))
w_pbc_plus[0]
M=5
H=np.mat(Ham_pbc_plus(M))
v=np.mat(v_pbc_plus[:,0])
print H
print v
print v*(H*v.T)
print np.dot(v_pbc_plus[0],(np.dot(v_pbc_plus[0], Ham_pbc_plus(M))))
def ipr(wavefn):# a parameter that characterizes the eigenvector
    return sum(abs(wavefn)**4)
ipr(v_pbc_plus[0]),ipr(v_pbc_minus[0])
4./M
M<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.27414285714285713, 'fraction_numerical': 0.037142857142857144, 'mean_word_length': 6.129327902240326, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '525295', 'license': 'MIT', 'n_tokens_mistral': 3716, 'n_tokens_neox': 3552, 'n_words': 441, 'path': '.ipynb_checkpoints/free ham-checkpoint.ipynb', 'repo_name': 'mohitpandey92/Brownian_particle', 'size': '7000'}