Simulating an electromagnet in MATLAB

Simulating an electromagnet in MATLAB

Simulating an electromagnet in MATLAB

It will be quite a lie to say that there is any person in the world who is not fascinated by magnets.  We all love to play around with magnets, attracting safety pins on the desk to the keys of our bike. We are unaware of that sometimes, but we actually are in love with the magnets.

So, since this is a case of love, it becomes complicated. Therefore magnets are of different types:

Broadly magnets are divided into two categories:

  1. Permanent magnets: These are magnets which have persistent magnetic ability . Unless they are heated above a temperature, or vigorously hit with a hammer.
  2. Secondary magnets: These are electromagnets, and gave the magnetic ability when current is allowed to flow around a core. These equations follow the Maxwell’s equation.

As a part of my job, I have to work with a lot of these electromagnets. The design of the electromagnets must be robust and we must also have sufficient magnetic field at the desired point for the business. So before we build the magnet we employ some simulations for calculating the magnetic field.

One such simulating program has been attached here. This just gives the field at the plane of the solenoid. The program runs in Matlab, so make sure you have the necessary software to run it.

B field lines due to the electromagnet

For more accurate simulations, I will prefer the PDE toolbox in matlab, and the FEMM software.

So go through the description in the pdf files before you run the program. Have fun, and post if you got any suggestions or corrections.

“But still try for who knows what is possible!”
Michael Faraday


Matlab code:

Originally Published on Oersted –