9
$\begingroup$

(I'm hoping this question is not hopelessly naive...)

My understanding is that Plot's strategy is to generate a list of abscissas, evaluate the argument expression at those abscissas, and from that point on behave pretty much like ListPlot with the list of abscissa-ordinate pairs as input. (More or less.)

Assuming that the sketch above is not fantastically off-base, what algorithm does Plot use to compute the list of abscissas to use?

$\endgroup$
  • 3
    $\begingroup$ ListLinePlot @@@ (Reap@Plot[Sow[x] x, {x, 0, 1}] $\endgroup$ – Dr. belisarius Jan 22 '13 at 19:11
  • $\begingroup$ @belisarius: interesting trick, thanks, but I confess that I don't feel much more capable of guessing Mathematica's algorithm for generating the mesh than I was before... $\endgroup$ – kjo Jan 22 '13 at 19:48
  • 2
    $\begingroup$ Mma algorithms are usually proprietary (except when they disclose them explicitly) and usually not easy to guess from the behavior $\endgroup$ – Dr. belisarius Jan 22 '13 at 19:51
  • 1
    $\begingroup$ a more interesting varient on belisarius suggestion: ListPlot[Reap[Plot[Sow[x]; 1/(x - .5)^2, {x, 0, 1}]][[2, 1]]]. You can see that there is an adaptive curvitue based algorithm. Oddly it seems to never eval at the lower bound.. $\endgroup$ – george2079 Jan 22 '13 at 22:11
  • 1
    $\begingroup$ Is your question answered by the posts linked here?: mathematica.stackexchange.com/a/11142/121 $\endgroup$ – Mr.Wizard Jan 22 '13 at 22:34
9
$\begingroup$

This doesn't really answer the question, but might help you with your investigations...

By setting the system option "VisualizationOptions" -> {"Verbose" -> True} you get all sorts of information printed about the plotting process. The code below intersperses that output with the actual sampled points (shown as ListPlots), showing the initial sampling and multiple refinement steps. There are numerical parameters associated with the refinement steps - they mean nothing to me but perhaps an expert could infer something about the algorithm.

plotinfo[func_, {from_, to_}] := Module[{a, f, g},
  SetSystemOptions["VisualizationOptions" -> {"Verbose" -> True}];
  a = SplitBy[Reap[Block[{Print = Sow[f[##]] &},
       Plot[func[x], {x, from, to}, EvaluationMonitor :>
         Sow[g[{x, func[x]}]]]]][[2, 1]], Head];
  SetSystemOptions["VisualizationOptions" -> {"Verbose" -> False}];
  a[[2 ;; -1 ;; 2]] = f@ListPlot[#, Filling -> Axis] & /@ a[[2 ;; -1 ;; 2, All, 1]];
  a /. f -> Print;]

The arguments are a function to plot and a range, e.g.

plotinfo[Tan, {0, 10}]

This is just a snippet of the full output:

enter image description here

$\endgroup$
  • $\begingroup$ Thanks! This was a beautiful answer. $\endgroup$ – kjo Aug 23 '13 at 11:48

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.