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


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

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

From Alexey Popkov <lehin.p@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject f(x)=x: why Plot continues to add new levels of recursion?
Date 2011-09-06 08:06 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j44kas$96b$1@smc.vnet.net> (permalink)

Show all headers | View raw


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?

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web