3
$\begingroup$

I'm new to Mathematica and will need some help in coding the Mandelbrot set.

I don't want to use MandelbrotSetPlot since I want to understand the interior mechanisms of the set. I'm also not interested in speed but just want to keep it simple.

Where do I start? z=z^2+c is relatively simple but:

  • How do I make clear that the function should be iterated? I tried NestList, NestGraph and NestWhile but nothing seems to work. Is there a way to include n and n+1 instead?
  • How do I make clear that c is a complex number? Can I define c=r+i, for example?

I found this Julia set here(Why is this Mandelbrot set's implementation infeasible: takes a massive amount of time to do?) which makes sense to me:

ArrayPlot[Table[
  NestWhile[#^2 - (0. - 1 I) & , r + i I, Abs[#] < 2.0 &, 1, 10],
  {r, -2, 2, 0.005},
  {i, -2, 2, 0.005}]]

But a Mandelbrot should have a variable c instead, that's right?

Thanks in advance and sorry for the stupid questions.

$\endgroup$
  • $\begingroup$ Just change 0. - 1 I to (r + i I). Mandelbrot is $z_{n+1}\leftarrow z_n^2 + c$ where $c$ is the intial $z_0$ - also switch your {r,...} and {i,...} ranges in the table over to rotate it by 90*. And consider using ParallelTable for better performance. $\endgroup$ – flinty Jun 21 at 14:05
  • 1
    $\begingroup$ How do I make clear that the function should be iterated? ... Is there a way to include n and n+1 instead? You're on the right track using NestWhile and this is the most efficient and expressive approach to this problem. There is no need to refer to n and n+1 and you should continue to experiment with constructs like Nest, FixedPoint, Map, as you learn Mathematica. Also if you have any syntax trouble, these answers are a good place to start mathematica.stackexchange.com/questions/18393/… $\endgroup$ – flinty Jun 21 at 14:41
4
$\begingroup$

Something like

f[c_, maxiter_Integer : 10^4] := 
  Abs[NestWhile[#^2 + c &, 0, Abs[#] < 2 &, 1, maxiter]] < 2

f[0]
(*    True    *)

f[1]
(*    False    *)

f[I]
(*    True    *)

f[I, 10^6]
(*    True    *)

ArrayPlot[
  Table[Boole[f[N[x + I y], 10^3]], {y, -2, 2, 1/50}, {x, -2, 2, 1/50}]]

enter image description here

By playing with the working precision of N you can achieve high-precision calculations.

ArrayPlot[
  Table[Boole[f[N[x + I y], 200]],
        {y, 0.14, 0.15, 10^-5},
        {x, -0.75, -0.74, 10^-5}]]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.