Here you can find the source of powerMean(final double p, final double[] x)
Parameter | Description |
---|---|
p | Power of the mean |
x | Array of doubles for which to compute the power mean |
public static double powerMean(final double p, final double[] x)
//package com.java2s; //License from project: Open Source License public class Main { /**/*www . ja v a2 s .c om*/ * Compute the power mean of an array of doubles for a given power (p). Many means are special cases of the power mean: Harmonic Mean => p * = -1, Geometric Mean => p = 0, Arithmetic Mean => p = 1, Root-Mean-Square => p = 2. * @param p Power of the mean * @param x Array of doubles for which to compute the power mean * @return Power mean of input values */ public static double powerMean(final double p, final double[] x) { double sum = 0; for (int i = 0; i < x.length; ++i) { sum += Math.pow(x[i], p); } return Math.pow(sum / x.length, 1.0 / p); } }