Force of electromagnet on piece of iron

I can find equations to give the force of an electromagnet on a piece of iron when the iron touches the electromagnet.

But what about when the iron is some distance from the electromagnet? Presumably the force depends on the shape/size of the iron piece as well as the location of the piece away from the magnet.

If anybody can tell me how to calculate this, even if I have to write a numerical calculation routine, I would appreciate any direction on this.

-
Are you just asking about the force exerted by a magnetic dipole? –  Kitchi Feb 11 '13 at 21:23
You'd have to solve for the magnetic field first, which will be function of the pemiability and shape of the core and the other piece. Then you could integrate the force. Probably only possible in practise to do computationally with some sort of finite element technique for other than special case controlled shapes. –  Olin Lathrop Feb 11 '13 at 21:47
You'll have hysteresis, so not only is this going to be horribly complicated but it will depend on the history of the system. –  Ben Crowell Aug 21 '13 at 21:53

I believe you can approximate the iron as a collection of dipoles, and calculate the potential energy as $$\frac{1}{2} \int(MB)\rm{d}V$$ over the volume of the iron, where $M$ is the magnetization and $B$ is the total field. This becomes impossibly difficult with a nonlinear magnetic material and an asymmetrical magnet. As always, the gradient of potential energy gives force. Good luck.
The equation $F=(NI)^2\mu_0A/2g^2$ should help. This equation gives the force in Newtons of an electromagnet given the number of turns in the electromagnetic coil ($N$), the current flowing through the electromagnet ($I$), the magnetic permeability of a vacuum ($\mu_0$, or just mu _0 in Google), the cross-sectional frontal area of the ferromagnetic material ($A$), and the distance of the ferromagnetic material ($g$). The units for $A$ and $g$ are arbitrary, as long as you're consistent with the usage. $F$ will always be in Newtons, and $\mu_0$ is a constant of nature (sometimes called the magnetic constant).