calculated the energy of the system