Bose–Einstein condensates in the presence of a magnetic trap and optical lattice: two-mode approximation