       [Q] problem with ColorFunction in ListDensityPlot

• Subject: [mg3114] [Q] problem with ColorFunction in ListDensityPlot
• From: glgesm at engr.psu.edu (Gary L. Gray)
• Date: 2 Feb 1996 04:28:26 -0600
• Approved: usenet@wri.com
• Distribution: local
• Newsgroups: wri.mathgroup
• Organization: Penn State University - Engineering Science & Mechanics
• Sender: daemon at wri.com

```I am putting together a demo for a class in which I am trying to use
Newton-Raphson to iterate the equation z^3 - 1 = 0. I then want to plot
which points in the complex plane go to which root by coloring the initial
starts points three different colors (results in a fractal). Here is what
I am doing:

I first define the function I will be iterating:

f[z_] := N[z - (z^3 - 1)/(3 z^2)];

Then I create the an array of points in which each element of the array
corresponds to the root to which the iteration converges for a given
starting value:

p = Table[ FixedPoint[ f, x + I y,
SameTest -> (Abs[#1 - #2] < 10.^-4 &)],
{x, -2, 2, 0.01}, {y, -2, 2, 0.01}];

Then I label the points 1, 2, or 3 depending on which root the starting
value converges to:

points = Table[ Which[Im[p[[i,j]]] < -0.8, 1,
Im[p[[i,j]]] > 0.8, 2,
True, 3],
{i, Length[p]}, {j, Length[p]} ];

Now, I get a grayscale density plot by using the following command:

ListDensityPlot[points, Mesh -> False,
MeshRange -> {{-2, 2}, {-2, 2}}]

The question is, how do I color it say Red, Blue, and Green? Why doesn't
the following command work?

ListDensityPlot[points, Mesh -> False,
ColorFunction ->
( Which[ # == 1, RGBColor[0,0,1],
# == 2, RGBColor[1,0,0],
True, RGBColor[0,1,0] ]& )
]

Thank you,

/---------------------------------------------------------\
| Gary L. Gray            Engineering Science & Mechanics |
| Assistant Professor               Penn State University |
| mailto:glgesm at engr.psu.edu               (814) 863-1778 |
| http://www.esm.psu.edu/HTMLs/Faculty/GGray.html         |
\=========================================================/

```

• Prev by Date: [Q] problem with ColorFunction in ListDensityPlot
• Next by Date: Re: Line and Surface Integrals
• Previous by thread: [Q] problem with ColorFunction in ListDensityPlot
• Next by thread: Not a valid limit in NIntegrate ???