Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4789 > unrolled thread

f(x)=x: why Plot continues to add new levels of recursion?

Started byAlexey Popkov <lehin.p@gmail.com>
First post2011-09-06 08:06 +0000
Last post2011-09-06 08:06 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  f(x)=x: why Plot continues to add new levels of recursion? Alexey Popkov <lehin.p@gmail.com> - 2011-09-06 08:06 +0000

#4789 — f(x)=x: why Plot continues to add new levels of recursion?

FromAlexey Popkov <lehin.p@gmail.com>
Date2011-09-06 08:06 +0000
Subjectf(x)=x: why Plot continues to add new levels of recursion?
Message-ID<j44kas$96b$1@smc.vnet.net>
Hello,

Please consider the following example (plotting function f(x)=x):

NumberOfEvals[r_] :=
 Length[Reap[
    Plot[x, {x, -Pi, Pi}, MaxRecursion -> r,
     EvaluationMonitor :> Sow[x]]][[2, 1]]]
data = Table[{r, NumberOfEvals[r]}, {r, 0, 15}];
f = Fit[data, {1, r, r^2}, r] // Factor
Show[ListPlot[data, Axes -> False, Frame -> True,
  FrameLabel -> {"MaxRecursion", "Number  of evaluation  points "},
  PlotLabel -> StandardForm@"Plot[x,{x,-\[Pi],\[Pi]}]"],
 Plot[f, {r, 0, 15}, PlotRange -> All]]

=> (100 + 3 r + r^2)/2
=> <Graphics>

One can see that the number of evaluation points for function f(x)=x
grows as (100 + 3 r + r^2)/2 where 'r' is the value of option
MaxRecursion.

It is clear that in the case of f(x)=x it is not necessary to go
deeper in recursion because the bend angle between successive segments
of the
approximating polyline in this case is always approximately equal to
zero. In Mathematica 5.2 Plot does no recursion in this case:

In[1]:=
l[div_]:=Length@Reap[Plot[Sow[x];x,{x,-Pi,
        Pi},PlotDivision\[Rule]div,DisplayFunction\[Rule](#&)]][[2,1]]
Table[l[div],{div,1,10}]

Out[2]=
{25,25,25,25,25,25,25,25,25,25}

Why in Mathematica 7 Plot makes these superfluous evaluations? Is it
possible to force it to behave like Plot in version 5.2?

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web