I'm trying to compute the following integral:
$$\int_{380 \, \mathrm{nm}}^{700 \, \mathrm{nm}}\mathbf{RGB}(\mathrm{Hue}(\lambda))\frac{\mathrm{d}\lambda}{\lambda^4}$$
where $\mathbf{RBG}$ takes in a Hue
and outputs a vector like {0., 1., 1.}
.
This is how I've tried to implement this:
lambdaToHue[wavelength_] := Hue[-.8/(700 - 380) wavelength + 1.75]
which takes wavelengths into Hues, (evaluating it on 380 gives purple, on 700 gives red). Then
hueToRBG[hue_] := Table[ColorConvert[hue, "RGB"][[i]], {i, 1, 3}]
takes Hues into vectors, so e.g. evaluating it on lambdaToHue[380]
gives {0.8, 0., 1.}
. So I can put in values for wavelength and get numbers from hueToRBG[wavelengthToHue[wavelengths]]
. So I should be able to compute an integral, like
NIntegrate[hueToRBG[lambdaToHue[l]]/l^4,{l,380,700}]
but in reality Mathematica complains:
"The integrand Hue[1.75 -0.0025\ l] has evaluated to \
non-numerical values for all sampling points in the region with \
boundaries {{380,700}}"
How can I get mathematica to actually just compute the integral of this function which takes numbers into lists of numbers? It works fine, e.g., for
NIntegrate[{x,Sin[x],Sqrt[x]}/x^4,{x,2,4}].
Much thanks!
ColorData["VisibleSpectrum"]
instead ofHue
. Should be more related to the actual physical colors... $\endgroup$Total /@ Transpose[(Table[ ColorData["VisibleSpectrum"][\[Lambda]] /. RGBColor[a___] -> {a}, {\[Lambda], 380, 750, 0.1}]* Table[0.1/\[Lambda]^2.5, {\[Lambda], 380, 750, 0.1}])]
$\endgroup$Sum [.1 1/\[Lambda]^4 Apply[List, ColorData["VisibleSpectrum"][\[Lambda]]], {\[Lambda], 380, 750, 0.1}]
evaluates to{1.56038*10^-9, 1.46384*10^-9, 2.74953*10^-9}
black $\endgroup$f[\[Lambda]_?NumericQ, k_] := (ColorData["VisibleSpectrum"][\[Lambda]])[[k]];NIntegrate[f[\[Lambda], #]/\[Lambda]^4, {\[Lambda], 380, 700}] & /@ Range[3]
? $\endgroup$