Variational methods and optimization