Exemple #1
0
 /**
  * Constructs OscillatorsMode with the given mode and number of particles.
  *
  * <p>The particle separation is one in this model.
  *
  * @param mode int
  * @param N int
  */
 OscillatorsMode(int mode, int N) {
   amplitude = Math.sqrt(2.0 / (N + 1));
   omega = 2 * Math.sqrt(OMEGA_SQUARED) * Math.abs(Math.sin(mode * Math.PI / N / 2));
   wavenumber = Math.PI * mode / (N + 1);
   functionDrawer = new FunctionDrawer(this);
   functionDrawer.initialize(0, N + 1, 300, false); // draws the initial displacement
   functionDrawer.color = Color.LIGHT_GRAY;
 }
 /**
  * Calculates statistical values for a data array.
  *
  * @param data the data array
  * @return the max, min, mean, SD, SE and non-NaN data count
  */
 private double[] getStatistics(double[] data) {
   double max = -Double.MAX_VALUE;
   double min = Double.MAX_VALUE;
   double sum = 0.0;
   double squareSum = 0.0;
   int count = 0;
   for (int i = 0; i < data.length; i++) {
     if (Double.isNaN(data[i])) {
       continue;
     }
     count++;
     max = Math.max(max, data[i]);
     min = Math.min(min, data[i]);
     sum += data[i];
     squareSum += data[i] * data[i];
   }
   double mean = sum / count;
   double sd = count < 2 ? Double.NaN : Math.sqrt((squareSum - count * mean * mean) / (count - 1));
   if (max == -Double.MAX_VALUE) max = Double.NaN;
   if (min == Double.MAX_VALUE) min = Double.NaN;
   return new double[] {max, min, mean, sd, sd / Math.sqrt(count), count};
 }