When plotting a slow function, it would be nice to know how much of the work has already be done. However due to the refinement algorithm, simply monitoring the integration variable doesn't give an useful estimate unless MaxRecursion
is set to 0 (and it's clear that the best I can hope for is an estimate). For example, consider
Monitor[Plot[Pause[0.01];Sin[x],{x,0,100}],x]
This goes through the interval dozens of times, although the number of points in each iteration goes down.
Therefore my question: Is there any way to get a reasonable estimate of how much of a plot is already done?
Answer
If you're willing to sacrifice automaticity on MaxRecursions
, you could do this
SetAttributes[celtschkPlot, HoldAll];
celtschkPlot[fun_, {v_, r1__}, mr_: 6, op : OptionsPattern[]] :=
Module[{i = 0, xant},
Monitor[
Plot[fun, {v, r1},
MaxRecursion -> mr,
EvaluationMonitor :> (If[v < xant, ++i]; xant = v), op],
ProgressIndicator[i, {0, 2^mr}]]]
So, try
celtschkPlot[Pause[0.001]; Sin[2 Pi t], {t, 0, 10}]
and play with the functions. The last argument specifies the max recursion with defaults to a hard 6
celtschkPlot[Pause[0.001]; Sin[2 Pi t], {t, 0, 10}, 6]
This would be an upper bound. You could get the happy surprise that the plot finishes early
Comments
Post a Comment