Theory of the magnetomechanical effect