Exploring Computational Quantum Mechanics

Solving for Eigenstates: The Time-Independent Schrödinger Equation

Time-Dependent Schrodinger Equation
Time-Dependent Schrodinger Equation
Time-Dependent Schrodinger Equation
Time-Independent Schrodinger Equation
Time-Independent Schrodinger Equation
Time-Independent Schrodinger Equation

HOW DO WE SOLVE IT, THOUGH?

Color-coded TISE
Color-coded TISE
Color-coded TISE (Made with CodeCogs)
Relationship between Eigenvalues and Eigenvectors
Relationship between Eigenvalues and Eigenvectors
We can pull close parallels between this equation and the TISE (Made with CodeCogs)

THAT ALL SEEMS GREAT, BUT HOW DO WE TURN THE OPERATOR INTO A MATRIX?

Expression for the second-order difference quotient
Expression for the second-order difference quotient
Expression for the second-order difference quotient (Made with CodeCogs)
Matrix approximation of second derivative
Matrix approximation of second derivative
Matrix approximation of second derivative (Made with CodeCogs)
Matrix approximation of kinetic and potential energy
Matrix approximation of kinetic and potential energy
Matrix approximation of kinetic and potential energy (Made with CodeCogs)
Matrix approximation of the Hamiltonian
Matrix approximation of the Hamiltonian
Matrix approximation of the Hamiltonian (Made with CodeCogs)
Matrix equation for the TISE
Matrix equation for the TISE
Matrix equation for the TISE (Made with CodeCogs)

AT LAST, THE GOOD STUFF: CODE

LANDING LIBRARIES & PREPARING PARAMETERS

import numpy as np
from scipy.sparse import diags #Allows us to construct our matrices
from scipy.sparse.linalg import eigsh #Solves the Eigenvalue problem
import matplotlib.pyplot as plt
Matrix approximation for Second Derivative
Matrix approximation for Second Derivative
Matrix approximation for Second Derivative (Made with CodeCogs)
Finite Potential Well
Finite Potential Well
Finite potential well (Annafitzgerald, CC BY-SA 3.0, via Wikimedia Commons)
### IMPORTS ###
import numpy as np
from scipy.sparse import diags #Allows us to construct our matrices
from scipy.sparse.linalg import eigsh #Solves the Eigenvalue problem
import matplotlib.pyplot as plt

### CONSTANTS ###
N = 1000
hbar = 1
m = 0.5
xmin = -1
xmax = 1
x = np.linspace(xmin, xmax, N)
dx = (xmax - xmin)/(N + 1)
L = 1.5
W = 1
U = np.where((x < L/2) & (x > -L/2), 0, W)

MANUFACTURING MATRICES & EVALUATING EIGENSTATES

Matrix approximation of kinetic and potential energy
Matrix approximation of kinetic and potential energy
Matrix approximation of kinetic and potential energy (Made with CodeCogs)
d2dx2 = diags([1, -2, 1], offsets=[-1, 0, 1], shape=(N, N))/(dx**2)
T = -(hbar**2)/(2 * m) * d2dx2
V = diags([U], offsets=[0], shape=(N, N))
H = T + V
eigvals, eigvecs = eigsh(H, which="SM")
### PREPARE MATRICES ###
d2dx2 = diags([1, -2, 1], offsets=[-1, 0, 1], shape=(N, N))/(dx**2)
T = -(hbar**2)/(2 * m) * d2dx2
V = diags(U)
H = T + V

### CALCULATE EIGENSTATES ###
eigvals, eigvecs = eigsh(H, which="SM", k=k)

VISUALIZING VECTORS & PLOTTING PROBABILITIES

plt.plot(x, U)
plt.plot(x, np.full_like(x, eigvals[i]), "k--")
plt.plot(x, eigvals[i] + eigvecs[:, i] * scale, 'k')
plt.plot(x, eigvals[i] + eigvecs[:, i] * eigvecs[:, i].conj() * scale ** 2, 'b')
for i in range(k):
plt.plot(x, np.full_like(x, eigvals[i]), "k--")
plt.plot(x, eigvals[i] + eigvecs[:, i] * scale, 'k')
plt.plot(x, eigvals[i] + eigvecs[:, i] * eigvecs[:, i].conj() * scale ** 2, 'b')
plt.show()
### PLOTTING ###
plt.plot(x, U)
for i in range(k):
plt.plot(x, np.full_like(x, eigvals[i]), "k--")
plt.plot(x, eigvals[i] + eigvecs[:, i] * scale, 'k')
plt.plot(x, eigvals[i] + eigvecs[:, i] * eigvecs[:, i].conj() * scale * scale, 'b')
plt.show()

CONCATENATING CODE

### IMPORTS ###
import numpy as np
from scipy.sparse import diags #Allows us to construct our matrices
from scipy.sparse.linalg import eigsh #Solves the Eigenvalue problem
import matplotlib.pyplot as plt

### CONSTANTS ###
N = 1000
hbar = 1
m = 0.5
xmin = -1
xmax = 1
x = np.linspace(xmin, xmax, N)
dx = (xmax - xmin)/(N + 1)
L = 1.5
W = 1
U = np.where((x < L/2) & (x > -L/2), 0, W)

### PREPARE MATRICES ###
d2dx2 = diags([1, -2, 1], offsets=[-1, 0, 1], shape=(N, N))/(dx**2)
T = -(hbar**2)/(2 * m) * d2dx2
V = diags(U)
H = T + V

### CALCULATE EIGENSTATES ###
eigvals, eigvecs = eigsh(H, which="SM", k=k)

### PLOTTING ###
plt.plot(x, U)
for i in range(k):
plt.plot(x, np.full_like(x, eigvals[i]), "k--")
plt.plot(x, eigvals[i] + eigvecs[:, i] * scale, 'k')
plt.plot(x, eigvals[i] + eigvecs[:, i] * eigvecs[:, i].conj() * scale * scale, 'b')
plt.show()
Our wavefunctions and probability distributions
Our wavefunctions and probability distributions
Finite Potential Well
Finite Potential Well
Our wavefunctions and probability distributions (Left) vs. some real solution (Right)
Harmonic Oscillator Energy Levels
Harmonic Oscillator Energy Levels
Harmonic Oscillator Energy Levels

CONCLUDING REMARKS

NCSSM Class of 2021 with interests in Computer Science, Physics, Entrepreneurship, and Math

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store