Unfortunately, in real life we cannot magically switch a permanent magnet’s poles.
We can, however, exchange the top magnet for an electromagnet.
And while we will still need the lower permanent magnet, this time we’ll add iron "pole pieces" to trap its magnet field (in green) and redirect it along the axis of the upper electromagnet.