  Observations and semianalytical galaxy formation and evolution models (SAMs)
have suggested the existence of a stellar mass-stellar metallicity relation
(MZR), which is shown to be universal for different types of galaxies over a
large range of stellar masses ($M_*\sim 10^3$-$10^{11}M_\odot$) and dark matter
(DM) halo masses ($M_{\rm halo}\sim 10^9$-$10^{15}h^{-1}M_\odot$). In this
work, we construct a chemical evolution model to investigate the origin of the
MZR, including both the effects of gas inflows and outflows in galaxies. We
solve the MZR from the chemical evolution model, by assuming that the cold gas
mass ($M_{\rm cold}$) and the stellar feedback efficiency ($\beta$) follow some
power-law scaling relationships with $M_*$ during the growth of a galaxy, i.e.,
$M_{\rm cold}\propto M_*^{\alpha_{\rm gs}}$ and $\beta\propto
M_*^{\alpha_{\beta{\rm s}}}$. We use the SAM to obtain these power-law scaling
relations, which appear to be roughly universal over a large range of stellar
masses for both satellites and central galaxies within a large range of halo
masses. The range of the MZRs produced by our models is in a narrow space,
which provides support to the universality of the MZRs. The formation of the
MZR is a result caused jointly by that the cold gas fraction decreases with
increasing $M_*$ and by that the stellar feedback efficiency decreases with
increasing $M_*$ in the galaxy growth, and the exponent in the MZR is around
$-\alpha_{\beta{\rm s}}$ or $1-\alpha_{\rm gs}$. The MZR represents an
''average'' evolutional track for the stellar metallicity of a galaxy. The
comparison of our model with some previous models for the origin of MZRs is
also discussed.
