Analytical maximum likelihood estimation of stellar magnetic fields