How does Clear [] & ClearAll [] work? Clear [] without deleting the variables used by two different Manipulate [] s

I have two different Mathematica laptops with similar but different features. Both work fine when they are the only laptop. One of them successively fails when the other laptop is open, despite my (liberal) use of Clear [] to clear the corresponding variables.

Call it, say GlobalManipulate

ClearAll["Global`*"] Clear["Global`*"] Definition[linear] linear[x_] := ax; quad[x_] := ax^2; functionList := {linear, quad}; Manipulate[ Plot[function[dummy], {dummy, -10, 10}], {function, functionList}, {a, -10, 10}, LocalizeVariables -> False, TrackedSymbols -> All ] 

Call it, say, LocalManipulate

 Clear["Global`*"]; Manipulate[ { linear := ax; quad := ax^2; linear, quad, function, Plot[ ReleaseHold@function , {x, -10, 10}] }, {function, { HoldForm@linear , HoldForm@quad }}, {a, -10, 10}, TrackedSymbols -> All ] 

When it starts on its own, GlobalManipulate works as expected, and I see that the graph, which is updated as a , is changing. The definition of linearity gives Null .

When LocalManipulate is open, it works, GlobalManipulate no longer works. even when restarted . This graph appears for a second and then disappears.

I reproduced this using my local copy of Mathematica 8 and a remote copy of Mathematica 7.

The problem should include the linear[x_] and quad[x_] functions since

GlobalManipulatePrime

 ClearAll["Global`*"] Clear["Global`*"] Definition[linear] linear1[x_] := ax; quad1[x_] := ax^2; functionList := {linear1, quad1}; Manipulate[ Plot[function[dummy], {dummy, -10, 10}], {function, functionList}, {a, -10, 10}, LocalizeVariables -> False, TrackedSymbols -> All ] 

works great.

Edited to add bold text to emphasize that I am reerunning Global, and that I am trying to understand why functions are saved, despite my ClearAll [].

+4
source share
2 answers

In addition to transferring functions to Module or DynamicModule and localizing variables, you can also place laptops in separate contexts using the Evaluation ► Notebook Default Context menu Evaluation ► Notebook Default Context .

You can also set the context using the Begin function. This must be done before your functions are defined.

Refresh

I did not read your question too well, I think. As for the reason, ClearAll does not work:

  • Due to the linearity definition in LocalManipulate using the localized variable a, the linear character is defined as something like linear:=FE`a$$51 x
  • In GlobalManipulate, you use both the linear name (in the choice of function) and the linear function
  • Due to the definition of the linear character in FE`a$$51 x string functionList := {linear, quad}; in GlobalManipulate now actually means functionList := {FE`a$$51 x,FE`a$$53 x^2} , which means nothing from another Manipulate context, so your plot disappears
  • Why then does ClearAll not delete this definition? This is due to the properties of dynamic variables buried in the Manipulation field visible in the LocalManipulate laptop. They continue to be reviewed there. Uninstall the Manipulate output and re-run GlobalManipulate and you will see that it now works. Something similar is discussed here .
+4
source

Inside LocalManipulate , you have linear := ax; quad := ax^2 definitions linear := ax; quad := ax^2 linear := ax; quad := ax^2 . Since they are not declared in the controller part of the Manipulate command, they are not localized and thus overwrite global variables and break your GlobalManipulate .

The easiest way to localize variables inside Manipulate is to use them to add the None controller type. Below I have changed your LocalManipulate code, so the last line does linear and quad local for this particular Manipulate ( DynamicModule )

 Manipulate[{linear := ax; quad := ax^2; linear, quad, function, Plot[ ReleaseHold@function , {x, -10, 10}]}, {function, { HoldForm@linear , HoldForm@quad }}, {a, -10, 10}, {linear, None}, {quad, None}, TrackedSymbols -> All] 
+5
source

All Articles