A variational method for unconstrained optimization problems