Deriving an equation to calculate the forces between cylindrical magnets is harder than for cuboid magnets (for which a closed form solution was first published in 1984).
Most recently, Ravaud et al. published (2010) an closed form expression for the force between coaxial magnetic cylinders, for which I've currently a paper in publication with a much simpler equation. You can download my code for implementing this in my repository of magnet code; the Matlab example is ‘examples/ravaud-cylmag.m’ and the Mathematica example has extension ‘.nb’ with the same name.
The force equation for coaxial magnets contains elliptic integrals, and when analysing the system for eccentric displacements in the radial direction the integral becomes, as far as I know, not possible to solve tractably. I'm aware of two different approaches for calculating the forces for these cases. The first is by Nagaraj in a somewhat-elusive paper from 1988 who simplifies the necessary integrals until only a double-integral that can be evaluated numerically. (A numerical evaluation of a nicely-behaved integral is typically around an order of magnitude slower than if a closed form solution is known.)
A more recent analysis of eccentric magnetic cylinder forces was published in 2009 by Vokoun et al., and to be honest their approach is a little alien to me; I haven't looked into their maths very much and I don't know if the implementation would be harder and/or more efficient than the approach used by Nagaraj.
Implementations of these latter two papers would be very useful for us at the moment but I don't have time to do it myself right now; I have some honours students who might step up to the plate. If so, I'll add their code to the magcode repository; a common theme with all this code is that a reference implementation saves people so much time when they need to use the theory publicised by these authors.
The DOIs for the papers mentioned above are:
- Akoun & Yonnet 1984: 10.1109/TMAG.1984.1063554
- Ravaud 2010: 10.1109/TMAG.2010.2049026
- Nagaraj 1988: 10.1080/10402008808981815
- Vokoun 2009: 10.1016/j.jmmm.2009.07.030