PDA

View Full Version : how to define local variables and constants in mathematica


yashar
Dec2-11, 10:00 AM
hi
suppose i run Two notebook and in each of them i have matrix A and Constant B and a function C
in each notebook these things have the same name.
if in notebook 1 i assign B=10 then in notebook 2 B is 10 too , which is not my desire.
how can i define these constants and matrices and functions so that they are not affect each other in each notebook.
i do not want to rename one of these entities.

thanks

a-tom-ic
Dec2-11, 06:35 PM
You might want to clear the globals at the beginning of your notebook (only works if you process the notebook as a whole):
http://reference.wolfram.com/mathematica/howto/ClearMyDefinitions.html
Another option could be to use local variables:
http://reference.wolfram.com/mathematica/tutorial/ModulesAndLocalVariables.html

Simon_Tyler
Dec3-11, 11:04 PM
You can handle this behaviour using Contexts. Under the Evaluation menu, choose "Notebook's Default Context" > "Unique to This Notebook".

Now each notebook will be using different name spaces, and the variables won't clash.

yashar
Dec7-11, 08:55 AM
thanks