Localization of Bose-Einstein condensates in optical lattices