Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have this little program that is adopted from a Wolfram demonstrations project (link here: http://demonstrations.wolfram.com/PercolationOnASquareGrid/).

I want to see what happen if I increase the matrix size to 1000 or even above but Mathematica quits me. If I made the change inside Manipulate, it just showed "Manipulate Aborted". If it is without Manipulate, it quits the Kernel.

I don't if it there is a glitch in my version (9.00) or simply because the limit of Mathematica...

Thanks a lot for your time!!

h = 1000;
p = 0.59;

Block[{a, $RecursionLimit = 25000, w = h}, 
 per[{i_, j_}] := 
  If[1 <= i <= w && 1 <= j <= h && a[[i, j]] == 1, a[[i, j]] = 2;
   per[{i, j} + #] & /@ {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}];
 SeedRandom[2424];
 a = Map[Boole[# < p] &, RandomReal[{0, 1}, {w, h}], {2}];
 a[[All, 1]] = a[[All, h]] = 1; Do[per[{i, 1}]; per[{i, h}], {i, w}];
 ArrayPlot[Transpose[a], ImageSize -> 1000, Mesh -> True, 
  ColorRules -> {0 -> White, 1 -> Darker[Blue], 2 -> Red}]]

Another piece that doesn't work:

L = 1000;
p1 = 0.6;
seed = 2000;

perColation[{i_, j_}] :=

  If[1 <= i <= L && 1 <= j <= L && a[[i, j]] == 1,
   a[[i, j]] = 2;
   perColation[{i + 1, j}];
   perColation[{i - 1, j}];
   perColation[{i, j + 1}];
   perColation[{i, j - 1}];
   ];

SeedRandom[seed];

Block[{a, $RecursionLimit = Infinity},
 a = RandomReal[{0, 1}, {L, L}];
 For[j = 1, j <= L, j++,
  For[i = 1, i <= L, i++,
   If[a[[i, j]] < p1,
    a[[i, j]] = 1,
    a[[i, j]] = 0
    ]]];

 a[[IntegerPart[L/2], IntegerPart[L/2]]] = 1;
 perColation[{IntegerPart[L/2], IntegerPart[L/2]}];
 ArrayPlot[Transpose[a], ImageSize -> 1000, 
  ColorRules -> {0 -> White, 1 -> White, 2 -> Red}]]
share|improve this question

1 Answer 1

The problem is with the Mesh->True Removing it works:

h = 1000;
p = 0.59;

Block[{a, $RecursionLimit = 25000, w = h},
 per[{i_, j_}] := If[1 <= i <= w && 1 <= j <= h && a[[i, j]] == 1,
   a[[i, j]] = 2;
   per[{i, j} + #] & /@ {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}
   ];

 SeedRandom[2424];

 a = Map[Boole[# < p] &, RandomReal[{0, 1}, {w, h}], {2}];

 a[[All, 1]] = a[[All, h]] = 1; Do[per[{i, 1}]; per[{i, h}], {i, w}];

 ArrayPlot[Transpose[a], ImageSize -> 1000, 
    ColorRules -> {0 -> White, 1 -> Darker[Blue], 2 -> Red}]
 ]

Mathematica graphics

From ref/Mesh it says

For ArrayPlot, Mesh->True draws mesh divisions between every cell.

And it must be that with the larger size, it failed to do this. The same problem shows up with Mesh->All.

You can either remove this options, or specify a smaller mesh value using Mesh->n.

btw, on V 9.01, with Mesh->True I do not get crash, just a gray box is displayed. No messages of any error or warning on the console. Windows 7, 16 GB RAM

share|improve this answer
    
Thanks a lot Nasser. Removing "Mesh" seems working. But I have another piece that crash again and doesn't include Mesh. I added the code into my original question. Thanks again. –  user3513537 Apr 12 at 14:07
    
@user3513537 no crash here with the new piece of code you posted. it works. Screen shot: !Mathematica graphics using V 9.01 on windows 7, 64 bit –  Nasser Apr 12 at 15:19
    
I see. It must be the memory limit. I use a mac 2.4GHz intel i5 and 8G memory. I will find another computer to run it and see what happen. Thanks! –  user3513537 Apr 12 at 18:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.