Java Standard Deviation Calculate computeStddev(double[] array, double mean)

Here you can find the source of computeStddev(double[] array, double mean)

Description

Computes the standard deviation given an array and its mean value

License

Open Source License

Parameter

Parameter Description
array the array
mean the mean value of the array

Return

the standard deviation

Declaration

public static double computeStddev(double[] array, double mean) 

Method Source Code

//package com.java2s;
/*/*from www  . j  a  v a  2  s  .c om*/
 * Copyright (C) 2010-2014  Andreas Maier
 * CONRAD is developed as an Open Source project under the GNU General Public License (GPL).
*/

public class Main {
    /**
     * Computes the standard deviation given an array and its mean value
     * @param array the array
     * @param mean the mean value of the array
     * @return the standard deviation
     */
    public static double computeStddev(double[] array, double mean) {
        double stddev = 0;
        for (int i = 0; i < array.length; i++) {
            stddev += Math.pow(array[i] - mean, 2);
        }
        return Math.sqrt(stddev / array.length);
    }

    /**
     * calls Math.pow for each element of the array
     * @param array
     * @param exp the exponent.
     * @return reference to the input array
     */
    public static double[] pow(double[] array, double exp) {
        for (int i = 0; i < array.length; i++) {
            array[i] = Math.pow(array[i], exp);
        }
        return array;
    }
}

Related

  1. calcStdDeviation(double[] population)
  2. calcStdDeviation(int sampleCount, long total, long sumOfSquares)
  3. computeStdDev(double[] results, double mean)
  4. computeStddev(float[] array, float mean)