# Is it correct to say “like poles attract, unlike poles repel” while two magnets are placed such that one is inside another?

As we know a solenoid is considered as a electromagnet(magnet) if there's a current flowing through it. if a soft iron core is placed inside the solenoid, the former get magnetised. Consider the solenoid as a hollow bar magnet, and the magnetised soft iron core inside as a bar magnet. The poles of the magnets next to each other is of same polarity. Is there attracting force between the two magnets? If so, does it mean "like poles attract, unlike poles repel" while two magnets are placed such that one is inside another?

-

"Like poles repel, unlike poles attract" is kind of a misleading analogy(I find it strange that I realized this after reading your question).

What actually is happening is that the tiny magnetic dipoles inside the magnetic material(a bar of iron, for example) align with the direction of the magnetic field. Look at this field line diagram of a bar magnet.

Observe that the field to the right of the north pole is rightward in direction. Now what happens if you place a tiny magnetic dipole in this region?

It will rotate and try to align with the direction of the magnetic field. That means its magnetic dipole moment vector will have the same direction as the magnetic field vector. The North-South poles of this dipole will arrange in such a way that the south pole faces the north pole of the magnet.

Now consider the case of a large bar of iron, which has similar numerous tiny dipole described above, whose directions are randomly oriented and cancel out in the absence of a magnetic field. When you bring this bar near to the north pole of the magnet, all those tiny dipoles align with the direction of the magnetic field inside the bar. This leads to a greater net dipole moment of the bar, which we also refer to as the north-south poles of this bar. Observe that the south pole will be formed near the north pole.

The same thing happens when you place this bar inside a solenoid. Suppose you have a solenoid whose field inside goes from left to right. The net dipole moment you'll observe will be such that the south pole is towards the left, and the north pole towards the right. This you see as the north pole forming near the north pole of the solenoid.

All that is happening is that the tiny magnetic dipoles are aligning in direction to the magnetic field.

-
However if you consider a permanent bar magnet kept in a solenoid, and the solenoid was large enough such that the bar magnet could rotate in any arbitrary direction, once the solenoid is switched on, the bar magnet will align itself with the solenoid's field. This has to do with minimizing the energy in the magnetic field. The energy is given by $$E = - m .\vec{B}$$
so clearly if $m$ and $B$ are in the same direction, it is a lower energy configuration than if $m$ and $B$ are in opposite directions.