Can I use magnets with opposite polarities to make a levitating sphere?

I’m trying to make a sphere that levitates inside a hemisphere cup lined with magnets glued down with all poles facing the same direction. The sphere is styrofoam lined with magnets with all the poles facing the same direction. So the hemisphere cup has magnets facing with the north pole out and the ball also has all of its north pole facing out. The cup covers about half the sphere, so the ball fits right inside. Is this possible to do?

I think Periphrasis has the right idea.

Some points to keep in mind:

You don’t want the magnets on the ball to touch each other. If they do, they will tend to act as one large magnet, with north on one side of the ball and south on the other.

You have to keep in mind that what will make the ball balance is equilibrium. In order to have a stable equilibrium, the geometry and the forces have to work in such a way that any displacement of the ball will create forces pushing it back toward the equilibrium position.

If the ball moves down, the repellent force needs to increase, so that it will move back up.

If it moves too high, the repellent force needs to decrease so that it will move back down.

If it gets off to one side, the force pushing it away from that side needs to increase (and the opposing force decrease), so that it moves back to the equilibrium position.

As Periphrasis points out, the upward force could pop it out of the cup. In particular, if it gets too high AND off to one side, it is doubtful that the lateral forces will be effective enough (once it rises above the sides) to move it back to the center.

Good luck!