# 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.

-

A solenoid induces a magnetic field in the iron bar kept inside it. This is not the same as inserting a permanent bar magnet inside the solenoid.

The induced magnetic field is in the same direction as the original magnetic field. One way of thinking about this is that the domains in the iron bar line up with the external field, producing a net magnetic field in the same direction as the original.

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.

-

A solenoid can behave like a bar magnet but its not a bar magnet. When a current is passed through a solenoid magnetic field is induced in and around it, field lines of which resemble those of a bar magnet. But the solenoid does not become a bar magnet, we do not talk about north pole and south pole of a solenoid. Its just a magnetic field created like the magnetic field created around a current carrying wire, field lines of which encircles the wire. A magnet needle placed in the magnetic field, $B$, of a current carrying wire will align itself in the way that the field lines of $B$ will appear to enter the S-pole of the needle and leave the N-pole.
Similarly, if you put a bar magnet inside a solenoid the bar magnet will align itself with the field inside the solenoid in the same way as shown in the figure.

The bigger rectangle is the solenoid and the smaller one is a bar magnet. Field lines inside the solenoid enters the S-pole of the bar magnet and leaves the N-pole.
If we put a soft iron core in place of the bar magnet, the field lines inside the solenoid will be concentrated inside the core because of its high permeability relative to air. The field will align the dipoles in the core like the bar magnet in the previous explanation.

-