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

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?


1 Answer 1


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

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

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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