Message Boards Message Boards

RegionPlot Overloaded?

GROUPS:

I'm working with a variation of the Mandelbrot set which works for the initial iterations but not for the higher ones:

mandelPlotOriginal[iterations_, plotpts_] := 
 RegionPlot[
  Abs[Nest[(#^2 - y - x I) &, -y - x I, iterations]] < 2, {x, -1.3, 
   1.3}, {y, -1, 2}, AspectRatio -> Automatic, PlotPoints -> plotpts, 
  BoundaryStyle -> None, ImageSize -> 200]

mandelPlotVariation[iterations_, c_, plotpts_] := 
 RegionPlot[
  Abs[Expand[
      Nest[(#^2 - y - x q) &, -y - x q, iterations]] /. {q^p_ :> 
       c I^p, q -> c I}] < 2, {x, -1.3, 1.3}, {y, -1, 2}, 
  AspectRatio -> Automatic, PlotPoints -> plotpts, 
  BoundaryStyle -> None, ImageSize -> 200]

For c=1, the variation is the same as the original Mandelbrot set. Works fine for 1st through 6th iteration. Here's the 6th iteration:

{mandelPlotVariation[6, 1, 50], mandelPlotOriginal[6, 50]}

enter image description here

But by the 7th and 8th, RegionPlot starts to crop out parts of the plot:

{mandelPlotVariation[8, 1, 50], mandelPlotOriginal[8, 50]}

enter image description here

Increasing PlotPoints does not help. Any ideas or workarounds? Thank you.

POSTED BY: Bryan Lettner
Answer
14 days ago

This design leads to an error:

Nest[(#^2 - y - x q) &, -y - x q, iterations]] /. {q^p_ :> 
           c I^p, q -> c I}]

Is it possible to simplify to

 Nest[(#^2 - y - x c*I) &, -y - x c*I, iterations]] 

?

POSTED BY: Alexander Trounev
Answer
14 days ago

Thanks Alexander. I'm not sure what error you're referring to, but I do notice an error when attempting to count the number of terms, for the 6th iteration:

enter image description here

Obviously there must be at least 3162 terms, since that many are suppressed in the output. But Length says only 2144 terms. I think since the long output is suppressed or handled differently for iteration 6 and later, the substitution {q^p_ :> c I^p, q -> c I} cannot be properly made.
Any ideas why Length doesn't count the number of terms properly? I tried exporting to a data file and importing, but Length still shows 2144. Either that, or the ... 3162 ... in the output is inaccurate.

POSTED BY: Bryan Lettner
Answer
14 days ago

You're right, Expand[] does not work at all, because it uses Short[] as Automatic option. Without Expand[] code works quickly and correctly

mandelPlotOriginal[iterations_, plotpts_] := 
 RegionPlot[
  Abs[Nest[(#^2 - y - x I) &, -y - x I, iterations]] < 2, {x, -1.3, 
   1.3}, {y, -1, 2}, AspectRatio -> Automatic, PlotPoints -> plotpts, 
  BoundaryStyle -> None, ImageSize -> 200]

mandelPlotVariation[iterations_, c_, plotpts_] := 
 RegionPlot[
  Abs[Nest[(#^2 - y - x q) &, -y - x q, iterations] /. {q^p_ :> c I^p,
       q -> c I}] < 2, {x, -1.3, 1.3}, {y, -1, 2}, 
  AspectRatio -> Automatic, PlotPoints -> plotpts, 
  BoundaryStyle -> None, ImageSize -> 200]
{mandelPlotVariation[8, 1, 50], mandelPlotOriginal[8, 50]}

m8

POSTED BY: Alexander Trounev
Answer
13 days ago

Thanks Alexander. Did not know that Expand uses Short[]. Is there a way to override that? Unfortunately, without Expand, your code above only works for c=1. For c=-4, for example, we see a big difference:

mandelPlotVariation[iterations_, c_, plotpts_] := 
 RegionPlot[
  Abs[Nest[(#^2 - y - x q) &, -y - x q, iterations] /. {q^p_ :> c I^p,
       q -> c I}] < 2, {x, -1.3, 1.3}, {y, -1, 2}, 
  AspectRatio -> Automatic, PlotPoints -> plotpts, 
  BoundaryStyle -> None, ImageSize -> 200]

mandelPlotVariationWithExpand[iterations_, c_, plotpts_] := 
 RegionPlot[
  Abs[Expand[
      Nest[(#^2 - y - x q) &, -y - x q, iterations]] /. {q^p_ :> 
       c I^p, q -> c I}] < 2, {x, -1.3, 1.3}, {y, -1, 2}, 
  AspectRatio -> Automatic, PlotPoints -> plotpts, 
  BoundaryStyle -> None, ImageSize -> 200]
{mandelPlotVariation[5, -4, 50],  mandelPlotVariationWithExpand[5, -4, 50]}

enter image description here

So the best option I think is to somehow tell Expand not to use Short, or to use another command to show the full output. I'll post when I figure it out. Thanks again for the help!

POSTED BY: Bryan Lettner
Answer
11 days ago

Expand does not use Short. The formatter for the user interface uses Short. Also I see no reason to believe the length of the expanded form is incorrect.

For what it is worth, the length of the expanded expressions roughly quadruples at each iteration.

ee = NestList[Expand[(#^2 - y - x q)] &, -y - x q, 7];
Map[Length, ee]

(* Out[31]= {2, 5, 14, 44, 152, 560, 2144, 8384} *)
POSTED BY: Daniel Lichtblau
Answer
10 days ago

Function Expand[] does not work at all even for $iterations=5$. So we have to compare two functions that do not contain Expand[] (see small changes {x, -1.3/Abs[c], 1.3/Abs[c]}, AspectRatio -> 1/2)

mandelPlotVariation1[iterations_, c_, plotpts_] := 
 RegionPlot[
  Abs[Nest[(#^2 - y - x*I*c) &, -y - x*I*c, iterations]] < 
   2, {x, -1.3/Abs[c], 1.3/Abs[c]}, {y, -1, 2}, PlotPoints -> plotpts,
   BoundaryStyle -> None, ImageSize -> 200, AspectRatio -> 1/2]
mandelPlotVariation[iterations_, c_, plotpts_] := 
 RegionPlot[
  Abs[Nest[(#^2 - y - x q) &, -y - x q, iterations] /. {q^p_ :> c I^p,
       q -> c I}] < 2, {x, -1.3/Abs[c], 1.3/Abs[c]}, {y, -1, 2}, 
  PlotPoints -> plotpts, BoundaryStyle -> None, ImageSize -> 200, 
  AspectRatio -> 1/2]
{mandelPlotVariation[8, -4, 50], mandelPlotVariation1[8, -4, 50]}

M1

POSTED BY: Alexander Trounev
Answer
11 days ago

Thank you Daniel that explained what is written in tutorials: When generated outputs in the notebook interface are exceedingly large, the Wolfram Language automatically applies Short to the output. This user interface enhancement prevents the Wolfram Language from spending a lot of time generating and formatting the printed output for an evaluation which probably generated output you did not expect.

When we run Evaluate Notebook, we are waiting for a long time when the Expand[] can complete the work and even without getting the right result. On the other hand without Expand[], we can quickly and easily get the result. All this we are discussing in this topic.

In[4]:= Table[(2^k + 3)*2^(k - 1), {k, 0, 7}]

Out[4]= {2, 5, 14, 44, 152, 560, 2144, 8384}
POSTED BY: Alexander Trounev
Answer
10 days ago

Group Abstract Group Abstract