2
$\begingroup$

I've encountered an error using DynamicModule to show results of some numeric or symbolic solving algorythms (I've tried NMaximize, Minimize, NMinValue). If a dynamic function (here it is named happa) uses such an algorithm, and influences the output, DynamicModule updates continuously. The following examples demonstrate the problem.

Can somebody explain why example #3 updates continuously, without any input?

  1. This example behaves as expected, printing "oops" once per every interaction with SetterBar:

    DynamicModule[{happa, dummy},
      happa[] := (dummy + 2);
      {SetterBar[Dynamic[dummy], Range[5]], Dynamic[Print["oops"]; happa[]]}]
    
  2. Now add a pointless algorithm in happa definition. This example behaves unexpectedly, printing "oops" twice per every interaction with SetterBar, suggesting that it updates twice:

    DynamicModule[{happa, dummy},
      happa[] := (Minimize[{Sin[x], x >= 0 && x <= 1}, x]; dummy + 2);
      {SetterBar[Dynamic[dummy], Range[5]], Dynamic[Print["oops"]; happa[]]}]
    
  3. Now add two pointless algorithms in happa definition. This example behaves unexpectedly, printing "oops" continuously, even without any interaction, suggesting that it is updating continuously:

    DynamicModule[{happa, dummy},
      happa[] := 
        (Minimize[{Sin[x], x >= 0 && x <= 1}, x]; 
         Minimize[{Sin[x], x >= 0 && x <= 1}, x]; dummy + 2);
      {SetterBar[Dynamic[dummy], Range[5]], Dynamic[Print["oops"]; happa[]]}]
    
  4. Now declare happa as a variable with delayed evaluation. This example behaves as expected, printing "oops" once per every interaction with SetterBar:

    DynamicModule[{happa, dummy},
      happa := 
        (Minimize[{Sin[x], x >= 0 && x <= 1}, x]; 
         Minimize[{Sin[x], x >= 0 && x <= 1}, x]; dummy + 2);
      {SetterBar[Dynamic[dummy], Range[5]], Dynamic[Print["oops"]; happa]}]
    
$\endgroup$

1 Answer 1

2
$\begingroup$

The continuous retriggering of dynamics in these examples is a bug.

It has been fixed, as of Mathematica 9.0.

$\endgroup$

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.