Variational treatment of electrostatic interaction force in atomic force microscopy