For a given spectral power distribution, $P(\lambda)$, of an emissive source (e.g. a monitor), the XYZ tristimulus values are computed like this:

$$X = \intop_\lambda \bar x (\lambda) P(\lambda) d\lambda$$ $$Y = \intop_\lambda \bar y (\lambda) P(\lambda) d\lambda$$ $$Z = \intop_\lambda \bar z (\lambda) P(\lambda) d\lambda$$where $\bar x$, $\bar y$ and $\bar z$ are the CIE standard observer functions (either 2 degree or 10 degree, depending on the application). The integrals are computed over the visible spectrum (about 360 to 830 nm).

But in practice, the functions found in these integrals exist either from empirical experiment or by measurement. Therefore, there are not mathematical equations representing them. Instead, they exist as discrete samples and so the integrals are replaced by summations:

$$X = \sum_i \bar x_i P_i \Delta \lambda$$ $$Y = \sum_i \bar y_i P_i \Delta \lambda$$ $$Z = \sum_i \bar z_i P_i \Delta \lambda$$Here there are questions of the wavelength span that is used as well as the sample spacing. The standard observer functions are greater than zero over the span of 360 to 830 nm. The spectral power distribution span may be less than that, depending on the mesuring device used. The sample spacing is typically in the range of 1 to 20 nm. In order to perform the summations, the spans and spacings of the standard observer functions must match those of the spectral power distribution of the sample. Resampling, interpolation and possibly even extrapolation are used to accomplish this.

Cases involving reflective and transmissive samples have strong similarities to, and important differences from the emissive case described above. The spectral power distribution of the sample, $P(\lambda)$, is replaced by the spectral reflectance (or transmittance) of the sample, $S(\lambda)$ multiplied by the spectral power distribution of a reference illuminant $I(\lambda)$:

$$X = {{1} \over {N}} \intop_\lambda \bar x (\lambda) S(\lambda) I(\lambda) d\lambda$$ $$Y = {{1} \over {N}} \intop_\lambda \bar y (\lambda) S(\lambda) I(\lambda) d\lambda$$ $$Z = {{1} \over {N}} \intop_\lambda \bar z (\lambda) S(\lambda) I(\lambda) d\lambda$$ $$N = \intop_\lambda \bar y (\lambda) I(\lambda) d\lambda$$Why is a reference illuminant needed? If you consider the emissive case, where the color sample is viewed in a dark room, you can
see its color because it is generating the light. However, when viewing a reflective (or transmissive) sample in that same environment
you see nothing at all because such a sample does not generate light. The only way it can be seen is by first illuminating it. It is
obvious that the appearance of the sample color is influenced by the type of illumination it receives. In order to make the XYZ value
of a color sample unambiguous, the illuminant must be somehow identified and associated with it. This poses a problem since there are
infinitely many possible illuminants. So instead of using an actual illuminant, a *reference* illuminant is used instead. Common
reference illuminants are C, D50, D65 and others. The reference illuminant of an XYZ is simply made by reference. For example, "D50" refers
to an entire standard spectral power distribution.

Note that the emissive case above does not involve a reference illuminant since the sample itself provides the light energy.

Again, the integrals are usually replaced by summations for the same reasons as discussed for the emissive case:

$$X = {{1} \over {N}} \sum_i \bar x_i S_i I_i \Delta \lambda$$ $$Y = {{1} \over {N}} \sum_i \bar y_i S_i I_i \Delta \lambda$$ $$Z = {{1} \over {N}} \sum_i \bar z_i S_i I_i \Delta \lambda$$ $$N = \sum_i \bar y_i I_i \Delta \lambda$$