I have 2 sections is my notebook:
___________SECTION 1______________
Contains variables x y z
___________SECTION 2______________
Should copy over the values of x and y up to now, but make all changes to x
and y local to section 2
The idea is that if I set x = 2
in Section 1, then when the notebook is executed we will have x == 2
in Section 2. However, should I execute x = 3
in Section 2 and then go back and execute x
in Section 1, it will still give me back x = 2
in section 1 because the changes to x
are local to Section 2.
Meanwhile, if I do the same for z
, which I did not make "local" to section 2, then the value for z
will be altered in section 1 by what I do in section 2.
Thanks a lot for your help!
--- UPDATE ---
Okay, to make my problem clearer. I have a very long notebook in which I do many calculations with symbolic variables (matrices included). At some point, I arrive at the symbolic expression that I want and from that point onwards I want to begin substituting real values for the symbolic variables, e.g. what may have before been the symbolic variable AA
I now substitute with {{a,b,c},{d,e,f},{g,h,i}}
. My problem is that once I do this, execution of anything from the start of my document - which assumes symbolic variables - fails and throws lots of errors because now those symbolic variables are substituted with their definitions by Mathematica.
Since my notebook has 1000+ lines of code, I do not want to change anything in terms of how I write my expressions to avoid this "propagation from end to beginning of notebook" (too late for that, although for my future better coding your suggestions are welcome). Therefore, I am looking for a non-intrusive way to separate the section with symbolic variables and the section where these variables become substituted by their definitions. At the same time, I want the latter section to be able to use the previous (symbolic) section's results.
I hope this is a useful clarification. Thank you!
Module
,Block
, etc... Here is a detailed discussion on MMA.SE of their use cases as well. To be honest though, your setup seems to be designed on purpose to engender confusion should the need to troubleshoot it arise :-) $\endgroup$ – MarcoB Jul 31 '15 at 16:22Context
s. $\endgroup$ – Jens Jul 31 '15 at 16:35Clear[Evaluate[Context[]<>"*"]]
. This will allow the symbolic stuff to always work. Trying to fix an existing notebook to do everything you asked is probably not realistic. $\endgroup$ – Jens Jul 31 '15 at 17:50