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)
| 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. |