1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#include <iostream> #include <vector> #include <cmath> #include <iomanip> // Constants const double PI = 3.141592653589793; const double HBAR = 1.0545718e-34; // Planck's constant over 2π (Js) const double MASS = 9.10938356e-31; // Electron mass (kg) // Function to compute the wave function at a given position double waveFunction(double x, double potential, double energy, double width) { double k = sqrt(2 * MASS * energy) / HBAR; double kappa = sqrt(2 * MASS * (potential - energy)) / HBAR; if (x < 0 || x > width) { return 0.0; } else if (x <= width / 2) { return sin(k * x); } else { return exp(-kappa * (x - width / 2)); } } // Function to simulate and print the quantum tunneling effect void simulateQuantumTunneling(double potential, double energy, double width, int numPoints) { std::vector<double> positions(numPoints); std::vector<double> waveFunctions(numPoints); // Set up positions and compute wave functions double step = width / (numPoints - 1); for (int i = 0; i < numPoints; ++i) { positions[i] = i * step; waveFunctions[i] = waveFunction(positions[i], potential, energy, width); } // Print results std::cout << "Position\tWave Function\n"; for (int i = 0; i < numPoints; ++i) { std::cout << std::fixed << std::setprecision(5) << positions[i] << "\t" << std::fixed << std::setprecision(5) << waveFunctions[i] << "\n"; } } int main() { double potential = 1.0e-18; // Potential barrier in Joules double energy = 1.5e-19; // Particle energy in Joules double width = 1e-10; // Width of the barrier in meters int numPoints = 100; // Number of points to simulate std::cout << "Quantum Tunneling Simulation\n"; simulateQuantumTunneling(potential, energy, width, numPoints); return 0; } |
Explanation
- Constants:
- PI: Mathematical constant π.
- HBAR: Reduced Planck’s constant (h/2π), crucial for quantum mechanics calculations.
- MASS: Mass of an electron (in kilograms), used for wave function calculations.
- Function
waveFunction(double x, double potential, double energy, double width)
:- Purpose: Computes the wave function of a particle given a potential barrier and energy.
- Parameters:
x
: Position where the wave function is evaluated.potential
: Height of the potential barrier.energy
: Energy of the particle.width
: Width of the potential barrier.
- Implementation:
- Calculates wave numbers
k
andkappa
based on the potential and energy. - Applies different formulas for the wave function inside and outside the potential barrier.
- Returns the computed wave function value.
- Calculates wave numbers
- Function
simulateQuantumTunneling(double potential, double energy, double width, int numPoints)
:- Purpose: Simulates and prints the quantum tunneling effect across a range of positions.
- Parameters:
potential
: Height of the potential barrier.energy
: Energy of the particle.width
: Width of the potential barrier.numPoints
: Number of discrete points to compute and display.
- Implementation:
- Computes positions and corresponding wave functions using the
waveFunction
function. - Prints the results in a tabulated format.
- Computes positions and corresponding wave functions using the
- Main Function:
- Setup: Defines parameters for potential, energy, width of the barrier, and number of points for simulation.
- Simulation: Calls
simulateQuantumTunneling
to compute and display the wave function over a range of positions.
Usage
- Quantum Tunneling Simulation: Provides a basic simulation of quantum tunneling through a potential barrier.
- Wave Function Visualization: Helps visualize how the wave function of a particle changes as it interacts with a potential barrier.