On two occasions we put a magnet near a compass.
While in Trinidad I put a VHF on the pedestal. We headed out for Granada to find that we were going East. In fact we were going East any direction we went. After scratching our heads we realized that the new VHF was about a foot from the compass and moved it further away. It was weird as we were in the middle of a squall at the time we realized what was happening and couldn't see much past the bow of the boat. We're scrambling for screwdrivers while the wind and rain was pelting us in bad visibility.
The other time we were leaving St Thomas heading toward the Turks and Cacios. On our way out of the harbor I switched on the autopilot to go to the mast to raise the main. The boat did a 180 and headed back to the anchorage. I tried it three times. Each time it turned the boat around. Damn,,, a broken autopilot and we have 400 miles to go. We decided to stop in the Spanish Virgins to see what was going on. It took 2 hours to find the problem. It seems that the Admiral, in an effort to stow items to be installed later put our new loud hailer in it's box directly against the fluxgate compass. The magnet must have been about 2 inches away. I moved the hailer and the problem was resolved.
Two interesting magnet and compass problems.