1
$\begingroup$

Try to reproduce the following code:

    upper = 0;
    lower = 0;
    set = False;

    Manipulate[
    tepsr = {1, 2, 3, 4, 5, 6, 7, 8, 9}[[1 + low ;; 9 - hig]]; 
    tepsi = {9, 8, 7, 6, 5, 4, 3, 2, 1}[[1 + low ;; 9 - hig]]; 
    ListLogLinearPlot[{tepsr, tepsi}]
    Button["Set", set = True;]
    If[set == True, upper = hig; lower = low; set = False; 
    epsi = Interpolation[tepsi];], {{low, 0}, 0, 3, 1}, {{hig, 0}, 0, 
    3, 1}]

For me it does not work most of the time. I get an Message "The Kernel is not responding to an dynamic evaluation...".

I tried kernel restart, PC restart, clean Mathematica startup, and complete reinstallation. Nothing works. The code worked fine this afternoon. Now I am tempted to apply destructive muscle force against my hardware. I already shredded a pillow.

$\endgroup$
2
  • $\begingroup$ No error message for me (v. 10.4.0.0, Mac). But why you want the Set button in your display field is beyond me. $\endgroup$ Jun 22, 2016 at 22:56
  • $\begingroup$ And you need semicolons throughout. You have no delimiters between your plot and the button, to take one example. $\endgroup$ Jun 22, 2016 at 23:08

3 Answers 3

2
$\begingroup$

I cannot reproduce the OP's problem, and despite that the variations on David G. Stork's and Chris Degnan fixes are limited and trivial, I will make some comments on potential issues in the code. These issues may in fact be a problem in the OP's notebook (but not in the code per se), which I will explain.

The body of a Manipulate is wrapped in Dynamic[] and depends on all the symbols (that are not System` functions) in the code. In the OP's case, the dependencies include these Global` variables:

tepsr, tepsi, upper, lower, epsi

Any time one of these changes, the whole body will be recalculated. If there are other Dynamic[] things going on in the notebook that depend on these variables, odd things can happen (infinite loops, slow response, the kernel message the OP is getting, and so forth).

Further there may be some (hidden) system parameters that the Manipulate may depend on, especially if there is a plot in the output.

And, of course, the body depends on the localized Manipulate variables, but these are usually less problematic (or if they are, the problem usually can be understood in terms of the code in the body).

The option TrackedSymbols is the usual way to control dependencies in complicated situations, such as in this question. Another consideration is to localize variables, so that the Manipulate has as few global side effects and dependencies as possible.

In the OP's code, it is not clear whether tepsr and tepsi need to be saved in a global variable. They can be recovered from upper and lower if necessary, and in this case, the extra expense of recomputing them would be minimal. So in the example below, I show one way of localizing them with With. The other "fix" is to set the tracked symbols to be just the Manipulate control variables. There is a short-hand for this, TrackedSymbols -> True.

I've followed the same path as Chris in putting the button's intended actions in the button itself. Having the button set a flag that causes the whole body to be reevaluated should usually be avoided, since it causes (potentially lots of) other computations that are unnecessary.

Finally, I show a variation on the presentation of the output elements, putting the button in the plot label; Chris and David show reasonable alternatives as well.

upper = 0;
lower = 0;

Manipulate[
 With[
  {tepsr = {1, 2, 3, 4, 5, 6, 7, 8, 9}[[1 + low ;; 9 - hig]],
   tepsi = {9, 8, 7, 6, 5, 4, 3, 2, 1}[[1 + low ;; 9 - hig]]},
  ListLogLinearPlot[
   {tepsr, tepsi} , 
   PlotLabel -> Button["Set",
     upper = hig;
     lower = low;
     epsi = Interpolation[tepsi]]
   ]
  ],
 {{low, 0}, 0, 3, 1}, {{hig, 0}, 0, 3, 1},
 TrackedSymbols :> True]
$\endgroup$
1
$\begingroup$

Not really clear what you're trying to do. Maybe this will help though.

Manipulate[
 tepsr = {1, 2, 3, 4, 5, 6, 7, 8, 9}[[1 + low ;; 9 - hig]];
 tepsi = {9, 8, 7, 6, 5, 4, 3, 2, 1}[[1 + low ;; 9 - hig]];
 Row[{ListLogLinearPlot[{tepsr, tepsi, epsi}, ImageSize -> 400] ,
   Button["Set",
    upper = hig;
    lower = low;
    epsi = Interpolation[tepsi]]}], {{low, 0}, 0, 3, 1}, {{hig, 0}, 0, 3, 1}]
$\endgroup$
1
$\begingroup$

Try this:

Manipulate[

 If[set == True,
  (upper = hig;
   lower = low), 
   upper = lower = 0)];

 tepsr = {1, 2, 3, 4, 5, 6, 7, 8, 9}[[1 + low ;; 9 - hig]];
 tepsi = {9, 8, 7, 6, 5, 4, 3, 2, 1}[[1 + low ;; 9 - hig]];

 ListLogLinearPlot[{tepsr, tepsi}],

 {{low, 0}, 0, 3, 1},
 {{hig, 0}, 0, 3, 1},
 {{set, False}, {False, True}}]

Your problem may be due, in part, to your changing the value of set within a conditional based on set. And you never use epsi, so why compute it?

Your code is very ugly, with unnecessary use of indexes, written out ranges of integers and such.

Try this instead:

Manipulate[

 If[set == True,
  (upper = hig;
   lower = low), 
   upper = lower = 0];

 tepsr = Range[low, 9 - hig];
 tepsi = Reverse@Range[low, 9 - hig];

 ListLogLinearPlot[{tepsr, tepsi}],

 {{low, 0}, 0, 3, 1},
 {{hig, 0}, 0, 3, 1},
 {{set, False}, {False, True}}]
$\endgroup$

Your Answer

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

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