-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpersistentwalk.java
More file actions
31 lines (30 loc) · 1.04 KB
/
persistentwalk.java
File metadata and controls
31 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.io.*;
public class persistentwalk{
public static void main(String[] args) throws FileNotFoundException {
PrintStream output = new PrintStream(new File ("persistentwalks.txt"));
int trials = 1;
int N = 500;
double[] Xaccum = new double[N+1];
double[] Xsquaredaccum = new double[N+1];
double p = .5;
for (int i = 0; i< trials; i++){
int position = 0;
for (int x = 0; x < N; x++){
double rando = Math.random();
if (rando <= p){
position--;
} else{
p = .5;
position++;
}
Xaccum[x+1] += position;
Xsquaredaccum[x+1] += Math.pow(position, 2);
}
for(int g=0; g<=N; g++){
double dummy=1.0*Xaccum[g]/N;
double dummy2=1.0*Xsquaredaccum[g]/N-dummy*dummy;
output.printf("%-6d %-10.5f %-10.5f \n",g,dummy, dummy2);
}
}
}
}