I am attempting to Append a new value into my list paramMonitor whenever the value for B changes. I had the code working perfectly, but my computer crashed without saving the document. I am now having a lot of trouble (dynamically) appending these values to my list.

My attempts:

  • This updates B but does nothing to append the value {B, e, some number} to paramMonitor

              {B,e,Abs[model[B, e][#] & /@ test[[All, 1]] - test[[All, 2]]] // Total}]


  • Removing the first argument 'B', this code fails to compile and simply aborts upon execution:

             {B,e, Abs[model[B, e][#] & /@ test[[All, 1]] - etst[[All, 2]]] // Total}]

I believe this is a quick fix (since I had it working earlier), but I cannot seem to find the issue.

  • $\begingroup$ Before I will update the answer, please tell me how B can be changed? I mean, it is tied to some kind of controller or it is just a global variable that can be change anywhere? $\endgroup$
    – Kuba
    Apr 24 '14 at 11:15
  • $\begingroup$ Sorry about the late response. B is changed through NonLinearModelFit (NLMF). NLMF is finding the best fit values for B and e. I have NLMF's EvaluationMonitor printing "B and e values" to the screen. So, at every new evaluation step, Dynamic[B] will update. Thanks for all the help!! $\endgroup$
    Apr 29 '14 at 18:32
  • $\begingroup$ So my answer does not fit your needs quite well, right? $\endgroup$
    – Kuba
    Apr 29 '14 at 18:36
  • $\begingroup$ Unfortunately not. Since NonlinearModel takes a very long time to evaluate, I wanted a way to monitor its progress in Real-Time. My other option is to add some commands within EvaluationMonitor, like this $\endgroup$
    May 1 '14 at 0:51

The most important thing, and the thing that can be easily missed is that the second argument of Dynamic must be a function or a list of functions:

list = {};
Slider[Dynamic[b, (b = #; list = Join[list, {b}]) &], {1, 10, 1}]

enter image description here

  • $\begingroup$ Another thing that can be easily missed is that the second argument of Dynamic only seems to work reliably when the Dynamic expression is evaluated as an argument of a control or other GUI element (like the slider you used in your example). I have found that the front-end does seem to like a naked Dynamic with a 2nd argument when it encounters one at top-level such as in the example the OP gave. $\endgroup$
    – m_goldberg
    Apr 24 '14 at 8:01
  • $\begingroup$ @m_goldberg good point, I have not though he tried to do that this way. It seems I have to write a little bit more. :) $\endgroup$
    – Kuba
    Apr 24 '14 at 9:15
  • $\begingroup$ @m_goldberg: you say "only seems to work reliably", but does it work at all and is it supposed to? I would have said it most probably isn't even meant to work, but honestly don't know what actually is the "documented" behavior that I could expect. I also can't see that a naked Dynamic with a 2nd argument does anything relevant concerning its 2nd argument, other than quietly ignoring it. Am I missing something here? $\endgroup$ Apr 24 '14 at 14:09
  • $\begingroup$ @AlbertRetey. I used tentative language because I don't know for sure. From my reading of the docs and my own experiments, I think it likely that the 2nd argument of Dynamic is not intended to be used at top-level the way the OP of this question did. My experience with naked Dynamic is exactly as you say. BTW, there is a typo in my comment. I meant to say: "does not seem to like a naked Dynamic" $\endgroup$
    – m_goldberg
    Apr 24 '14 at 14:44
  • $\begingroup$ @AlbertRetey I agree with you, it's meant to cooperate with controllers: "during interactive changing or editing of val." I think that m_goldberg pointed that OP tried to use it in "naked" Dynamic. I'm waiting for confirmation from OP. :) $\endgroup$
    – Kuba
    Apr 24 '14 at 14:44

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.