Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Evaluate the CIE color matching functions for a given wavelength
| ResourceFunction["CIEColorMatchingFunctionValues"][λ] evaluates the CIE color matching functions for a given wavelength λ. | 
Evaluate the color matching functions for a given wavelength:
| In[1]:= | ![ResourceFunction["CIEColorMatchingFunctionValues"][589]](https://www.wolframcloud.com/obj/resourcesystem/images/a8b/a8b21d3b-f4ec-4ecf-a638-5c3a19221f81/78f6bccb0bd4688e.png)  | 
| Out[1]= |   | 
Get the corresponding color:
| In[2]:= | ![XYZColor[%]](https://www.wolframcloud.com/obj/resourcesystem/images/a8b/a8b21d3b-f4ec-4ecf-a638-5c3a19221f81/69a6e23f2fd574df.png)  | 
| Out[2]= |   | 
Plot the color matching functions:
| In[3]:= | ![Plot[ResourceFunction[
  "CIEColorMatchingFunctionValues"][\[Lambda]], {\[Lambda], 385, 745}]](https://www.wolframcloud.com/obj/resourcesystem/images/a8b/a8b21d3b-f4ec-4ecf-a638-5c3a19221f81/0eeb2f5e1ed2158d.png)  | 
| Out[3]= |   | 
Use any Quantity with length units:
| In[4]:= | ![ResourceFunction["CIEColorMatchingFunctionValues"][
 Quantity[5500, "Angstroms"]]](https://www.wolframcloud.com/obj/resourcesystem/images/a8b/a8b21d3b-f4ec-4ecf-a638-5c3a19221f81/3d68a3ae62340a27.png)  | 
| Out[4]= |   | 
Get the corresponding color:
| In[5]:= | ![XYZColor[%]](https://www.wolframcloud.com/obj/resourcesystem/images/a8b/a8b21d3b-f4ec-4ecf-a638-5c3a19221f81/34fa595c4d4e9a3b.png)  | 
| Out[5]= |   | 
CIEColorMatchingFunctionValues threads over lists:
| In[6]:= | ![ResourceFunction["CIEColorMatchingFunctionValues"][{400, 500, 600}]](https://www.wolframcloud.com/obj/resourcesystem/images/a8b/a8b21d3b-f4ec-4ecf-a638-5c3a19221f81/164f981cdf4df700.png)  | 
| Out[6]= |   | 
Compare the color obtained from CIEColorMatchingFunctionValues with the color obtained from ColorData["VisibleSpectrum"]. There are slight differences, for example a narrower red band:
| In[7]:= | ![DensityPlot[\[Lambda], {\[Lambda], 385, 745}, {y, 0, 50}, ColorFunction -> Function[t, XYZColor[ResourceFunction["CIEColorMatchingFunctionValues"][t]]], ColorFunctionScaling -> False, AspectRatio -> Automatic, FrameTicks -> {Automatic, None}]](https://www.wolframcloud.com/obj/resourcesystem/images/a8b/a8b21d3b-f4ec-4ecf-a638-5c3a19221f81/7edbab02634435d5.png)  | 
| Out[7]= |   | 
| In[8]:= | ![DensityPlot[\[Lambda], {\[Lambda], 385, 745}, {y, 0, 50}, ColorFunction -> Function[t, ColorData["VisibleSpectrum", t]], ColorFunctionScaling -> False, AspectRatio -> Automatic, FrameTicks -> {Automatic, None}]](https://www.wolframcloud.com/obj/resourcesystem/images/a8b/a8b21d3b-f4ec-4ecf-a638-5c3a19221f81/733f7ac733a13b0f.png)  | 
| Out[8]= |   | 
CIEColorMatchingFunctionValues is left unevaluated if the argument is a quantity with incompatible units:
| In[9]:= | ![ResourceFunction["CIEColorMatchingFunctionValues"][
 Quantity[7.*^14, "Hertz"]]](https://www.wolframcloud.com/obj/resourcesystem/images/a8b/a8b21d3b-f4ec-4ecf-a638-5c3a19221f81/2424d74dad1ccbb5.png)  | 
| Out[9]= |   | 
Convert frequency to wavelength before giving it to CIEColorMatchingFunctionValues:
| In[10]:= | ![ResourceFunction["CIEColorMatchingFunctionValues"][
 Quantity["SpeedOfLight"]/Quantity[7.*^14, "Hertz"]]](https://www.wolframcloud.com/obj/resourcesystem/images/a8b/a8b21d3b-f4ec-4ecf-a638-5c3a19221f81/34cda6d80d479df2.png)  | 
| Out[10]= |   | 
This work is licensed under a Creative Commons Attribution 4.0 International License