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

Method quadratic

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

Computes the quadratic mean (root mean square) of the given numbers. The quadratic mean is calculated as: √[(x₁^2 × x₂^2 × ... × xₙ^2)/n] Example: For numbers [1, 7], the quadratic mean is √[(1^2+7^2)/2] = √25 = 5.0 @param numbers the input numbers (must not be empty) @return the

(final Iterable<Double> numbers)

Source from the content-addressed store, hash-verified

123 * Mean</a>
124 */
125 public static Double quadratic(final Iterable<Double> numbers) {
126 checkIfNotEmpty(numbers);
127 double sumOfSquares = StreamSupport.stream(numbers.spliterator(), false).reduce(0d, (x, y) -> x + y * y);
128 int size = IterableUtils.size(numbers);
129 return Math.pow(sumOfSquares / size, 0.5);
130 }
131
132 /**
133 * Validates that the input iterable is not empty.

Calls 4

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