Magnetic energy and electric energy are related by Maxwell's equations. The potential energy of a magnet of magnetic moment, m, in a magnetic field, B, is defined as the mechanical work of magnetic force (actually of magnetic torque) on re-alignment of the vector of the Magnetic dipole moment, and is equal: