calculate average energy density on arbitrary length interval