Skip to content

Commit 0db086f

Browse files
authored
Added comment to quadratic mean
1 parent b7941ab commit 0db086f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/com/thealgorithms/maths/Means.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ public static Double harmonic(final Iterable<Double> numbers) {
107107
return size / sumOfReciprocals;
108108
}
109109

110+
/**
111+
* Computes the quadratic mean (root mean square) of the given numbers.
112+
* <p>
113+
* The quadratic mean is calculated as: √[(x₁^2 × x₂^2 × ... × xₙ^2)/n]
114+
* </p>
115+
* <p>
116+
* Example: For numbers [1, 7], the quadratic mean is √[(1^2+7^2)/2] = √25 = 5.0
117+
* </p>
118+
*
119+
* @param numbers the input numbers (must not be empty)
120+
* @return the quadratic mean of the input numbers
121+
* @throws IllegalArgumentException if the input is empty
122+
* @see <a href="https://en.wikipedia.org/wiki/Root_mean_square">Quadratic
123+
* Mean</a>
124+
*/
110125
public static Double quadratic(final Iterable<Double> numbers) {
111126
checkIfNotEmpty(numbers);
112127
double sumOfSquares = StreamSupport.stream(numbers.spliterator(), false).reduce(0d, (x, y) -> x + y * y);

0 commit comments

Comments
 (0)