Published/scientific-latex-templates/computational-physics / code / __pycache__ / quantum_mechanics.cpython-312.pyc
289 viewsubuntu2404
�
q8�h�$ � �� � d Z ddlZddlmZ ddlmZ ddlm Z ddl
mZmZ ej j d� G d� d� Z G d � d
� Z G d� d� Zd
� Zd� Zd� Zedk( r e� e� e� yy)u,
Quantum Mechanics Simulations for Computational Physics
========================================================
This module contains implementations of fundamental quantum mechanics simulations:
- Time-dependent Schrödinger equation solver
- Quantum harmonic oscillator eigenstates
- Particle in a box solutions
- Quantum tunneling demonstrations
Keywords: quantum mechanics python, schrodinger equation solver, quantum harmonic oscillator,
particle in a box simulation, quantum tunneling python code
Author: CoCalc Scientific Templates
License: MIT
� N)�diags)�expm)�hermite� factorial�* c �* � e Zd ZdZdd�Zd� Zd� Zd� Zy)�SchrodingerSolveru�
Time-dependent Schrödinger equation solver using finite difference method.
Solves: iℏ ∂ψ/∂t = Ĥ ψ where Ĥ = T̂ + V̂
c �V � || _ || _ || _ || _ ||z | _ t j d||� | _ dt j |� z }t j |dz
� }|dz d|z | j dz z z t |||gg d�||f�� z | _
y)a?
Initialize the solver.
Parameters:
-----------
L : float
Length of simulation box
N : int
Number of grid points
hbar : float
Reduced Planck constant (natural units)
m : float
Particle mass (natural units)
r ������ � )�����r r )�shapeN)�L�N�hbar�m�dx�np�linspace�x�onesr �T_matrix)�selfr r r r �kinetic_diag�kinetic_offs �code/quantum_mechanics.py�__init__zSchrodingerSolver.__init__# s� � � �������� �����a�%������Q��1�%��� �B�G�G�A�J����g�g�a��c�l����'�Q�q�S����!��^�4�5��;��k�:�J�q�RS�f�U�
��
� c �N � || _ | j t |d� z | _ y)z'Set the potential energy function V(x).r N)�Vr r �H)r r! s r �
set_potentialzSchrodingerSolver.set_potential@ s � ��������q�!��,��r c �D � t j | j |z
dz d|dz z z � t j d|z | j z � z }|t j t j t j
|� dz | j � � z S )z�
Create a Gaussian wave packet initial condition.
Parameters:
-----------
x0 : float
Initial position
sigma : float
Wave packet width
k0 : float
Initial momentum
r
y �?)r �expr �sqrt�trapz�abs)r �x0�sigma�k0�psis r �gaussian_wavepacketz%SchrodingerSolver.gaussian_wavepacketE sy � � �f�f�t�v�v��{�Q�&�&�!�E�1�H�*�5�6�����R��$�&�&�@P�9Q�Q���R�W�W�R�X�X�b�f�f�S�k�1�n�d�f�f�=�>�>�>r c �B � t j d||� }t d| j j � z |z | j
z � }|j
� }|j
� g}|dd D ]&