Repulsive Force between two Electromagnets

This question might seem a bit too basic(or advanced!), but it is the one to which I'm really desperate to find a simple enough explanation and solution.

Ok, So here's the problem,

I have two identical electromagnets with a field strength $B$ each. Each of radius $r$ and length $l$ with $N$ turns say, how do I calculate the net repulsive/attractive force between them if

1. they attract each other and are pulled apart or
2. they repel each other and are pushed against each other

I want to levitate one magnet carrying a weight (so its stabilized) above the other electromagnet. Even if the solution is for different fields it is no problem.

• Wikipedia has a long list of examples of such calculations. Sep 10, 2015 at 18:53
• Sebastian Riese gave you a good pointer there, but unfortunately it's not going to work for scenarios with ferromagnetic materials, which you will need, if you want to make this work. You could use a simulation program like MaxFem for the calculations, but there is a rather steep learning curve associated with that. As a practical pointer: start with permanent magnets and figure out a way to use a weak electromagnet just for stability control. Do not try to create the load bearing magnetic field with an electromagnet, cheap electromagnets don't have the power density of permanent magnets. Sep 10, 2015 at 20:20
• @Winther: My first site to visit was Wikipedia but it did not specify for electromagnets. Sep 11, 2015 at 13:48
• @CuriousOne: Since I already have the materials for making an electromagnet, I didn't want to use permenant magnets. Besides, if I use electromagnet I could easily vary the magnetic field in real time for future changes. Sep 11, 2015 at 13:51
• And you will need those material to control the levitation. All I am saying is that you will find it much easier to do if you start with permanent magnets to create >90% of the required forces. You don't have to do it this way, it just turns out to be the by far better approach. Sep 11, 2015 at 13:57

$$\vec F = I \oint_{\gamma_2} d\vec r \times \vec B(\vec r).$$
Where $\vec B(\vec r)$ is the field generated by coil 1 and $I$ is the current in coil 2 and the integral is along the curve $\gamma$ which is described by the wires of the coil 2. Note, that there might also be a torque.
Knowing the maximal or homogeneous field $B$ in the interior of the coils does not help much.
The field of the coil is given by the Biot-Savart law: $$\vec B(\vec r) = \frac{\mu_0 I}{4\pi} \int_{\gamma_1} \frac{d\vec r' \times (\vec r - \vec r')}{\left| \vec r - \vec r' \right|^3}.$$