# Solving Hydrogen atom numerically with 14 lines of Matlab code

Let’s have a look the code first(They were wrote by Mikael Kuisma in this vedio):

These code calculated the ground state energy of Hydrogen atom(You can run the code online in this website).

Result: Energy: 13.321eV

## Theory

The Hamiltonian of electron in the Hydrogen is (in Atomic units):

$$H = -\frac{1}{2} \nabla^2 - \frac{1}{r}$$

In order to calculate the energy levels and wave functions of Hydrogen, we have to solve the t-independent Schrodinger equation of the electron in a Hydrogen atom is

$$H \psi_n = E_n \psi_n$$

Generally speaking, $$H$$ is an Oprator, $$E_n$$ is its eigenvalues and $$\psi_n$$ is the corresponding eigenvactors.
In continus space, the Hamiltonian is complicated as it contains second derivatives(the Laplacian: $$\nabla^2$$).

However, if we discretize the space, the wave function becomes a column vector, and the Hamiltonian can be expresse’d as
a matrix. As it is an opration on the vector.
In this way, the problem is transformed to “find eigenvactors and eigenvalues of a matrix”. And matlab is an expert about this kind of job.

In order to get this matrix form of $$H$$, the hard part is to the Laplacian. And this link
tells you how to get the “discrete Laplacians”.

## Code explanation

Comment by the code owner:

There is a special trick with the grids. We take a 3d grid with dimensions g times g times g.
We flatten the 3d-array to a vector of dimensions 1 x g^3.
The hamiltonian operator is a linear mapping in this vector space,
thus a g^3 x g^3 array.
After we have calculated the wave function, we can reshape it back from vector representation to 3