Monitor
Details
- In Monitor[expr,mon], mon can access dynamically scoped variables that appear in expr even though mon is outside the scoping construct. For example, Monitor[Table[e,{x,…}],x] generates a monitor cell that shows the continually updated current value of x during the evaluation of the Table. »
- Monitor prints a cell that is automatically deleted after the evaluation of expr is complete.
- Any expression, including graphics and controls, can be given for mon. »
- Monitor[expr,mon,delay] will delay the indicated number of seconds before generating the monitor cell. If the evaluation of expr is complete before then, no monitor is displayed. »
- Monitor[expr] creates a monitoring interface based on Head[expr]. If the head is not supported, no monitoring interface is created. »
- Supported heads for automatic monitoring include:
-
Do, Table, Array iteration functions Map, MapIndexed, KeyValueMap,Scan, … mapping functions Fold, FoldList, FoldPair, … folding functions Nest, NestList, … nesting functions - Monitor[expr,Automatic,delay] is similar to Monitor[expr] but delays the automatic monitor by the specified number of seconds. »
Examples
open all close allBasic Examples (4)
Monitor the value of n while the computation is running:
Monitor[Table[Length[FactorInteger[2 ^ n - 1]], {n, 50, 500, 50}], n]Display a progress indicator while the computation is running:
Monitor[Table[Length[FactorInteger[2 ^ n - 1]], {n, 50, 500, 50}], ProgressIndicator[n, {50, 500}]]Create an automatic interface that monitors the number of computations performed:
Monitor[Table[Length[FactorInteger[2 ^ n - 1]], {n, 50, 500, 50}]]Monitor a fast process by using Pause to slow down:
Monitor[i = 0;While[i < 100, Pause[0.1];i++];i, i]Scope (5)
Automatically monitor iteration-based functions such as Table and Do:
Monitor[Table[Pause[.1];.1x y, {x, 10}, {y, 0.1, 1, 0.18}]]Delay the appearance of the monitor by two seconds:
i = 0;
Monitor[Do[Pause[0.1];i += .1x y, {x, 10}, {y, 0.1, 1, 0.18}], Automatic, 2]
iAutomatically monitor Map family functions such as Map, MapIndexed, Apply, Scan, MapApply, MapAll:
Monitor[MapIndexed[(Pause[.1First[#2]];f[##])&, RandomReal[1, 10]]]Monitor a Map at level 2:
mat = Table[.1x y, {x, 10}, {y, 0.2, 1, 0.4}];
Monitor[Map[(Pause[#1];#1 ^ 2)&, mat, {2}]]The variants AssociationMap, KeyMap and KeyValueMap are also supported:
Monitor[AssociationMap[(Pause[#];#^2)&, Range[4]]]Automatically monitor MapThread:
Monitor[MapThread[(Pause[.5];f[##1])&, {Range[10], Range[11, 20]}]]Create a list of terms in a series, monitoring the index, term and partial sum:
Monitor[s = 0;Table[Block[{val = (1/n^2)}, s += val;Pause[.1];val], {n, 1, 50}], {n, val, s}]Use a Graphics expression to monitor randomly generated points:
IconizedObject[«Iniialize variables»]
SeedRandom[state];
Monitor[For[{i = 0, pts = {{0, 0}}}, i < numPoints, i++, addPoint[pts]],
Graphics[{Thick, Arrow[Line[pts, VertexColors -> colors]]}, PlotRange -> maxDistance, Frame -> True]];Short[pts]Applications (6)
Monitor NIntegrate, with steps along the
axis and evaluation points on the
axis:
values = {};
Monitor[NIntegrate[Sqrt[x(1 - x)], {x, 0, 1}, EvaluationMonitor :> (Pause[0.025];AppendTo[values, x];)], Quiet@ListPlot[values]]Monitor NDSolve using an extrapolation method:
values1 = {};values2 = {};Monitor[NDSolve[{x''[t] + Sin[x[t]] == 0, x[0] == 1, x'[0] == 0}, x, {t, 0, 2π}, EvaluationMonitor :> (AppendTo[values1, {t, x[t]}];AppendTo[values2, {t, x'[t]}];Pause[0.05];), Method -> "Extrapolation"],
Quiet@ListPlot[{values1, values2}]]Monitor the actual steps taken by NDSolve solving the sine-Gordon PDE with a StepMonitor:
Monitor[NDSolve[{Subscript[∂, t, t]u[t, x] == Subscript[∂, x, x]u[t, x] + Sin[u[t, x]] , u[0, x] == E^-x^2, u^(1, 0)[0, x] == 0, u[t, -10] == u[t, 10]}, u, {t, 0, 10}, {x, -10, 10}, StepMonitor :> (sol = u[t, x]; time = t)], Plot[sol, {x, -10, 10}, PlotRange -> {0, 8}, PlotLabel -> time]]Monitor every attempted step taken by NDSolve time integrating of a wave equation with an EvaluationMonitor:
Monitor[NDSolveValue[{D[u[t, x, y], {t, 2}] == Laplacian[u[t, x, y], {x, y}], u[0, x, y] == 0, Derivative[1, 0, 0][u][0, x, y] == 0, DirichletCondition[u[t, x, y] == If[t < 1, t, 1], x == 0]}, u, {x, y}∈RegionUnion[Rectangle[{0, 0}, {5, 1}], Disk[{5, 1 / 2}, 1 / 2]], {t, 0, 10}
, EvaluationMonitor :> (monitor = Row[{"t = ", CForm[t]}])], monitor]Steps in parameter space for a nonlinear fit:
data = {{0.18, -0.13}, {0.84, -0.06}, {0.05, 0.88}, {0.24, -0.63}, {0.67, 0.93}, {0.05, 0.88}, {0.65, 0.92}, {0.01, 0.99}, {0.17, -0.04}, {0.23, -0.55}};
lp = ListPlot[data, PlotRange -> All];model[{a_, k_, w_, p_}][x_] = a Exp[-k x] Sin[w x + p];Monitor the evolution of the model over the steps with a graph:
Module[{vars = {a, k, w, p}}, Monitor[FindFit[data, model[vars][x], vars, x, StepMonitor :> Pause[0.3]], Show[Plot[model[vars][x], {x, 0, 1}, PlotRange -> {-2, 2}], lp]]]Implement a simple LU decomposition with a slowdown parameter
:
LU[A_, p_ : 0] := Block[{m, n, L, U}, {m, n} = Dimensions[A];{L, U} = {IdentityMatrix[n], A};
Do[Pause[p];L[[k ;; n, k]] = U[[k ;; n, k]] / U[[k, k]];U[[(k + 1) ;; n, k ;; n]] = U[[(k + 1) ;; n, k ;; n]] - L[[(k + 1) ;; n, {k}]].U[[{k}, k ;; n]];
, {k, 1, n - 1}];
{L, U}]Monitor an algorithm animation using MatrixForm or MatrixPlot:
Monitor[LU[{{1, 2, 3}, {4, 5, 7}, {6, 8, 9}}, 1], MatrixForm /@ {L, U}]Monitor[LU[RandomReal[1, {10, 10}], .3]//Short, MatrixPlot /@ {L, U}]Properties & Relations (4)
If the computation being monitored completes during the initial delay, no monitor will be displayed:
AbsoluteTiming[Monitor[Do[i, {i, 10 ^ 7}], i, 2]]The following computation takes longer than two seconds, and so the monitoring expression appears:
AbsoluteTiming[Monitor[Do[i, {i, 10 ^ 8}], i, 2]]If the head of expr is not a supported head for Monitor[expr], no monitoring interface is created:
AbsoluteTiming[Monitor[For[i = 1, i <= 6, i++, Pause[0.5]]]]Compare when For is replaced with Do, which is supported:
AbsoluteTiming[Monitor[Do[Pause[0.5], {i, 6}]]]Many numerical functions have StepMonitor and EvaluationMonitor options to update expressions to be monitored:
Monitor[c = 0;NDSolve[{Subscript[∂, t, t]u[t, x] == Subscript[∂, x, x]u[t, x] + Tanh[u[t, x]] , u[0, x] == E^-x^2, u^(1, 0)[0, x] == 0, u[t, -10] == u[t, 10]}, u, {t, 0, 25}, {x, -10, 10}, StepMonitor :> (c++)], c]The local variables in the input are automatically updated without appearing in the option value:
Monitor[c = 0;NDSolve[{Subscript[∂, t, t]u[t, x] == Subscript[∂, x, x]u[t, x] + Tanh[u[t, x]] , u[0, x] == E^-x^2, u^(1, 0)[0, x] == 0, u[t, -10] == u[t, 10]}, u, {t, 0, 25}, {x, -10, 10}, EvaluationMonitor :> {c++}], {HoldForm[c] == c, HoldForm[t] == t}]Monitor can monitor dynamically scoped variables such as those created by Block whether Block is inside or outside the Monitor expression:
s = 0;Monitor[Table[Block[{val = (1/n^3)}, s += val;Pause[0.2];val], {n, 1, 10}], val]s = 0;Block[{val}, Monitor[Table[val = (1/n^3);s += val;Pause[0.2];val, {n, 1, 10}], val]]Lexically scoped variables such as those created by Module can only be monitored if Monitor appears within the scoping construct:
s = 0;Monitor[Table[Module[{val = (1/n^3)}, s += val;Pause[0.2];val], {n, 1, 10}], val]s = 0;Module[{val}, Monitor[Table[val = (1/n^3);s += val;Pause[0.2];val, {n, 1, 10}], val]]Possible Issues (3)
Monitor can increase the time of a calculation:
AbsoluteTiming[Do[i, {i, 10 ^ 7}]]AbsoluteTiming[Monitor[Do[i, {i, 10 ^ 7}], i]]This is especially true for the form Monitor[expr] when there are very many steps, each of which is very fast:
AbsoluteTiming[Monitor[Do[i, {i, 10 ^ 7}]]]Use Refresh to control the update interval used for displaying:
AbsoluteTiming[Monitor[Do[i, {i, 10 ^ 7}], Pause[0.03];i]]AbsoluteTiming[Monitor[Do[i, {i, 10 ^ 7}],
Refresh[Pause[0.03];i, UpdateInterval -> 0.2, TrackedSymbols -> {}]]]For automatically monitoring the work, the supported head must be the outermost head in the expression:
Monitor[Table[Pause[.3];Sqrt[n], {n, 10}]]Monitor[{Table[Pause[.3];Sqrt[n], {n, 10}]}]The default value of the options StepMonitor and EvaluationMonitor is None:
Options[NDSolve, {StepMonitor, EvaluationMonitor}]This means the internal variables cannot be monitored:
Monitor[NDSolve[{Subscript[∂, t, t]u[t, x] == Subscript[∂, x, x]u[t, x] + Tanh[u[t, x]] , u[0, x] == E^-x^2, u^(1, 0)[0, x] == 0, u[t, -10] == u[t, 10]}, u, {t, 0, 25}, {x, -10, 10}], 5]Changing it to any other value will make the variables accessible:
Monitor[NDSolve[{Subscript[∂, t, t]u[t, x] == Subscript[∂, x, x]u[t, x] + Tanh[u[t, x]] , u[0, x] == E^-x^2, u^(1, 0)[0, x] == 0, u[t, -10] == u[t, 10]}, u, {t, 0, 25}, {x, -10, 10}, StepMonitor -> {}], t]See Also
Dynamic PrintTemporary ProgressIndicator EvaluationMonitor StepMonitor Print Sow Trace
Function Repository: MonitorProgress DisplayWithProgress
Related Guides
Related Workflows
- Dynamically Monitor Values of Variables
History
Introduced in 2007 (6.0) | Updated in 2014 (10.0) ▪ 2026 (15.0)
Text
Wolfram Research (2007), Monitor, Wolfram Language function, https://reference.wolfram.com/language/ref/Monitor.html (updated 2026).
CMS
Wolfram Language. 2007. "Monitor." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2026. https://reference.wolfram.com/language/ref/Monitor.html.
APA
Wolfram Language. (2007). Monitor. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Monitor.html
BibTeX
@misc{reference.wolfram_2026_monitor, author="Wolfram Research", title="{Monitor}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/Monitor.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_monitor, organization={Wolfram Research}, title={Monitor}, year={2026}, url={https://reference.wolfram.com/language/ref/Monitor.html}, note=[Accessed: 12-June-2026]}