import numpy as np import matplotlib.pyplot as plt N = 100 E0 = 10 Omega = 1 #Question 1 main_diag = [E0 for i in range(N)] off_diag = [Omega for i in range(N-1)] H = np.diag(main_diag,k=0) + np.diag(off_diag,k=-1) + np.diag(off_diag, k=1) # Question 2 energy, phi = np.linalg.eig(H) # Question 3 order = energy.argsort() energy = energy[order] phi = phi[:,order] # Question 4 phase = np.pi/(N+1)*np.arange(N,0,-1) En = E0 + 2*Omega*np.cos(phase) plt.plot(energy,'*') plt.plot(En,'-') plt.xlabel('n') plt.ylabel('E') plt.savefig('energy.png') plt.close() # Question 5 m = 20 plt.plot(phi[:,-m],'*') phase = np.sqrt(2./(N+1))*np.sin((np.pi*m/(N+1))*np.arange(1,N+1)) plt.plot(phase,'-') plt.xlabel('i') plt.ylabel('Phi_n') plt.savefig('Phi20.png') plt.close()