Mathematica is remember variable values it shouldn't be

In summary, the conversation discusses a problem with variables being automatically assigned values in Mathematica, even after using the Clear[] function. The issue is resolved by placing Clear[] for all variables of interest, as Mathematica stores values once they are compiled. The notebook is also noted to not be linear in terms of spatial organization.
  • #1
rynlee
45
0
Hi There,

Once I put in values for variable farther down the code from when I first use them (I initially want them just in variable form, I don't want their values defined), every time I evaluate the cell mathematica puts the values in farther up.

Even more disturbing, however, is in other cells that are even above that cell, those variables get defined.

Even more disturbing, when I put the Clear[] function in the appropriate places, mathematica still assigns values to those variables!

Is this a bug? Or am I seriously misunderstanding something?

Thanks for any help or advice!
 
Physics news on Phys.org
  • #2
Scratch that, I believe I got it working with appropriate Clear[]'s placed for all the variables of interest. It seems that once you put a value for a variable in and it is compiled, mathematica stores that value unless it is cleared?
 
  • #3
That's right. The notebook is not spatially linear. In essence it's just a pretty interface to the kernel.
 

1. Why is Mathematica remembering variable values that I didn't explicitly assign?

Mathematica has a feature called "automatic persistence" where it remembers the values of variables that have been used in previous calculations. This feature is meant to make it easier for users to work with large and complex calculations without having to constantly redefine variables.

2. How can I disable automatic persistence in Mathematica?

You can disable automatic persistence by using the command ClearAll["Global`*"]. This will clear all values of variables in the current session and prevent Mathematica from remembering them.

3. Can I selectively disable automatic persistence for certain variables?

Yes, you can use the command Clear["var1", "var2", ...] to clear the values of specific variables. This will prevent Mathematica from remembering those values while still retaining the values of other variables.

4. Will disabling automatic persistence affect my previous calculations?

No, disabling automatic persistence will only affect the current session. Any previous calculations will remain unchanged. However, if you want to clear the values of all variables in previous sessions, you can use the command ClearAll["Global`*"] in a new session.

5. Can I turn off automatic persistence permanently?

Yes, you can turn off automatic persistence permanently by going to the "Preferences" menu in Mathematica and unchecking the box for "Automatic Persistence". This will disable automatic persistence for all future sessions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
262
  • MATLAB, Maple, Mathematica, LaTeX
Replies
21
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
9K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
14K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top