I need an algorithm or function to map each wavelength of visible range of spectrum to its equivalent RGB values. Is there any structural relation between the RGB System an
If you want an exact match then the only solution is to perform a convolution of the x,y,z color matching functions with your spectral values so you finally get a (device-independent) XYZ color representation that you can later convert into (device-dependent) RGB.
This is described here: http://www.cs.rit.edu/~ncs/color/t_spectr.html
You can find the x,y,z color matching function for convolution here: http://cvrl.ioo.ucl.ac.uk/cmfs.htm