66
77 - In classical mechanics, it is the sum of kinetic and potential energies.
88
9- - In quantum mechanics, it becomes an operator acting on the wavefunction ψ(x), describing how the system evolves in time.
9+ - In quantum mechanics, it becomes an operator acting on the wavefunction ψ(x),
10+ describing how the system evolves in time.
1011
1112This module includes:
12- - classical_hamiltonian(): return total energy for given mass, momentum, and potential.
13- - quantum_hamiltonian_1d(): Builds a 1D Hamiltonian matrix for numerical quantum systems.
13+ - classical_hamiltonian(): return total energy for given mass, momentum,
14+ and potential.
15+ - quantum_hamiltonian_1d(): Builds a 1D Hamiltonian matrix for numerical
16+ quantum systems.
1417"""
1518
1619import numpy as np
@@ -23,7 +26,7 @@ def classical_hamiltonian(
2326 Calculate the classical Hamiltonian (total energy) of a particle.
2427
2528 The Hamiltonian(H) represents the total energy of the system:
26- H = (momentum² / (2 × mass)) + potential_energy
29+ H = (momentum² / (2 * mass)) + potential_energy
2730
2831 Parameters:
2932 mass (float): Mass of the particle (must be positive).
@@ -74,19 +77,22 @@ def quantum_hamiltonian_1d(
7477 This turns the continuous operator into a discrete matrix.
7578
7679 Formula:
77- H[i, i] = (ħ² / (m × Δx²)) + V[i]
78- H[i, i±1] = - (ħ² / (2m × Δx²))
80+ H[i, i] = (ħ² / (m * Δx²)) + V[i]
81+ H[i, i±1] = - (ħ² / (2m * Δx²))
7982
8083 Parameters:
8184 mass (float): Mass of the particle. (must be positive)
8285 hbar (float): Reduced Planck constant. (must be positive)
83- potential_energy_array (np.ndarray): Potential energy values V(x) at each grid point.
84- grid_spacing (float): Distance between consecutive grid points Δx. (must be positive)
86+ potential_energy_array (np.ndarray): Potential energy values V(x)
87+ at each grid point.
88+ grid_spacing (float): Distance between consecutive grid points Δx.
89+ (must be positive)
8590 round_to (int | None): Number of decimal places to round the matrix to.
8691 If None (default), no rounding is applied.
8792
8893 Returns:
89- np.ndarray: The discrete Hamiltonian matrix representing the total energy operator.
94+ np.ndarray: The discrete Hamiltonian matrix representing
95+ the total energy operator.
9096
9197 Examples:
9298 >>> import numpy as np
0 commit comments