calculate the kinetic and potential energy