A new method on constructing analytical potential energy functions is presented, and then a relatively universal analytical potential energy function for precisely calculating the spectra of diatomic molecules and ions is derived. Furthermore, six kinds of common potential energy curves containing three main potential curves i.e. steady state, metastable state and repulsive state are obtained from this potential energy function. Finally, spectroscopic parameters of thirteen diatomic molecules and ions including 2 2BeD-, BeT-X X + + and 1 2 Nag X + etc are calculated by using the potential function, as a consequence, all calculation results are in good agreement with experimental data.Analytical potential energy functions are of great significance in the study of material science, molecular spectrum reaction dynamics of atoms and molecules, vibrational and rotational energy-level structures of molecules, interactions between laser and matter, photoionization etc [1][2][3][4][5][6][7] . So far, the representative analytical potential energy function are Morse potential, Rydberg potential, Murrell-Sorbie (MS) potential. Huxley-Murrell-Sorbie (HMS) potential and TT potential etc. Recently, Sun et al [8] have proposed an energy-consistent method (ECM) and a potential function of a diatomic system called ECM potential. In this paper, a cosine function with a phase factor is used as basic potential energy function through renormalization to the phase factor, a relatively universal potential energy function applied to both neutral diatomic molecules and charged diatomic molecular ions is given. Spectroscopic parameters of thirteen diatomic molecules and ions are calculated and compared with experimental data.