MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How does Plot work?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115165] Re: How does Plot work?
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Mon, 3 Jan 2011 03:56:18 -0500 (EST)

Not that this  answers the question, but it looks to me like this behavior
has to
do with the exact periodicity of Sin and the plot limits being multiples of
2 Pi. Somehow,
for PlotPoints being exactly 50, this breaks the algorithm (I think this is
either a bug, or
at least the algorithm used is unstable in some cases like this one). You
can see that
changing any of the above would result in a normal plot:

Show[Plot[Sin[x], {x, -42 Pi + 0.01, 42 Pi + 0.01},
  PlotStyle -> LightGray, MaxRecursion -> 5, Mesh -> All,
  MeshStyle -> Thick, PlotStyle -> Red, PlotPoints -> 50],
 PlotRange -> {{-110, -90}, {-1, 1}}]

Show[Plot[Sin[x], {x, -42 Pi, 42 Pi}, PlotStyle -> LightGray,
  MaxRecursion -> 5, Mesh -> All, MeshStyle -> Thick,
  PlotStyle -> Red, PlotPoints -> 49],
 PlotRange -> {{-110, -90}, {-1, 1}}]

Show[Plot[Sin[x*1.01], {x, -42 Pi, 42 Pi}, PlotStyle -> LightGray,
  MaxRecursion -> 5, Mesh -> All, MeshStyle -> Thick,
  PlotStyle -> Red, PlotPoints -> 50],
 PlotRange -> {{-110, -90}, {-1, 1}}]

You can further analyze the plot points, first collecting them through
Reap-Sow:

res = Reap[
   Show[Plot[Sin[Sow[x]], {x, -42 Pi, 42 Pi}, PlotStyle -> LightGray,
     MaxRecursion -> 5, Mesh -> All, MeshStyle -> Thick,
     PlotStyle -> Red, PlotPoints -> 50],
    PlotRange -> {{-110, -90}, {-1, 1}}]];

and then plotting the differences to see if there are outliers which would
signal
missed points (indeed there are)

ListPlot[Differences[res[[2, 1]][[3 ;;]]],  PlotRange -> {All, {-20, 20}}]

What you can see from this is that the point located within the gap gets
systematically
missed during the sampling iterations, except the very first one. This looks
like an interplay
of subdivision into equal regions and periodicity of Sin. Without knowing
the exact algorithm
used, it is hard to say what exactly is causing this. It also seems that the
conditions must
be pretty fine tuned to cause this effect.

Regards,
Leonid


On Sun, Jan 2, 2011 at 12:56 PM, Yaroslav Bulatov <yaroslavvb at gmail.com>wrote:

> I've read the chapter in Stan Wagon's book on adaptive plotting, and I
> still have unanswered questions
>
> 1. How does Plot choose initial 50 points?
> If they were chosen to split PlotRange into 49 equal intervals, then
> the following Plot would coincide with x-axis, but it doesn't
> kk = 49;
> plot1 = Plot[Sin[2 Pi x], {x, 0, kk}, Mesh -> All, PlotStyle -> Gray,
>  MeshStyle -> Directive[Black, Thick], MaxRecursion -> 0,
>  PlotPoints -> kk + 1, PlotRangePadding -> 0,
>  PlotRange -> {{0, kk}, {-1, 1}}, Axes -> {True, True}]
>
> 2. How does adaptive plotting choose to subdivide the regions?
> The explanation in the book is that it subdivides if the angle between
> two segments is more than 5 degrees, but you can see in this sequence
> below that a segment doesn't get subdivided, even it should be
> according to the "5 degree rule". This recently caused a user to
> wonder why there was a "hole" in his plot (http://stackoverflow.com/
> questions/4572183/strange-sinx-graph-in-mathematica<http://stackoverflow.com/%0Aquestions/4572183/strange-sinx-graph-in-mathematica>
> )
>
> plot1 = Plot[Sin[x], {x, -42 Pi, 42 Pi}, PlotPoints -> 100,
>   PlotStyle -> LightGray];
> Table[plot2 =
>   Plot[Sin[x], {x, -42 Pi, 42 Pi}, Mesh -> All, MeshStyle -> Thick,
>    PlotStyle -> Red, MaxRecursion -> k];
>  Show[plot1, plot2, PlotRange -> {{-110, -90}, {-1, 1}},
>   PlotLabel -> ("MaxRecursion " <> ToString[k])], {k, 0,
>   5}] // GraphicsColumn
>
>


  • Prev by Date: Re: AVI with sound
  • Next by Date: Re: Mathematica daily WTF
  • Previous by thread: How does Plot work?
  • Next by thread: Re: How does Plot work?