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 and wavelength of a light?
like this image:
(source: kms at www1.appstate.edu)
sorry if this was irrelevant :-]
There is a relationship between frequency and what is known as Hue, but for complicated reasons of perception, monitor gamut, and calibration, the best you can achieve outside of expensive lab equipment is a gross approximation.
See http://en.wikipedia.org/wiki/HSL_and_HSV for the math, and note that you'll have to come up with your best guess for the Hue ⇔ Frequency mapping. I expect this empirical mapping to be anything but linear.