  Magnetic field inhomogeneity is usually detrimental to magnetic resonance
(MR) experiments. It is widely recognized that a nonuniform magnetic field can
lead to an increase in the resonance line width, as well as a reduction in
sensitivity and spectral resolution. However, nonuniform magnetic field can
also cause shift in resonance frequency, which received far less attention. In
this work, we investigate the frequency shift under arbitrary nonuniform
magnetic field and boundary relaxation by applying perturbation theory to the
Torrey equation. Several compact frequency shift formulas are reported. We find
that the frequency shift is mainly determined by $B_z$ distribution (rather
than the transverse field components in previous study) and has important
dependence on boundary relaxation. Furthermore, due to the difference of
boundary relaxation and high order perturbation correction, this frequency
shift is spin-species dependent, which implies a systematic error in many MR
based precision measurements such as NMR gyroscope and comagnetometers. This
insight provides a potential tool for understanding the unexplained isotope
shifts in recent NMR gyroscope and new physics searching experiments that
utilize comagnetometers. Finally, we propose a new tool for wall interaction
research based on the frequency shift's dependency on boundary relaxation.
