1
$\begingroup$

The obvious way of plotting the progress of FindMinimum fails with an error about things not being localizable:

Dynamic[ListPlot[vals]]
vals={};FindMinimum[x1^2, {x1}, StepMonitor :> vals = Append[vals, x1]];
  FindMinimum::vloc: The variable StepMonitor:>vals=Append[vals,x1] cannot be localized so that it can be assigned to numerical values. >>

I am not certain of the usefulness of the error, as when I added the StepMonitor to a more complex FindMinimum expression (that previously worked), it led to an error about the Gradient (when I put the StepMonitor after the Gradient) or the same error as above (otherwise).

Is this achievable in some way?

$\endgroup$
3
$\begingroup$

You can just use AppendTo, I added a Pause since it happens so fast otherwise

vals = {};
Dynamic[ListPlot[vals]]
FindMinimum[x1^4, {x1}, StepMonitor :> (AppendTo[vals, x1]; Pause[.5])]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.