Force on a magnetic dipole due to a magnetic field Imagine a solenoid which has current $i$ and is producing a magnetic field $B$ which equals $$B=\mu N i$$

Now, imagine we put a small cylindrical magnet at the end of the solenoid.
Then because at end of the solenoid, field lines start diverging and are not parallel, a force is exerted on the magnet from the magnetic field created by the solenoid.
What is the magnitude of this force?
 A: Depends on the orientation of the magnet at the end of the solenoid as to how strong the force is.
This is the equation that governs how the current in the solenoid creates the magnetic field around it
$ \nabla \times B = \mu_0 j $ where j is the current density.
This equation shows the potential that can be created from a magnetic field on something charged
$ U = \mu B $ where $\mu$ is the dipole moment.
for using $ F = \frac{dU}{dx} $
so we can say that $ F = \mu \frac{\partial B}{\partial x} $
Similarly, the magnetization  is the net magnetic dipole moment in the material:
$M = N \mu $ or $ M $ ~ $ \mu $
therefore the force exerted would be:
$ F = M \frac{\partial B}{\partial x} $
This can be shown in more detail using the material versions of Maxwell's equations, but the main idea behind it is that a magnetic field B acts on the magnetic dipole moments of another magnetic material.
A: Assuming that the magnetic moment (or N-S axis) of the cylindrical magnet  is horizontally oriented, i.e., same as the magnetic moment of the solenoid, the force between them will be also horizontally oriented. 
The cylindrical magnet will be attracted or repelled by the solenoid, depending on the orientation of magnetic poles. The magnitude of that force will depend on the strength of the individual magnetic fields of the solenoid and the cylindrical magnet and the distance between them. 
It won't be fundamentally different than the force between two current carrying solenoids or two permanent magnets. The direction of attraction or repulsion forces will be such that it'll force the magnets to move in the direction minimizing the total magnetic field or, more precisely, minimizing the total magnetic field energy.
