0
|
4534 Views
|
|
0 Total Likes
View groups...
Share

# Unusual behaviour V10.

Posted 10 years ago
 Can any one see if there is something wrong here, I have been getting weird results from this code. When I run the code all results and formatting is as expected, yet when I print the result of a 'set variable' from that code, after it has run, the variable has changed and the input number sequence has skipped a number (see picture). Also in the full version of the code, when I print the result of a variable after it has run, not only is it different but it resets one of the other variables back to 'not allocated' as the colour of that variable returns to blue and printing it just return the variable name. Here is part of the code and picture on my system. I have no other books open. n = 4; a = Partition[RandomSample[Range[n^2]], n]; k = a; Print[a]; Print[ MatrixForm[a]]; e = ToString[Column[a]]; f = StringReplace[e, {"{" .. -> "(", "}" .. -> "),"}]; Print[f]; Print[a]; Print[k]  The code was run sequentially. Paul.
 Does not happen here (Mathematica 10.0.1, Windows 7 Home Premium 64 Bit) In[18]:= Clear[n, a, k, e, f] n = 4; a = Partition[RandomSample[Range[n^2]], n]; k = a; Print[a]; Print[MatrixForm[a]]; e = ToString[Column[a]]; f = StringReplace[e, {"{" .. -> "(", "}" .. -> "),"}]; Print[f]; Print[a]; Print[k] {{13,7,15,1},{11,5,9,14},{10,3,16,2},{8,6,4,12}} (13 7 15 1 11 5 9 14 10 3 16 2 8 6 4 12 ) (13, 7, 15, 1), (11, 5, 9, 14), (10, 3, 16, 2), (8, 6, 4, 12), {{13,7,15,1},{11,5,9,14},{10,3,16,2},{8,6,4,12}} {{13,7,15,1},{11,5,9,14},{10,3,16,2},{8,6,4,12}} In[21]:= Print[k] {{13,7,15,1},{11,5,9,14},{10,3,16,2},{8,6,4,12}} In[22]:= Print[a] {{13,7,15,1},{11,5,9,14},{10,3,16,2},{8,6,4,12}} looks like the a gets re-evaluated to hold a new RandomSample.How the input sequence number propagates depends strictly on your typing habits to give new lines or not In[32]:= n = 4; n = 5; n = 6; (* one input 32, return *) In[33]:= n (* one input 33, return *) Out[33]= 6 In[34]:= n = 4; (* one input 34, new line *) n = 5; (* one input 35, new line *) n = 6; (* one input 36, return *) In[37]:= n (* one input 37 *) Out[37]= 6 Try please to quit the mathematica kernel and start with a new session - from somewhere a re-evaluation of a slipped in in your example.