Observe the following code:
nd[y_, a_, b_, n_] := (Binomial[b - a + 1, y]*Sum[((-1)^i)*Binomial[y, i]*((y - i)/(b - a + 1))^n, {i, 0, y}]);
mycolorfun = Function[Blend[{Black, Purple, Blue, Green, Yellow, Orange, Red, White}, Rescale[#, {0, 1}]]]
Manipulate[
ArrayPlot[Table[nd[y, 1, K, n], {K, 1, 25}, {n, 1, 25}],
ColorFunction -> mycolorfun, DataReversed -> True, Frame -> True,
FrameTicks -> Automatic,
FrameLabel -> {Rotate["K", -90 Degree], "N"}], {y, 1, 15, 1}]
Notice how when the slider is moved up to y=15, there is a white square that appears at N = 25 and K = 21:
My goal is for the color function to map the individual value of the output of my function to a color as dependent on its closeness to 0 or 1 (since my function is a probability density function, this makes sense).
However, look what happens when you check the actual value of the function for N = 25 and b=K=21:
nd[15, 1, 21, 25.0]
(out) 0.268495
I get 26%! 26% should be mapping to a color somewhere around Purple/Blue, but it's getting mapped all the way up to the color white! White is what's supposed to be mapped to when the output of my function is really close to 1! Clearly something is amiss here, and I cannot figure out what it is. Can somebody please explain what is going on and what I need to do to get the desired color output?
mycolorfun
. $\endgroup$N
as a variable name as that is a function in Mathematica. You're getting "white" because that is where the largest value in your table is. Someone else will know what the function for having a constant scaling from 0 to 1 will be. $\endgroup$