Logarithmic mean - Java Object Oriented Design

Java examples for Object Oriented Design:Method

Description

Logarithmic mean

Demo Code

public class Main {
  static double LogarithmicMean(double[] array, int i, int j) {
    if (j - i == 0)
      return array[i];
    else {//ww  w.ja v a2s  .c o m
      int n = j - i + 1;
      return (n - 1) * (LogarithmicMean(array, i + 1, j) - LogarithmicMean(array, i, j - 1))
          / (Math.log(array[j]) - Math.log(array[i]));
    }
  }

  static double LogarithmicMean(double[] array) {
    return LogarithmicMean(array, 0, array.length - 1);
  }
  
  public static void main(String[] argv) {
    double[] d = new double[] {1.2,3,4,5,6,7,8,9};
    
    double r  = LogarithmicMean(d);
    System.out.println(r);
  }
}

Result


Related Tutorials