-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.java
65 lines (61 loc) · 1.99 KB
/
Test.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package Hair;
import java.util.*;
import java.io.*;
public class Test{
public static void main(String[] args) throws IOException {
Hair[] head = new Hair[100000]; /**sets up an array of Hair*/
double timestep = 1.0/365.0; /**timestep = 1 day*/
double simuTime = Double.parseDouble(args[0]); /**simulation time in years*/
/**simulate the head!*/
for (int i = 0; i < head.length; i++) {
head[i] = new Hair();
}
double deadCount = 0;
for (double t = 0; t < simuTime; t = t + timestep) {
for (int i = 0; i < head.length; i++) {
Hair h = head[i];
h.grow(timestep);
if (!h.isAlive()) {
head[i] = new Hair();
deadCount = deadCount + 1;
}
}
}
System.out.println("average fallen hair per day: " + deadCount/(simuTime*365));
double averageLength = 0;
for (int i = 0; i < head.length; i++) {
averageLength += head[i].getLength();
}
averageLength = averageLength/(double)head.length;
System.out.println("average length: " + averageLength);
/**FileWriter f = new FileWriter("hairlength.txt");
for (int i = 0; i < head.length; i++) {
f.write(head[i].getLength() + "\n");
}
f.close();
double[][] histo = lengthHisto(head, 1, 100);
for (int i = 0; i < histo.length; i++ ) {
System.out.println(histo[i][0] + " " + histo[i][1]);
}*/
}
public static double[][] lengthHisto(Hair[] head, double binSize, double range) {
int nBin = (int)(range/binSize);
double[][] result = new double[nBin][2];
for (int i = 0; i < nBin; i++) {
result[i][0] = (0.5 + (double)i)*binSize;
result[i][1] = 0;
}
Hair h;
for (int i = 0; i < head.length; i++) {
h = head[i];
int binToEnter = (int)(h.getLength()/binSize);
if (binToEnter <= nBin) {
result[binToEnter][1] = result[binToEnter][1] + 1.0;
}
}
for (int i = 0; i < nBin; i++) {
result[i][1] = result[i][1]/((double)head.length*binSize);
}
return result;
}
}