Created
December 29, 2022 16:25
-
-
Save theideasmith/ed38402fd96d369e895001c509a1423d to your computer and use it in GitHub Desktop.
Solving for the eigenvectors and eigenvalues of the quantum hamiltonian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(*Define the potential energy function*) | |
potential[x_] := x^2 | |
(*Set the mass and Planck's constant*) | |
mass = 1; | |
hbar = 1; | |
(*Set the range of x values and the number of points to use*) | |
xMin = -5; | |
xMax = 5; | |
numPoints = 1000; | |
(*Calculate the step size*) | |
stepSize = (xMax - xMin)/numPoints; | |
(*Generate the list of x values*) | |
xValues = Range[xMin, xMax, stepSize]; | |
(*Calculate the kinetic energy operator matrix*) | |
kineticMatrix = | |
Table[If[i == j, -hbar^2/(2*mass*stepSize^2), | |
If[Abs[i - j] == 1, hbar^2/(2*mass*stepSize^2), 0]], {i, | |
numPoints}, {j, numPoints}]; | |
(*Calculate the potential energy operator matrix*) | |
potentialMatrix = Table[potential[xValues[[i]]], {i, numPoints}]; | |
(*Calculate the Hamiltonian matrix*) | |
hamiltonianMatrix = kineticMatrix + DiagonalMatrix[potentialMatrix]; | |
(*Solve for the eigenvalues and eigenvectors of the Hamiltonian \ | |
matrix*) | |
{eigenvalues, eigenvectors} = Eigensystem[hamiltonianMatrix]; | |
(*Select the ground state wave function*) | |
groundStateWaveFunction = eigenvectors[[All, 1]]; | |
(*Normalize the wave function*) | |
groundStateWaveFunction = | |
groundStateWaveFunction/Norm[groundStateWaveFunction]; | |
(*Plot the wave function*) | |
ListLinePlot[groundStateWaveFunction, DataRange -> {xMin, xMax}, | |
PlotRange -> All] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment