When I execute Foobar[] in the code below and move a slider, the variable grad is printed twice. Why is this? How can I make the Manipulate body only execute once on each update?
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]
]
];
Edit: As noticed below, this function is creating a Manipulate. My concern is why the Manipulate appears to be executing twice for every one update. This is a minimal working example and hence there is significant amount of code (that takes a while to run) excluded from inside the Manipulate body. I included Print to emphasize that the code appears to be executing twice.
Manipulate. There's nothing wrong with that. I would expect that eventuallyfandvarswill be passed in as arguments ofFoobar. – Brett Champion Jul 16 '12 at 19:22