Mathematica is remember variable values it shouldn't be

  • Context: Mathematica 
  • Thread starter Thread starter rynlee
  • Start date Start date
  • Tags Tags
    Mathematica Variable
Click For Summary
SUMMARY

The discussion centers on variable management in Mathematica, specifically regarding the behavior of variable values when using the Clear[] function. Users reported that Mathematica retains variable values even after attempts to clear them, leading to unexpected behavior in code execution. The resolution involved placing Clear[] functions appropriately to ensure that variables do not retain unwanted values. It was concluded that Mathematica's notebook interface does not follow a linear execution model, as it interacts with the kernel in a non-linear fashion.

PREREQUISITES
  • Understanding of Mathematica's variable assignment and scope
  • Familiarity with the Clear[] function in Mathematica
  • Knowledge of how Mathematica evaluates cells and manages state
  • Basic experience with Mathematica notebooks and kernel interaction
NEXT STEPS
  • Research the implications of variable scope in Mathematica
  • Learn about the evaluation order of cells in Mathematica notebooks
  • Explore advanced usage of the Clear[] function and its alternatives
  • Investigate best practices for managing variable states in Mathematica
USEFUL FOR

This discussion is beneficial for Mathematica users, particularly those involved in programming, data analysis, or algorithm development who need to manage variable states effectively.

rynlee
Messages
44
Reaction score
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
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?
 
That's right. The notebook is not spatially linear. In essence it's just a pretty interface to the kernel.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 21 ·
Replies
21
Views
6K
  • · Replies 1 ·
Replies
1
Views
10K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 4 ·
Replies
4
Views
15K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K