# Visually and physically reasonable analytic approximation to the field of a bar magnet

I want to produce publication-quality drawings of the field of a bar magnet, in both the field line representation and as a "sea of arrows." I've found some open-source software that looks like it will do this (matplotlib, with the quiver and streamplot functions), but it would be convenient to have some closed-form equation that would produce a good enough expression for the field.

In principle I guess there is a physically well-defined statement to the problem with a well-defined solution. You would have a cylinder or rectangular box made of a uniformly magnetized, highly permeable material. However, I don't really care if it's the right solution to some idealized version of the problem, as long as it looks reasonable (compared to photos of iron filings) and is physically admissible (e.g., it would be bad if it had a nonvanishing divergence).

Any suggestions on how to cook up a reasonable analytic expression that will look sort of right? It would probably have two different forms on the interior and exterior, with discontinuities in the field at the surface.

Maybe the thing to do is to start from a magnetic potential $$\textbf{A}$$, then distort it somehow, then take its curl. That way we would be guaranteed to get a $$\textbf{B}$$ with a vanishing divergence. I don't really care if the calculus is a little messy, as long as it's closed form. I can crank out an ugly curl using a computer algebra system.

Maybe another possibility would be just to add up a multipole expansion up to some order, and fiddle with the coefficients, but it seems like this could take a lot of trial and error, and the abrupt kinks in the field lines at the surfaces would seem impossible to reproduce with a finite number of terms.

• You should be able to treat it as a medium with a uniform permeability and fixed magnetization. You can then calculate the $\textbf{H}$ field everywhere, which should be continuous. When you calculate the $\textbf{B}$ field you will get the kink at the surface which you are looking for. – jgerber Nov 15 '18 at 23:07