fbitonti
Registered: Oct 2007
Posts: 3 |
how does this work?
Hello, I apologize if this isn't the correct forum for this kind of question but I hope someone will be able to help me. I am writing a java program that will let me do CA simulations I am in the process of validating the results against Mathematica and i noticed that my results are not quite the same. this is my Mathematica output.
x = CellularAutomaton[110, {0, 0, 0, 1, 0, 0, 0, 0}, 5];
MatrixForm[x]
{"0", "0", "0", "1", "0", "0", "0", "0"},
{"0", "0", "1", "1", "0", "0", "0", "0"},
{"0", "1", "1", "1", "0", "0", "0", "0"},
{"1", "1", "0", "1", "0", "0", "0", "0"},
{"1", "1", "1", "1", "0", "0", "0", "1"},
{"0", "0", "0", "1", "0", "0", "1", "1"}
however the output from my java debugger looks nothing like this.
this is my java code
public static int[] newMatrix;
public static int xc;
public static int jc;
public static int check;
public static int masterCount;
public static cellularAutomata calcCA( cellularAutomata x,int evolun) {
rows = x.sizeCA();
if(newMatrix==null)
{
newMatrix = new int[rows];
}
int caLOOP = 0;
xc = 0;
jc = 0;
while (xc < evolun){
jc = 0;
masterCount = 0;
//print($x);
while(jc < x.sizeCA()-1){
check = jc - 1;
if(check < 0){
check = 0;
}
if(x.getNumber(check) == 1 && x.getNumber(jc+1) == 1 && x.getNumber(jc) == 1){
newMatrix[jc] = i;
// x.setValue(jc,i);
}
if(x.getNumber(check) == 1 && x.getNumber(jc+1) == 0 && x.getNumber(jc) == 1){
newMatrix[jc] = j;
// x.setValue(jc,j);
}
if(x.getNumber(check) == 1 && x.getNumber(jc+1) == 1 && x.getNumber(jc) == 0){
newMatrix[jc] = k;
// x.setValue(jc,k);
}
if(x.getNumber(check) == 1 && x.getNumber(jc+1) == 0 && x.getNumber(jc) == 0){
newMatrix[jc] = l;
// x.setValue(jc,l);
}
if(x.getNumber(check) == 1 && x.getNumber(jc+1) == 0 && x.getNumber(jc) == 1){
newMatrix[jc] = m;
// x.setValue(jc,m);
}
if(x.getNumber(check) == 0 && x.getNumber(jc+1) == 0 && x.getNumber(jc) == 1){
newMatrix[jc] = n;
// x.setValue(jc,n);
}
if(x.getNumber(check) == 0 && x.getNumber(jc+1) == 1 && x.getNumber(jc) == 0){
newMatrix[jc] = o;
// x.setValue(jc,o);
}
if(x.getNumber(check) == 0 && x.getNumber(jc+1) == 0 && x.getNumber(jc) == 0){
newMatrix[jc] = p;
// x.setValue(jc,p);
}
jc= jc + 1;
}
xc = xc + 1;
jc = 0;
while(caLOOP < x.sizeCA()-1){
x.setValue(caLOOP,newMatrix[caLOOP]);
caLOOP = caLOOP + 1;
}
caLOOP = 0;
}
return new cellularAutomata(newMatrix);
}
if anyone can tell me where i went wrong I would appreciate it. I think it has something to o with how I treat the edges of the matrix because I only want to calculate for the width of the initial conditions. because the first three lines are always correct.
Report this post to a moderator | IP: Logged
|