A variational method for functions with positive real part