Theoretical approach for calculation of dielectric functions of plasmonic nanoparticles of noble metals, magnesium and their alloys