 In general the demagnetizing field is a function of position .It is derived from the magnetostatic equations for a body with no electric currents.These are Ampère's law

and Gauss's law

The magnetic field and flux density are related by

where formula_1 is the permeability of vacuum and is the magnetisation.