- Overview
- Theoretical Background
- Features
- Installation
- Visualization
- Usage (Time Evolution)
- Usage (Frequency Evolution)
- Dependencies
- Code Structure
- License
This project is a Python-based simulation of the Particle in a Box problem, a fundamental concept in quantum mechanics. It models the time evolution of a quantum particle confined within a one-dimensional box, allowing users to explore different initial states and observe how these states evolve over time. The simulation provides visual insights into the behavior of quantum systems, making it an excellent educational tool for students and enthusiasts of quantum physics. Also, this project contains a code that animates the
The foundation of this simulation lies in the Schrödinger equation, which describes how the quantum state of a physical system changes over time:
where:
-
$( i )$ is the imaginary unit, -
$( \hbar )$ is the reduced Planck's constant, -
$( \Psi(x, t) )$ is the wave function of the particle, -
$( \hat{H} )$ is the Hamiltonian operator.
By seperating
For the Particle in a Box problem, the potential
This represents an infinitely deep potential well where the particle is confined between
Within the confines of the box, the particle can only occupy specific energy levels known as bound states. These states are quantized, meaning the particle can only have certain discrete energy values.
The solutions to the Schrödinger equation for this system are the eigenfunctions
where:
-
$( n )$ is the quantum number, -
$( m )$ is the mass of the particle. -
$( L )$ is the width of the box which in this case is$( a )$
These eigenfunctions form an orthonormal basis, allowing any desired initial wave function
- Time Evolution: Visualize how different initial states evolve over time within the potential well.
- Multiple Initial States: Choose from various predefined initial wave functions or define custom ones.
- Eigenstate Analysis: Examine the contributions of different eigenstates to the overall wave function.
- Interactive Visualization: Real-time plots displaying the real and imaginary parts of the wave function, as well as the probability density.
- Animation: Dynamic animations showing the evolution of the wave function and probability density.
Ensure you have Python 3.x installed on your system. Follow the steps below to set up the simulation environment:
-
Clone the Repository:
git clone https://github.com/yourusername/particle-in-a-box-simulation.git cd particle-in-a-box-simulation
-
Create a Virtual Environment (Optional but Recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install numpy matplotlib tkinter
The simulation provides several real-time plots:
-
Cn Coefficients:
- Displays the magnitude of the coefficients
$( C_n )$ for each eigenstate, illustrating their contribution to the overall wave function.
- Displays the magnitude of the coefficients
-
Initial Wave Function
$(( \Psi(x, 0) ))$ :- Shows the chosen initial state of the particle within the box.
-
Real Part of
$( \Psi(x, t) )$ :- Visualizes the real component of the wave function as it evolves over time.
-
Imaginary Part of
$( \Psi(x, t) )$ :- Visualizes the imaginary component of the wave function as it evolves over time.
-
Probability Density
$(( \Psi^*(x, t)\Psi(x, t) ))$ :- Illustrates the probability distribution of finding the particle at position
$( x )$ and time$( t )$ .
- Illustrates the probability distribution of finding the particle at position
Execute the Python script to start the simulation:
python particle_in_box.py
Upon running the script, you will be prompted to select the simulation mode and define the initial state.
-
Select Application Mode:
- 1: Time Evolution Mode - Simulates how the wave function evolves over time.
- 0: Frequency Evolution Mode - Analyzes the frequency components of the initial wave function.
Example Input:
Enter the application mode you want (1 for time evolution, 0 for frequency evolution): 1
-
Select Initial State:
-
0: Stationary State - Choose a specific quantum number
$( n )$ for a stationary eigenstate. - 1: Linear Combination (Function 1) - A predefined linear combination of eigenstates.
- 2: Linear Combination (Function 2) - Another predefined linear combination.
- 3: Custom Function - Define a custom initial wave function within a specified interval.
Example Input:
Enter the mode you want: 3
For Custom Function (mode 3):
Enter a (should be between -1/2 to 1/2): -0.25 Enter b (should be between -1/2 to 1/2 and more than a): 0.25
-
0: Stationary State - Choose a specific quantum number
Execute the Python script to start the simulation:
python particle_in_box.py
-
Select Application Mode:
Enter the application mode you want (1 for time evolution, 0 for frequency evolution): 0
-
Select Initial State:
-
0: Stationary State - Choose a specific quantum number
$( n )$ for a stationary eigenstate. - 1: Linear Combination (Function 1) - A predefined linear combination of eigenstates.
- 2: Linear Combination (Function 2) - Another predefined linear combination.
- 3: Custom Function - Define a custom initial wave function within a specified interval.
Example Input:
Enter the mode you want: 2
-
0: Stationary State - Choose a specific quantum number
The simulation relies on the following Python libraries:
- math: Mathematical functions.
- numpy: Numerical operations and array handling.
- tkinter: GUI toolkit for Python.
- matplotlib: Plotting and visualization.
- matplotlib.animation.FuncAnimation: For creating animations.
- matplotlib.backends.backend_tkagg.FigureCanvasTkAgg: Integrating Matplotlib with Tkinter.
Ensure all dependencies are installed via pip
as outlined in the Installation section.
The main script particle_in_box.py
comprises several key components:
-
Imports and Initialization:
- Imports necessary libraries.
- Sets up the Tkinter root window.
-
Global Variables:
- Defines constants and arrays for eigenfunctions, coefficients, energies, and time steps.
-
Function Definitions:
- func0 to func3: Define different initial wave functions.
-
integrate: Calculates the coefficients
$( C_n )$ by integrating the product of the initial wave function and eigenfunctions. - normalize_coefs: Normalizes the coefficients to ensure the total probability is 1.
- Psi_n: Constructs the time-dependent wave function for a given eigenstate.
- animate_1 and animate_0: Handle the animation for time evolution and frequency evolution modes, respectively.
-
User Input Handling:
- Prompts the user to select the simulation mode and define the initial state.
-
Simulation Execution:
- Depending on the selected mode, calculates coefficients, normalizes them, and sets up the visualization using Matplotlib and Tkinter.
-
Visualization:
- Creates plots for coefficients
$( C_n )$ , initial wave function, real and imaginary parts of$( \Psi(x, t) )$ , and probability density. - Animates the evolution of the wave function over time or frequency components.
- Creates plots for coefficients
This project is licensed under the MIT License.
Note: Ensure that the Tkinter library is properly installed and configured on your system, as it is essential for the GUI components of this simulation.
This simulation is inspired by fundamental concepts in quantum mechanics and aims to provide an interactive learning experience for those interested in exploring the quantum behavior of particles in confined systems.
For any questions or suggestions, please contact amirarsalan.sanati81@gmail.com.