Addition of product and geometericMean.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@140919 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark R. Diggory 2003-06-17 23:23:07 +00:00
parent 175c7c5fce
commit d4f6a5c818
1 changed files with 26 additions and 0 deletions

View File

@ -89,6 +89,32 @@ public class StatUtils {
}
/**
* Returns the product for this collection of values
* @param values Is a double[] containing the values
* @return the product values or Double.NaN if the array is empty
*/
public static double product(double[] values) {
double product = Double.NaN;
if( values.length > 0 ) {
product = 1.0;
for( int i = 0; i < values.length; i++) {
product *= values[i];
}
}
return product;
}
/**
* Returns the geometric mean for this collection of values
* @param values Is a double[] containing the values
* @return the geometric mean or Double.NaN if the array is empty or
* any of the values are &lt;= 0.
*/
public static double geometricMean(double[] values) {
return Math.pow(product(values),(1.0/values.length));
}
/**
* Returns the <a href=http://www.xycoon.com/arithmetic_mean.htm>
* arithmetic mean </a> of the available values
* @param values Is a double[] containing the values