I'm trying to get the eigenfunctions and eigenvalues (energies) of an infinite well in Python, but I have a few things I can't seem to fix or don't understand...(adsbygoogle = window.adsbygoogle || []).push({});

Here's the code I have:

First of all, the eigenfunctions U[:,i] appear to be normalized if I check, but they don't match the analytic solution. Also, the eigenvalues don't match the values of energy for the infinite well 0.5(πn/L)Code (Python):from numpy import *

from numpy.linalg import eigh

import matplotlib.pyplot as plt

from __future__ import division

def Laplacian(x):

h = x[1]-x[0] # assume uniformly spaced points

n = len(x)

M = -2*identity(n,'d')

for i in range(1,n):

M[i,i-1] = M[i-1,i] = 1

return M/h**2

L = 6

x = linspace(0, L, 100)

T = -0.5*Laplacian(x)

H = T

E,U = eigh(H)

n = 1 # change to see another state

plt.plot(x,U[:,n-1],'o')

plt.plot(x, sqrt(2/L)*sin(n*pi*x/L),'o')

plt.show()^{2}.

What could I be missing? The math seems to be fine.

Would it make it better to use scipy.linalg instead of numpy's?

Thanks!

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Python Simulating an infinite well

Tags:

Have something to add?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**