Plotting eigenstates
Numbers are a good check, but the shape of a wavefunction is easier to read from a picture. The usual picture draws each eigenstate at the height of its own energy, on top of the potential.
The standard figure
solve returns a result holding energies, wavefunctions and potential, and grid.values() gives the matching points. The rest is ordinary matplotlib, so this same code works in a script on your own machine:
import matplotlib.pyplot as plt
from eigora import GridND
from eigora.qm import QuantumSystem
from eigora.qm.potentials import HarmonicWell
omega = 1.0
n_states = 5
grid = GridND.line(-8.0, 8.0, 512)
system = QuantumSystem(grid=grid, potential=HarmonicWell(omega=omega))
solution = system.solve(n_states=n_states)
x = grid.values()
plt.plot(x, solution.potential, color="gray", label="V(x)")
for n, energy in enumerate(solution.energies):
# Each state is drawn at the height of its own energy.
plt.plot(x, energy + solution.wavefunctions[n], label=f"n = {n}")
plt.ylim(0, (n_states + 1) * omega)
plt.xlabel("x")
plt.ylabel("energy")
plt.legend()
plt.show()
Each extra state adds one node, and the states spread further into the regions where the potential is high.
Your own potential
To define a new system, subclass Potential and write the formula in __call__. This cell is yours to edit, so try changing the formula, or the number of states:
import numpy as np
import matplotlib.pyplot as plt
from eigora import GridND
from eigora.qm import QuantumSystem
from eigora.qm.potentials import Potential
class TiltedWell(Potential):
"""Any callable V(x) works: subclass Potential and write the formula."""
def __call__(self, x):
return 0.1 * x**4 - x**2 + 0.2 * x
grid = GridND.line(-6.0, 6.0, 512)
system = QuantumSystem(grid=grid, potential=TiltedWell())
solution = system.solve(n_states=4)
x = grid.values()
plt.plot(x, solution.potential, color="gray", label="V(x)")
for n, energy in enumerate(solution.energies):
plt.plot(x, energy + solution.wavefunctions[n], label=f"E = {energy:.3f}")
plt.ylim(-4, 2)
plt.xlabel("x")
plt.ylabel("energy")
plt.legend()
plt.show()
If you break something, Reset brings the original code back. Code that runs for more than 10 seconds is stopped, and the page itself stays responsive.
These states don't change over time, apart from a phase. To see something move, continue to time evolution.