In [1]:
import sympy as sp
from IPython.display import Image, display
In [2]:
x, a, phi, c1, c2, c3, alpha, beta = sp.symbols("x a, phi C_1 C_2 C_3 alpha beta")
m, hbar, E, k, v0 = sp.symbols("m hbar E k V_0", positive=True)
psi = sp.Function("psi")
V = sp.Function("V")
In [3]:
def get_matches(expr, fn, x):
A = sp.Wild("A")
B = sp.Wild("B")
pattern = A * fn(B*x)
matches = []
for term in sp.Add.make_args(expr):
m = term.match(pattern)
if m:
matches.append((m[A], m[B]))
return matches
In the finite square well the two regions outside x < -a and x > a have a constant potential V0.
Now the Schrodinger equation is....
We define another constant $ k = \frac{\hbar^2 }{2 m} $
In [4]:
ks = hbar**2 / (2 * m)
ks
Out[4]:
$\displaystyle \frac{\hbar^{2}}{2 m}$
In [5]:
eq = sp.Eq(
-k * sp.diff(psi(x), x, 2) + V(x)*psi(x),
E * psi(x)
)
display("The Shröedinger Equation")
display(eq)
display(ks)
eq.subs(k, ks)
'The Shröedinger Equation'
$\displaystyle - k \frac{d^{2}}{d x^{2}} \psi{\left(x \right)} + V{\left(x \right)} \psi{\left(x \right)} = E \psi{\left(x \right)}$
$\displaystyle \frac{\hbar^{2}}{2 m}$
Out[5]:
$\displaystyle - \frac{\hbar^{2} \frac{d^{2}}{d x^{2}} \psi{\left(x \right)}}{2 m} + V{\left(x \right)} \psi{\left(x \right)} = E \psi{\left(x \right)}$
In [6]:
potential = v0
In [7]:
eq = sp.Eq(
-k * sp.diff(psi(x), x, 2) + v0*psi(x),
E * psi(x)
)
psi1 = sp.dsolve(eq)
display(eq)
display(psi1)
display(str(psi1))
$\displaystyle V_{0} \psi{\left(x \right)} - k \frac{d^{2}}{d x^{2}} \psi{\left(x \right)} = E \psi{\left(x \right)}$
$\displaystyle \psi{\left(x \right)} = C_{1} e^{- \frac{x \sqrt{- E + V_{0}}}{\sqrt{k}}} + C_{2} e^{\frac{x \sqrt{- E + V_{0}}}{\sqrt{k}}}$
'Eq(psi(x), C1*exp(-x*sqrt(-E + V_0)/sqrt(k)) + C2*exp(x*sqrt(-E + V_0)/sqrt(k)))'
In [8]:
matches = get_matches(psi1.rhs, sp.exp, x)
display(matches)
#psi1 = psi1.args[1].args[0]
a1,b1 = matches[1]
psi1 = c1*sp.exp(b1*x)
display(psi1)
[(C1, -sqrt(-E + V_0)/sqrt(k)), (C2, sqrt(-E + V_0)/sqrt(k))]
$\displaystyle C_{1} e^{\frac{x \sqrt{- E + V_{0}}}{\sqrt{k}}}$
While inside the finite square well the potential is zero.
In [9]:
eq = sp.Eq(
-k * sp.diff(psi(x), x, 2),
E * psi(x)
)
psi2 = sp.dsolve(eq)
display(eq)
display(psi2)
$\displaystyle - k \frac{d^{2}}{d x^{2}} \psi{\left(x \right)} = E \psi{\left(x \right)}$
$\displaystyle \psi{\left(x \right)} = C_{1} \sin{\left(\frac{\sqrt{E} x}{\sqrt{k}} \right)} + C_{2} \cos{\left(\frac{\sqrt{E} x}{\sqrt{k}} \right)}$
Boundary Conditions
In [10]:
# Here I match the sin function but then I turn it into a sin with a phi phase
# so that I can incorporate both results into one.
matches = get_matches(psi2.rhs, sp.sin, x)
c2 = sp.symbols("C_2")
display(matches)
a1,b1 = matches[0]
psi2 = c2 * sp.sin(b1*x + phi)
display(psi2)
[(C1, sqrt(E)/sqrt(k))]
$\displaystyle C_{2} \sin{\left(\frac{\sqrt{E} x}{\sqrt{k}} + \phi \right)}$
In [11]:
display(psi1.subs(x,-a/2))
display(psi2.subs(x,-a/2))
$\displaystyle C_{1} e^{- \frac{a \sqrt{- E + V_{0}}}{2 \sqrt{k}}}$
$\displaystyle - C_{2} \sin{\left(\frac{\sqrt{E} a}{2 \sqrt{k}} - \phi \right)}$
In [12]:
sp.diff(psi1, x)
Out[12]:
$\displaystyle \frac{C_{1} \sqrt{- E + V_{0}} e^{\frac{x \sqrt{- E + V_{0}}}{\sqrt{k}}}}{\sqrt{k}}$
In [13]:
sp.diff(psi2,x)
Out[13]:
$\displaystyle \frac{C_{2} \sqrt{E} \cos{\left(\frac{\sqrt{E} x}{\sqrt{k}} + \phi \right)}}{\sqrt{k}}$
In [14]:
lhs = sp.diff(psi1, x) / psi1
lhs
Out[14]:
$\displaystyle \frac{\sqrt{- E + V_{0}}}{\sqrt{k}}$
In [15]:
rhs = sp.simplify(sp.diff(psi2, x)/psi2)
rhs
Out[15]:
$\displaystyle \frac{\sqrt{E}}{\sqrt{k} \tan{\left(\frac{\sqrt{E} x}{\sqrt{k}} + \phi \right)}}$
In [16]:
# Because of difficulties getting radicals to combine I have decided to square the left hand
# side an right side of both expressions.
(lhs**2)
Out[16]:
$\displaystyle \frac{- E + V_{0}}{k}$
In [17]:
rhs
Out[17]:
$\displaystyle \frac{\sqrt{E}}{\sqrt{k} \tan{\left(\frac{\sqrt{E} x}{\sqrt{k}} + \phi \right)}}$
In [18]:
# Actually it turns out the right hand side is less troublesome.
rhs.subs(sp.sqrt(E)/sp.sqrt(k), alpha)
Out[18]:
$\displaystyle \frac{\alpha}{\tan{\left(\alpha x + \phi \right)}}$
In [19]:
sp.expand((lhs**2)).subs(E/k, alpha**2).subs(v0/k, -beta**2)
Out[19]:
$\displaystyle - \alpha^{2} - \beta^{2}$
In [ ]: