0 Replies - 1806 Views - Last Post: 07 April 2012 - 07:07 AM

#1 Ryano121 Reputation: 1461
• Posts: 3,289
• Joined: 30-January 11

Calculate the Geometric Mean

Posted 07 April 2012 - 07:07 AM

Description: See Example usage in snippetThe geometric mean, in mathematics, is a type of mean or average, which indicates the central tendency or typical value of a set of numbers.
public class Means
{
// Returns the geometric mean of a data set
public static double geometricMean(double[] data)
{
double sum = data;

for (int i = 1; i < data.length; i++)
{
sum *= data[i];
}

return Math.pow(sum, 1.0 / data.length);
}

public static void main(String[] args)
{
double[] x = { 2, 3, 4, 5, 6, 8, 10, 11.53542 };

System.out.println("Geometric Mean = " + Means.geometricMean(x));
}
}

// OUTPUT

// Geometric Mean = 5.343268362096718

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }