Theory of the de Haas-van Alphen Effect in a System of Coupled Orbits. Application to Magnesium