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.
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.
Examples
open all close allBasic Examples (4)
Print information with every function evaluation used to find a root:
FindRoot[x ^ 2 - 2, {x, 1}, EvaluationMonitor :> Print["x = ", x, " x^2 - 2 =", x ^ 2 - 2]]Block[{c = 0}, {FindRoot[x ^ 2 - 2, {x, 1}, EvaluationMonitor :> c++], c}]Use Reap and Sow to collect evaluation data:
{res, data} = Reap[FindRoot[x ^ 2 - 2, {x, 1}, EvaluationMonitor :> Sow[x - Sqrt[2]]]]Show the superlinear convergence of the method:
ListLogLogPlot[data[[1]]]Monitor the time integration of a wave equation:
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]Scope (5)
Monitor the solution progress when solving the sine–Gordon PDE:
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}, EvaluationMonitor :> (sol = u[t, x]; time = t)], Plot[sol, {x, -10, 10}, PlotRange -> {0, 8}, PlotLabel -> time]]Evaluations for a numerical minimization:
{res, data} = Reap[FindMinimum[(x - 1) ^ 2 + 100(y - Sin[x]) ^ 2, {{x, -10}, {y, 1}}, EvaluationMonitor :> Sow[{x, y}]]]ListPlot[data[[1]]]Evaluations for computing a numerical integral with NIntegrate:
{res, data} = Reap[NIntegrate[Sqrt[x(1 - x)], {x, 0, 1}, EvaluationMonitor :> Sow[x]]];resShow a plot of the evaluation position versus evaluation number:
ListPlot[data[[1]]]Evaluations for solving a differential equation with NDSolve with a extrapolation method:
{sol, evals} = Reap[NDSolve[{x''[t] + Sin[x[t]] == 0, x[0] == 1, x'[0] == 0}, x, {t, 0, 10}, EvaluationMonitor :> Sow[{t, x[t], x'[t]}], Method -> "Extrapolation"]];A plot shows that with this method, not all evaluations are on the solution curve:
Show[Plot[Evaluate[First[{x[t], x'[t]} /. sol]], {t, 0, 10}], ListPlot[{evals[[1, All, {1, 2}]], evals[[1, All, {1, 3}]]}]]Count evaluations for doing a surface plot:
f[x_, y_] := E^x - Sin[x^3 - 3 y];Block[{c = 0}, Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, EvaluationMonitor :> c++, PlotLabel :> ToString[c] <> " evaluations"]]When the function is evaluated, it takes fewer evaluations since symbolic derivatives are used:
Block[{c = 0}, Plot3D[Evaluate[f[x, y]], {x, -2, 2}, {y, -2, 2}, EvaluationMonitor :> c++, PlotLabel :> ToString[c] <> " evaluations"]]Generalizations & Extensions (2)
Catch[FindMinimum[Exp[x] + 1 / x ^ 2, {x, 1}, EvaluationMonitor :> If[x ≤ 0, Throw["Negative x"]]]]With a different starting value, the computation is stopped:
Catch[FindMinimum[Exp[x] + 1 / x ^ 2, {x, 10}, EvaluationMonitor :> If[x ≤ 0, Throw["Negative x"]]]]Distinguish between function and derivative evaluations in doing a numerical minimization:
{sol, evaldata} = Reap[FindMinimum[(x - 1) ^ 2 + 100(y - x ^ 2) ^ 2, {{x, -1}, {y, 1}}, EvaluationMonitor :> Sow[{x, y}, 0], Gradient -> {"Symbolic", EvaluationMonitor :> Sow[{x, y}, 1]},
Method -> {"Newton", "Hessian" -> {"Symbolic", EvaluationMonitor :> Sow[{x, y}, 2]}}], _, Rule];solShow function, gradient, and Hessian evaluations in blue, yellow and red, respectively:
colors = {Blue, Yellow, Red};
sizes = {PointSize[0.015], PointSize[0.03], PointSize[0.05]};ContourPlot[(x - 1) ^ 2 + 100(y - x ^ 2) ^ 2, {x, -1, 1}, {y, -1, 1}, Epilog -> Table[{colors[[i + 1]], sizes[[i + 1]], Map[Point, i /. evaldata]}, {i, 2, 0, -1}]]Applications (6)
Show where evaluations were done for part of a plot using a tooltip that indicates order:
f[x_] = Exp[-x ^ 2];
{plot, evals} = Reap[Block[{e = 0}, Plot[f[x], {x, -5, 5}, PlotRange -> All, EvaluationMonitor :> Sow[Tooltip[Point[{x, f[x]}], ++e]]]]];
Show[plot, Graphics[{Red, evals}]]Show number of evaluations required to find a root as a function of starting value:
evals[sv_ ? NumberQ] := Block[{c = 0}, FindRoot[Cos[x], {x, sv}, EvaluationMonitor :> c++];c]Plot[evals[sv], {sv, 0, π}]Compare evaluations required for different local minimization methods:
TableForm[Table[ Block[{e = 0}, {method, Norm[{x - 1, y - 1} /. FindMinimum[(x - 1) ^ 2 + 100(y - x ^ 2) ^ 2, {{x, -1}, {y, 1}}, Method -> method, EvaluationMonitor :> e++][[2]]], e}], {method, {Automatic, "LevenbergMarquardt", "Newton", "QuasiNewton", "Gradient"}}], TableHeadings -> {{}, {"Method", "Error", "Evaluations"}} ]Compare evaluations and timing required for different ODE integration methods in NDSolve:
evals[method_] := Block[{e = 0}, Timing[NDSolve[{x''[t] + x[t] == 0, x[0] == 1, x'[0] == 0}, x, {t, 0, 100π}, MaxSteps -> Infinity, Method -> method, EvaluationMonitor :> e++];e]]methods = {Automatic, "Adams", "BDF", "ExplicitRungeKutta", "ImplicitRungeKutta", "Extrapolation"};TableForm[Table[Join[{method}, evals[method]], {method, methods}], TableHeadings -> {{}, {"Method", "Timing", "Evaluations"}}]Steps and evaluations as a function of PrecisionGoal and AccuracyGoal in NDSolve:
se[method_][g_] := Block[{s = 0, e = 0}, NDSolve[{x''[t] + x'[t] / 10 + x[t] / (1 + x[t] ^ 2) == Sin[t], x[0] == 1, x'[0] == 0}, x, {t, 0, 100}, PrecisionGoal -> g, AccuracyGoal -> g, WorkingPrecision -> If[g > 8, 2g, MachinePrecision], StepMonitor :> s++, EvaluationMonitor :> e++, MaxSteps -> Infinity, Method -> method];{s, e}]Use a fixed order explicit Runge–Kutta method:
erk = Table[Flatten[{g, se[{"ExplicitRungeKutta", "DifferenceOrder" -> 8}][g]}], {g, 0, 20, 2}]Use an adaptive order extrapolation method:
ext = Table[Flatten[{g, se["Extrapolation"][g]}], {g, 0, 20, 2}]Compare the two methods. Beyond a goal of about 12, adaptive order is clearly superior:
ListLogPlot[{erk[[All, {1, 2}]], erk[[All, {1, 3}]], ext[[All, {1, 2}]], ext[[All, {1, 3}]]}, PlotStyle -> {Purple, Red, Orange, Blue}]Evaluations 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}};model[{w_, p_}] = Exp[-0.1 x] Sin[w x + p];{fit, {evals}} = Reap[FindFit[data, model[{w, p}], {w, p}, x, EvaluationMonitor :> Sow[{w, p}]]]The evaluation points on a contour plot of the sum of squares:
residual = Map[Function[{x}, Evaluate[model[{w, p}]]], data[[All, 1]]] - data[[All, 2]];
ContourPlot[Evaluate[residual.residual], {w, 0, 10}, {p, 0, 2 π}, Epilog -> {Red, Point[evals]}]{bfit, {bevals}} = Reap[FindFit[data, model[{w, p}], {{w, 4}, {p, 4}}, x, EvaluationMonitor :> Sow[{w, p}]]]ContourPlot[Evaluate[residual.residual], {w, 0, 10}, {p, 0, 2 π}, Epilog -> {{Red, Point[evals]}, {Green, Point[bevals]}}]Compare the two fits with the data:
Show[Plot[Evaluate[model[{w, p}] /. {fit, bfit}], {x, 0, 1}, PlotStyle -> {{Red}, {Green}}], ListPlot[data]]Properties & Relations (1)
Evaluation done for EvaluationMonitor is scoped like Block:
f[x_] := x ^ 2 - 2;FindRoot[f[x], {x, 1, 2}, EvaluationMonitor :> Print["x = ", x, " f[x] = ", f[x]]]This is effectively using Block with assignments of numerical values of the variable:
ff[xx_ ? NumberQ] := Block[{x = xx}, Print["x = ", x, " f[x] = ", f[x]];f[x]]FindRoot[ff[x], {x, 1, 2}]Tech Notes
Related Guides
Related Workflows
- Print Intermediate Values of a Variable ▪
- Dynamically Monitor Values of Variables
History
Introduced in 2003 (5.0) | Updated in 2007 (6.0)
Text
Wolfram Research (2003), EvaluationMonitor, Wolfram Language function, https://reference.wolfram.com/language/ref/EvaluationMonitor.html (updated 2007).
CMS
Wolfram Language. 2003. "EvaluationMonitor." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2007. https://reference.wolfram.com/language/ref/EvaluationMonitor.html.
APA
Wolfram Language. (2003). EvaluationMonitor. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/EvaluationMonitor.html
BibTeX
@misc{reference.wolfram_2026_evaluationmonitor, author="Wolfram Research", title="{EvaluationMonitor}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/EvaluationMonitor.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_evaluationmonitor, organization={Wolfram Research}, title={EvaluationMonitor}, year={2007}, url={https://reference.wolfram.com/language/ref/EvaluationMonitor.html}, note=[Accessed: 13-June-2026]}