Skip to main content
added 380 characters in body; added 2 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

I think what you need is ContinuousAction -> False and TrackedSymbols -> vars:

Foobar[] :=
  Module[{f, vars, grad}, f = a x^3 - b x^2 + c y^2;
   vars = {a, b, c};
   With[{fman = f, controls = Apply[Sequence, {{#, 0}, -5, 5} & /@ vars]},
    Manipulate[
     g = fman/(x^2 + y^2 + 1);
     grad = D[g, {{x, y}}];
     Print[grad];
     , controls, ContinuousAction -> False, TrackedSymbols -> vars]
   ]];

ContinuousAction -> False is needed to keep from evaluating continuously while dragging the sliders. In the original version this happened and the Print statements were sent to the Messages window.

TrackedSymbols -> vars is needed to keep Mathematica from reevaluating when the values of g or grad change (which would be necessary if these were interdependent).

I think what you need is ContinuousAction -> False and TrackedSymbols -> vars:

Foobar[] :=
  Module[{f, vars, grad}, f = a x^3 - b x^2 + c y^2;
   vars = {a, b, c};
   With[{fman = f, controls = Apply[Sequence, {{#, 0}, -5, 5} & /@ vars]},
    Manipulate[
     g = fman/(x^2 + y^2 + 1);
     grad = D[g, {{x, y}}];
     Print[grad];
     , controls, ContinuousAction -> False, TrackedSymbols -> vars]
   ]];

I think what you need is ContinuousAction -> False and TrackedSymbols -> vars:

Foobar[] :=
  Module[{f, vars, grad}, f = a x^3 - b x^2 + c y^2;
   vars = {a, b, c};
   With[{fman = f, controls = Apply[Sequence, {{#, 0}, -5, 5} & /@ vars]},
    Manipulate[
     g = fman/(x^2 + y^2 + 1);
     grad = D[g, {{x, y}}];
     Print[grad];
     , controls, ContinuousAction -> False, TrackedSymbols -> vars]
   ]];

ContinuousAction -> False is needed to keep from evaluating continuously while dragging the sliders. In the original version this happened and the Print statements were sent to the Messages window.

TrackedSymbols -> vars is needed to keep Mathematica from reevaluating when the values of g or grad change (which would be necessary if these were interdependent).

added 222 characters in body; deleted 34 characters in body; added 162 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

I am under the impression that this question is a duplicate, but as I cannot presently locate one I shall give a short answer. In this particular casethink what you can useneed is ContinuousAction -> False and TrackedSymbols -> vars:

ControlActive[NullFoobar[] :=
  Module[{f, Print[grad]]vars, grad}, f = a x^3 - b x^2 + c y^2;
   vars = {a, b, c};
   With[{fman = f, controls = Apply[Sequence, {{#, 0}, -5, 5} & /@ vars]},
    Manipulate[
     g = fman/(x^2 + y^2 + 1);
     grad = D[g, {{x, y}}];
     Print[grad];
     , controls, ContinuousAction -> False, TrackedSymbols -> vars]
   ]];

in place of the Print expression and it should stop the doubling.

I am under the impression that this question is a duplicate, but as I cannot presently locate one I shall give a short answer. In this particular case you can use:

ControlActive[Null, Print[grad]]

in place of the Print expression and it should stop the doubling.

I think what you need is ContinuousAction -> False and TrackedSymbols -> vars:

Foobar[] :=
  Module[{f, vars, grad}, f = a x^3 - b x^2 + c y^2;
   vars = {a, b, c};
   With[{fman = f, controls = Apply[Sequence, {{#, 0}, -5, 5} & /@ vars]},
    Manipulate[
     g = fman/(x^2 + y^2 + 1);
     grad = D[g, {{x, y}}];
     Print[grad];
     , controls, ContinuousAction -> False, TrackedSymbols -> vars]
   ]];
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

I am under the impression that this question is a duplicate, but as I cannot presently locate one I shall give a short answer. In this particular case you can use:

ControlActive[Null, Print[grad]]

in place of the Print expression and it should stop the doubling.