Energy loss of a Korteweg–de Vries solitary wave in a slowly varying medium