  Using first-principles calculations based on density functional theory (DFT),
we investigate the exchange interaction between a magnetic tip and a magnetic
sample which is detected in magnetic exchange force microscopy (MExFM) and also
occurs in spin-polarized scanning tunneling microscopy (SP-STM) experiments. As
a model tip-sample system, we choose Fe tips and one monolayer Fe on W(001)
which exhibits a checkerboard antiferromagnetic structure and has been
previously studied with both SP-STM and MExFM. We calculate the exchange forces
and energies as a function of tip-sample distance using different tip models
ranging from single Fe atoms to Fe pyramids consisting of up to 14 atoms. We
find that modelling the tip by a single Fe atom leads to qualitatively
different tip-sample interactions than using clusters consisting of several
atoms. Increasing the cluster size changes the calculated forces quantitatively
enhancing the detectable exchange forces. Rotating the tip with respect to the
surface unit cell has only a small influence on the tip-sample forces.
Interestingly, the exchange forces on the tip atoms in the nearest and
next-nearest layers from the apex atom are non-negligible and can be opposite
to that on the apex atom for a small tip. In addition, the apex atom interacts
not only with the surface atoms underneath but also with nearest-neighbors in
the surface. We find that structural relaxations of tip and sample due to their
interaction depend sensitively on the magnetic alignment of the two systems. As
a result the onset of significant exchange forces is shifted towards larger
tip-sample separations which facilitates their measurement in MExFM. At small
tip-sample separations, structural relaxations of tip apex and surface atoms
can either enhance or reduce the magnetic contrast measured in SP-STM
