## Quantum Harmonic Oscillator

The quantum harmonic oscillator is a mathematical model that describes the behavior of a particle oscillating around an equilibrium point constrained to move along an axis with a harmonic potential. The system is described by the Hamiltonian:
$$\hat{H} = \frac{\hat{p}^2}{2m} + \frac{1}{2}m\omega^2\hat{x}^2$$
where $m$ is the mass of the particle and $\omega$ is the frequency of harmonic motion.

The solution of the Schrödinger equation for the quantum harmonic oscillator is known and is given by the Hermite functions, which represent the stationary states of the oscillator. These states are quantized and their energy is given by the formula:
$$ E_n = \hbar \omega \left( n + \frac{1}{2} \right) $$

The quantum harmonic oscillator has several applications in physics, particularly in quantum mechanics and quantum field theory. For example, it is used to describe the behavior of bound atoms and simple molecules, as well as to describe the behavior of subatomic particles such as electrons in a magnetic field. This is a very important mathematical model because it is one of the few quantum physical system models for which an exact analytical solution of the Schrödinger equation can be found. This makes the quantum harmonic oscillator one of the most studied models in quantum mechanics.

The code solves the eigenvalue problem of the quantum harmonic oscillator $1$D, setting $\hbar = \omega = 1$ for simplicity. In order to solve the problem, the discretization solution is adopted: in theory, the space is continuous, consisting of an infinite number of points. Unfortunately, the reasoning cannot be applied at the practical level where we can only deal with a finite number of points. So we want to adopt a very small step $dx$ in order to approximate the continuous model as best as possible. The discretization produces a simpler tridiagonal Hamiltonian $H_{discr}$, where in the main diagonal we find the terms $-2+V(x_i)$ and in the sub-diagonals we find $-1$.

The

**function takes as input the minimum and maximum value of the $x$-axis, the discretization step of the $dx$ grid, and the number of eigenvalues to be computed.**

*'quantum_harmonic_oscillator*First, the range of the $x$-axis, its mean value, and the number of steps within the range are calculated. Next, a matrix of the potential of the quantum harmonic oscillator and an associated diagonal matrix is created. The diagonal matrix consists of the sum of the potential and a constant. In addition, a subdiagonal to the tridiagonal matrix with constant values is created, so that $H_{disc}$ is obtained.

The eigenvalue problem is solved using the

**function from the module**

*'eigh_tridiagonal'***. This function returns the eigenvalues and eigenvectors of the tridiagonal matrix from its three diagonals.**

*'scipy.linalg'*Finally, the

**function prints a table of the expected eigenvalues, the calculated eigenvalues, and the percentage difference between the two. In addition, a graph is generated showing the eigenvalues and eigenvectors of the quantum harmonic oscillator.**

*'print_results'*The quantum harmonic oscillator is a mathematical model that describes the behavior of a particle oscillating around an equilibrium point constrained to move along an axis with a harmonic potential. The system is described by the Hamiltonian:
$$\hat{H} = \frac{\hat{p}^2}{2m} + \frac{1}{2}m\omega^2\hat{x}^2$$
where $m$ is the mass of the particle and $\omega$ is the frequency of harmonic motion.

The solution of the Schrödinger equation for the quantum harmonic oscillator is known and is given by the Hermite functions, which represent the stationary states of the oscillator. These states are quantized and their energy is given by the formula:
$$ E_n = \hbar \omega \left( n + \frac{1}{2} \right) $$

The quantum harmonic oscillator has several applications in physics, particularly in quantum mechanics and quantum field theory. For example, it is used to describe the behavior of bound atoms and simple molecules, as well as to describe the behavior of subatomic particles such as electrons in a magnetic field. This is a very important mathematical model because it is one of the few quantum physical system models for which an exact analytical solution of the Schrödinger equation can be found. This makes the quantum harmonic oscillator one of the most studied models in quantum mechanics.

The code solves the eigenvalue problem of the quantum harmonic oscillator $1$D, setting $\hbar = \omega = 1$ for simplicity. In order to solve the problem, the discretization solution is adopted: in theory, the space is continuous, consisting of an infinite number of points. Unfortunately, the reasoning cannot be applied at the practical level where we can only deal with a finite number of points. So we want to adopt a very small step $dx$ in order to approximate the continuous model as best as possible. The discretization produces a simpler tridiagonal Hamiltonian $H_{discr}$, where in the main diagonal we find the terms $-2+V(x_i)$ and in the sub-diagonals we find $-1$.

The

**function takes as input the minimum and maximum value of the $x$-axis, the discretization step of the $dx$ grid, and the number of eigenvalues to be computed.**

*'quantum_harmonic_oscillator*First, the range of the $x$-axis, its mean value, and the number of steps within the range are calculated. Next, a matrix of the potential of the quantum harmonic oscillator and an associated diagonal matrix is created. The diagonal matrix consists of the sum of the potential and a constant. In addition, a subdiagonal to the tridiagonal matrix with constant values is created, so that $H_{disc}$ is obtained.

The eigenvalue problem is solved using the

**function from the module**

*'eigh_tridiagonal'***. This function returns the eigenvalues and eigenvectors of the tridiagonal matrix from its three diagonals.**

*'scipy.linalg'*Finally, the

**function prints a table of the expected eigenvalues, the calculated eigenvalues, and the percentage difference between the two. In addition, a graph is generated showing the eigenvalues and eigenvectors of the quantum harmonic oscillator.**

*'print_results'*