A variational approach to complex Monge-Ampère equations