Why Doesn't Mathematica Erase Memory Between Runs?

  • Context: Mathematica 
  • Thread starter Thread starter Rjah
  • Start date Start date
  • Tags Tags
    Mathematica Matrix
Click For Summary
SUMMARY

The discussion centers on the behavior of Mathematica regarding variable memory retention between runs. The user initially creates a matrix using the command Table[Subscript[p, i, j], {i, 0, 3}, {j, 0, 2}] and encounters unexpected results when rerunning the program after attempting to clear variables. The suggested solutions include using Clear[P], ClearAll, and Remove to effectively manage variable states. The consensus is that these commands are essential for ensuring that Mathematica does not retain previous variable values.

PREREQUISITES
  • Familiarity with Mathematica programming syntax
  • Understanding of variable scoping in Mathematica
  • Knowledge of commands such as Clear, ClearAll, and Remove
  • Basic understanding of matrix operations in Mathematica
NEXT STEPS
  • Research the differences between Clear, ClearAll, and Remove in Mathematica
  • Explore variable scoping and lifetime in Mathematica
  • Learn about memory management techniques in Mathematica
  • Investigate the use of MatrixForm for displaying matrices in Mathematica
USEFUL FOR

This discussion is beneficial for Mathematica users, programmers, and data analysts who need to manage variable states effectively and understand memory retention issues in their computations.

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 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 41 ·
2
Replies
41
Views
10K
  • · Replies 52 ·
2
Replies
52
Views
13K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 20 ·
Replies
20
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K