Java Number Power powerMean(final double p, final double[] x)

Here you can find the source of powerMean(final double p, final double[] x)

Description

Compute the power mean of an array of doubles for a given power (p).

License

Open Source License

Parameter

Parameter Description
p Power of the mean
x Array of doubles for which to compute the power mean

Return

Power mean of input values

Declaration

public static double powerMean(final double p, final double[] x) 

Method Source Code

//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);
    }
}

Related

  1. power(long x, long y)
  2. power2(int power)
  3. powerConverter(String _varSymbol)
  4. powerLevelToDb(double value)
  5. powerLevelToDb0(double value)
  6. powerMod(long base, long exp, long mod)
  7. powerOf(final int value, final int powerOf)
  8. powerOf10(int number)
  9. powerOf2Log2(int n)