MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / geometric

Method geometric

src/main/java/com/thealgorithms/maths/Means.java:76–81  ·  view source on GitHub ↗

Computes the geometric mean of the given numbers. The geometric mean is calculated as: ⁿ√(x₁ × x₂ × ... × xₙ) Example: For numbers [2, 8], the geometric mean is √(2×8) = √16 = 4.0 Note: This method may produce unexpected results for negative numbers, as it computes the real-val

(final Iterable<Double> numbers)

Source from the content-addressed store, hash-verified

74 * Mean</a>
75 */
76 public static Double geometric(final Iterable<Double> numbers) {
77 checkIfNotEmpty(numbers);
78 double product = StreamSupport.stream(numbers.spliterator(), false).reduce(1d, (x, y) -> x * y);
79 int size = IterableUtils.size(numbers);
80 return Math.pow(product, 1.0 / size);
81 }
82
83 /**
84 * Computes the harmonic mean of the given numbers.

Calls 4

checkIfNotEmptyMethod · 0.95
streamMethod · 0.80
sizeMethod · 0.65
powMethod · 0.45