Stabilizing Effect of Mg on the Energetics of the Li(Ni,Co,Al)O2 Cathode Material for Lithium Ion Batteries