Magnetic energy and electrostatic potential energy are related by Maxwell's equations. The potential energy of a magnet of magnetic moment m {displaystyle mathbf {m} } in a magnetic field B {displaystyle mathbf {B} } is defined as the mechanical work of the magnetic force (actually magnetic torque) on the re-alignment of the vector of the Magnetic dipole moment and is equal to: Magnetic energy and electrostatic potential energy are related by Maxwell's equations. The potential energy of a magnet of magnetic moment m {displaystyle mathbf {m} } in a magnetic field B {displaystyle mathbf {B} } is defined as the mechanical work of the magnetic force (actually magnetic torque) on the re-alignment of the vector of the Magnetic dipole moment and is equal to: while the energy stored in an inductor (of inductance L {displaystyle L} ) when a current I {displaystyle I} flows through it is given by: