This example is from the documentation under Monitor
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[{a_, k_, w_, p_}][x_] = a Exp[-k x] Sin[w x + p]
lp = ListPlot[data, PlotRange -> All]
I can successfully plot the steps using Monitor
Module[
{
vars = {a, k, w, p}
},
Monitor[
FindFit[data, model[vars][x], vars, x,
StepMonitor :> Pause[1.0]],
Show[
Plot[model[vars][x], {x, 0, 1}, PlotRange -> {-2, 2}],
lp]
]
]
I can print the results using StepMonitor
FindFit[data, model[{a, k, w, p}][x], {a, k, w, p}, x,
StepMonitor :> Print[{a, k, w, p}]]
As shown in the documentation I can extract the results using Reap
and Sow
.
steps = Reap[
FindFit[data, model[{a, k, w, p}][x], {a, k, w, p}, x,
StepMonitor :> Sow[{a, k, w, p}]]]
I can then use the steps to plot the results.
My question is not about how to plot the results.
My question is why when I use Plot
as an argument to StepMonitor
I get no result.
I made various attempts. One is shown below.
FindFit[data, model[{a, k, w, p}][x], {a, k, w, p}, x,
StepMonitor :> CompoundExpression[
Pause[1.0],
Show[
Plot[model[{a, k, w, p}][y], {y, 0, 1}, PlotRange -> {-2, 2}],
lp
]
]
]
It gives me the results and takes much longer than running without the StepMonitor
but no plots are shown on the screen.
I am confused as to why this happens.