[Date Index]
[Thread Index]
[Author Index]
How to use Monitor inside Manipulate?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg116513] How to use Monitor inside Manipulate?
*From*: Sourav Mukherjee <sourav.scube at gmail.com>
*Date*: Thu, 17 Feb 2011 05:21:22 -0500 (EST)
Hi,
?EvaluationMonitor
EvaluationMonitor is an option for various numerical computation and
*plotting functions* that gives an expression to evaluate whenever
functions derived from the input are evaluated numerically.
After reading this example ( http://wolfram.com/xid/05fmrzwc0a-8v3nl )
in the documentation, I decided to try out the same for DensityPlot. I
want to count the number of internal computations performed when
DensityPlot is used. I also want to display a progress bar as long as
the DensityPlot does not appear in the output cell.
c = 0;
Monitor[Rasterize@
DensityPlot[Sin[x] Sin[y], {x, -3, 3}, {y, -3, 3},
ColorFunction -> Hue, MaxRecursion -> 0, PlotPoints -> 250,
PlotLabel -> c, EvaluationMonitor :> c++],
Row[{ProgressIndicator[c, Indeterminate],
Style[c, Magnification -> 3]}]]
I am dissatisfied with the above code for the following reasons: there
seems to be a time lag between the appearance of the DensityPlot
graphic in the output cell and the stopping of the progress bar. I
wish the progress bar would continue changing as long as the
DensityPlot graphic does not actually appear in the output cell, and
not just when the values of Sin[x]Siny[y] for different x and y are
being computed internally. I understand this does not happen as
ProgressIndicator is dependent only the variable 'c', but how to do
what I intend to do here?
Second problem: I want to determine the number of computations for
different values of MaxRecursion and PlotPoints. To that effect I wrap
my code with Manipulate:
Manipulate[
Block[{c = 0},
Monitor[Rasterize@
DensityPlot[Sin[x] Sin[y], {x, -3, 3}, {y, -3, 3},
ColorFunction -> Hue, MaxRecursion -> maxrecur,
PlotPoints -> plp, PlotLabel -> c, EvaluationMonitor :> c++],
Dynamic@c]], {plp, 2, 500,
1}, {maxrecur, {Automatic, 0, 1, 2, 3, 4, 5}}]
This program temporarily displays a '0' below the Manipulate area
while the internal computations are underway (I've omitted the
ProgressIndicator part for simplicity--let's fix one problem first!).
The problem is that EvaluationMonitor localizes 'c' inside another
Block, and thus the changing values of c are not accessible to the
line Dynamic@c ... am I correct (
http://reference.wolfram.com/mathematica/ref/EvaluationMonitor.html#217061240
)? Use DynamicModule instead of Block and the code still behaves the
same way.
So now I put Block around Manipulate
Block[{c = 0},
Manipulate[
Monitor[Rasterize@
DensityPlot[Sin[x] Sin[y], {x, -3, 3}, {y, -3, 3},
ColorFunction -> Hue, MaxRecursion -> maxrecur,
PlotPoints -> plp, PlotLabel -> c, EvaluationMonitor :> c++],
Dynamic@c], {plp, 2, 500,
1}, {maxrecur, {Automatic, 0, 1, 2, 3, 4, 5}}]]
This program temporarily displays not '0', but 'c'. More bizarre, if
Block is replaced by DynamicModule, the program seems to run into an
infinite loop.
I've tried approaches that don't make use of Monitor. Please see below:
Manipulate[DynamicModule[{c = 0}, Column[{
Dynamic@c,
Rasterize@
DensityPlot[Sin[x] Sin[y], {x, -3, 3}, {y, -3, 3},
ColorFunction -> Hue, MaxRecursion -> maxrecur,
PlotPoints -> plp, PlotLabel -> c,
EvaluationMonitor :> c++]}]], {plp, 2, 500,
1}, {maxrecur, {Automatic, 0, 1, 2, 3, 4, 5}}]
This displays the updated value of 'c' only *after* the DensityPlot
has been rendered. Here again I fail to understand how am I supposed
to prevent the overshadowing of 'c' by the Block which is used by
EvaluationMonitor behind the scenes.
I'll be grateful for any suggestions or solutions...
Regards,
Sourav
Prev by Date:
**Re: 3D surface plots - non deletion of data inside undesirable**
Next by Date:
**Re: Fitting Experimental Data**
Previous by thread:
**Re: 3D surface plots - non deletion of data inside undesirable**
Next by thread:
**ContourPlot3D**
| |