The problem of RGB values to represent a real color is incredibly complex.
First, you have the actual spectrum P(f). Then you have the eye's response functions S(f), M(f), L(f). And finally, you have the spectra for RGB components, R(f), G(f), B(f). Your goal is to find such a set of positive numbers r,g,b that the following holds.
\int_{0}^{\infty} S(f)P(f) df = \int_{0}^{\infty} S(f)(rR(f)+gG(f)+bB(f)) df
\int_{0}^{\infty} M(f)P(f) df = \int_{0}^{\infty} M(f)(rR(f)+gG(f)+bB(f)) df
\int_{0}^{\infty} L(f)P(f) df = \int_{0}^{\infty} L(f)(rR(f)+gG(f)+bB(f)) df
Naturally, there is no general solution, but you can usually find a decent approximation. Of course, for that, you'd ideally need to know S(f), M(f), L(f), which, being physiological, aren't even the same for everyone, but there are some descent approximations out there.
You can probably
start with this article and work up from there.
I had to dig through a lot of that stuff when I was writing some code to simulate the stars in the sky realistically, or at least believably, based on spectral types. Converting from temperature, to spectrum, to RGB was a major pain.