Mathematica Why Doesn't Mathematica Erase Memory Between Runs?

AI Thread Summary
The discussion centers around issues with variable persistence in Mathematica when running a program that populates a matrix with specific values. The user initially creates a matrix P and populates the first row with the value 2. Upon modifying the program to change the row being populated, the output does not match the expected format, indicating that previous values are still affecting the current run. Suggestions for resolving this issue include using Clear, ClearAll, or Remove to ensure that all previous variable states are reset before rerunning the program. The user seeks a solution to effectively clear memory and achieve the desired output format for the matrix.
Rjah
Messages
1
Reaction score
0
Hi,

I ran this program:

P = Table[Subscript[p, i, j], {i, 0, 3}, {j, 0, 2}]
For[j = 0; i=0, j <= 2, j++, Subscript[p, i, j] = 2]
MatrixForm[P]

What is gives me is this:
2 2 2
p[1,0] p[1,1] p[1,2]
p[2,0] p[2,1] p[2,2]
p[3,0] p[3,1] p[3,2]


If I change the program and rerun it:

Clear[p]
P = Table[Subscript[p, i, j], {i, 0, 3}, {j, 0, 2}]
For[j = 0; i=1, j <= 2, j++, Subscript[p, i, j] = 2]
MatrixForm[P]

Now it gives me:

2 2 2
1 1 1
p[2,0] p[2,1] p[2,2]
p[3,0] p[3,1] p[3,2]


I was expecting something like:
p[0,0] p[0,1] p[0,2]
1 1 1
p[2,0] p[2,1] p[2,2]
p[3,0] p[3,1] p[3,2]


I want mathematica to erase its memory from the previous run, but nothing seems to work!


Any suggestions?
 
Physics news on Phys.org
Did you try something like
Clear[P]
or
For[every {i, j}, Subscript[p, i, j] = .;]
 
You might try ClearAll or Remove instead of Clear.
 

Similar threads

Replies
4
Views
2K
Replies
3
Views
4K
Replies
3
Views
2K
Replies
52
Views
12K
Replies
20
Views
5K
Replies
1
Views
2K
Back
Top