# Abs failed on evaluating nested complex expressions

I am a new Mathematica user and try to use its power to do some cool stuff. I want to draw a fractal graph with DensityPlotthe length of outcome of z->z^2+c, where z and c are both complex numbers, and z is initially 0. I try to combine my knowledge of nested function and delayed-value to accomplish this, here is my code.

p[x, y] = x + y*I
f[z_] := z^2 + p[x, y]
DensityPlot[
Abs[Nest[f[p[x, y]], p[x, y], 10]], {x, -2, 2}, {y, -2, 2}]


Then, nothing appears on the graph. I isolate the nested function, and it works well.

Nest[f[p[x, y]], p[x, y], 10]

(x + (x + I y)^2 + I y)[(x + (x + I y)^2 + I y)[(x + (x + I y)^2 +I y)[(x + (x + I y)^2 + I y)[(x + (x + I y)^2 + I y)[(x + (x + I y)^2 + I y)[(x + (x + I y)^2 + I y)[(x + (x + I y)^2 + I y)[(x + (x + I y)^2 + I y)[(x + (x + I y)^2 + I y)[x + I y]]]]]]]]]]


However, it turns out that Abs does not give numerical values of these complex numbers, even when x,y are given values.

Table[N[Abs[Nest[f[p[1, 1]], p[1, 1], 2]]], {x, 1}, {y, 1}]


{{Abs[(1. + 3. I)[(1. + 3. I)[1. + 1. I]]]}}

Your Nest statement makes no sense. Anything immediately preceding a set of square brackets must be a function and what is inside of the square brackets must be a valid argument to that function.

Clear[p, f, x, y]


You should use patterns on the LHS of the definition of p

p[x_, y_] = x + y*I;

f[z_] := z^2 + p[x, y];


I am guessing that you intend f to be the function used in the Nest

Abs[Nest[f, p[1, 1], 10]] /. {x -> 1., y -> 1.}

(*  2.02639*10^254  *)


EDIT 2: Added ColorFunctionScaling

DensityPlot[
Abs[Nest[f, p[x, y], 10]],
{x, -2.5, 1.5}, {y, -2, 2},
PlotPoints -> 75,
ColorFunctionScaling -> False] EDIT: The ContourPlot of the Log of the function

ContourPlot[
Log@Abs[Nest[f, p[x, y], 10]],
{x, -2.5, 1.5}, {y, -2, 2},
PlotPoints -> 75] • This really does help me!!! Thanks! So Nest can only pass to a single argument, right? – Dumb_Mouse Nov 8 '16 at 10:12
• @Dumb_Mouse - the "single" (second) argument to Nest can be a list provided that the function (first argument) accepts a list as its argument and returns a list as its output. – Bob Hanlon Nov 8 '16 at 15:12

You left out the underscores for the argument of the function p

p[x_, y_] = x + y*I


Nest[f[p[x, y]], p[x, y], 10] has faulty arguments.

Look at f[p[x, y]] results in f goes to require 2 arguments ( x + yI)^2+ (x + yI). 2 arguments because now f need x and y

Nesting to p[x,y] will not work because p delivers only satisfy one of the arguments. This is why you get the square bracket in the Nest...

• This explains a lot, thanks. – Dumb_Mouse Nov 8 '16 at 10:13