.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/quantum/particle_in_box/plot_01_particle_in_box.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_quantum_particle_in_box_plot_01_particle_in_box.py: Solving Schrodinger's equation for a particle in a box ======================================================== Plots the first few 1D particle-in-a-box wavefunctions (:class:`~chemistrykit.quantum.systems.particle_in_box.ParticleInBox1D`), each offset by its own energy level, then checks the textbook 3D cubic-box degeneracy pattern (:class:`~chemistrykit.quantum.systems.particle_in_box.ParticleInBox3D`). These are the simplest exact solutions of Schrodinger's 1926 time-independent equation :math:`-\frac{\hbar^2}{2m}\nabla^2\psi=E\psi` inside hard walls: quantized energies :math:`E_n=n^2h^2/8mL^2` appear from the boundary conditions alone, with no quantization postulate. .. GENERATED FROM PYTHON SOURCE LINES 17-32 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from chemistrykit.quantum.systems.particle_in_box import ParticleInBox1D, ParticleInBox3D from chemistrykit.quantum.visualizers.quantum_plots import plot_particle_in_box_wavefunctions box = ParticleInBox1D(length=1.0e-9) for n in (1, 2, 3, 4): print(f"E_{n} = {box.energy(n) / 1.602176634e-19:.4f} eV, E_{n}/E_1 = {box.energy(n) / box.energy(1):.4f} (n^2 = {n**2})") fig, ax = plt.subplots(figsize=(7, 5)) plot_particle_in_box_wavefunctions(box, [1, 2, 3, 4], ax=ax, scale=2.0e-20) ax.set_title("1D particle-in-a-box wavefunctions (1 nm box)") fig.tight_layout() .. image-sg:: /api/gallery/quantum/particle_in_box/images/sphx_glr_plot_01_particle_in_box_001.png :alt: 1D particle-in-a-box wavefunctions (1 nm box) :srcset: /api/gallery/quantum/particle_in_box/images/sphx_glr_plot_01_particle_in_box_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none E_1 = 0.3760 eV, E_1/E_1 = 1.0000 (n^2 = 1) E_2 = 1.5041 eV, E_2/E_1 = 4.0000 (n^2 = 4) E_3 = 3.3843 eV, E_3/E_1 = 9.0000 (n^2 = 9) E_4 = 6.0165 eV, E_4/E_1 = 16.0000 (n^2 = 16) .. GENERATED FROM PYTHON SOURCE LINES 33-35 A cubic 3D box shows genuine degeneracy from symmetry alone: the three permutations of (2, 1, 1) share exactly the same energy. .. GENERATED FROM PYTHON SOURCE LINES 35-53 .. code-block:: Python cubic_box = ParticleInBox3D(Lx=1.0e-9, Ly=1.0e-9, Lz=1.0e-9) e211 = cubic_box.energy(2, 1, 1) e121 = cubic_box.energy(1, 2, 1) e112 = cubic_box.energy(1, 1, 2) print(f"E(2,1,1) = E(1,2,1) = E(1,1,2)? {np.allclose([e211, e121, e112], e211)}") degeneracies = cubic_box.degeneracy(n_max=3) fig2, ax2 = plt.subplots(figsize=(6, 4)) energies_ev = np.array(sorted(degeneracies.keys())) / 1.602176634e-19 counts = [degeneracies[e] for e in sorted(degeneracies.keys())] ax2.bar(range(len(energies_ev)), counts, tick_label=[f"{e:.2f}" for e in energies_ev]) ax2.set_xlabel("energy (eV)") ax2.set_ylabel("degeneracy") ax2.set_title("Cubic-box level degeneracies") fig2.tight_layout() plt.show() .. image-sg:: /api/gallery/quantum/particle_in_box/images/sphx_glr_plot_01_particle_in_box_002.png :alt: Cubic-box level degeneracies :srcset: /api/gallery/quantum/particle_in_box/images/sphx_glr_plot_01_particle_in_box_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none E(2,1,1) = E(1,2,1) = E(1,1,2)? True .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.070 seconds) .. _sphx_glr_download_api_gallery_quantum_particle_in_box_plot_01_particle_in_box.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_particle_in_box.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_particle_in_box.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_particle_in_box.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_