Updated 12 Jan 2020
Collection of functions for the generation the magnetic flux density of axially magnetized cylinders (equivalently of solenoids) and axially magnetized rings. The implemented model used for all the calculations can be found in the article:
 Derby, Norman, and Stanislaw Olbert. “Cylindrical Magnets and Ideal Solenoids.” American Journal of Physics 78.3 (2010): 229–235. Crossref. Web .
For an efficient computation of the field, you can find an implementation of the Bulirsch algorithm, which can compute in a fast way (according to a specified tolerance) a generalized complete elliptic integral, also known as Bulirsch's integral. Ref.  reports the algorithm in the Appendix, however you can also check:
for additional information about the relationships of the generalized complete elliptic integral (cel) with the complete elliptic integrals K (first kind), E (second kind) and Pi (third kind). In particular the developed function can be adopted for an efficient computation of the complete elliptic integrals, since it performs better than the original built-in Matlab function ellipke and ellipticPi.
Additionally this repository provides some fancy functions to draw the cylindrical permanent magnets and ring magnets with custom choice of position, orientation, size and appearance (pattern and color), and functions to draw vectors and reference frames (e.g. to show the magnetic moment vector of the magnets).
The code is provided with a lot of comments and some useful DEMOs which also provides the plot of the magnetic flux density (thanks to David CEBRON for the useful code of the plots and for his very nice documentation, https://it.mathworks.com/matlabcentral/fileexchange/71881-magnetic-fields-of-solenoids-and-magnets).
Federico Masiero (2021). Magnetic Field Modeling (https://github.com/ApeParrot/Magnetic-Field-Modeling), GitHub. Retrieved .
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!