wrote function to calculate full energy