Java stddev stddev(double[] a)

Here you can find the source of stddev(double[] a)

Description

Computes the standard deviation of an array

License

Open Source License

Parameter

Parameter Description
a the array

Return

the standard deviation

Declaration

public static double stddev(double[] a) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   ww w. j a  va  2  s .com
     * Computes the standard deviation of an array
     * @param a the array
     * @return the standard deviation
     */
    public static double stddev(double[] a) {
        double std = 0;
        double ave = mean(a);

        for (double d : a)
            std += (d - ave) * (d - ave);

        return Math.sqrt(std / (double) a.length);
    }

    /**
     * computes the mean of a double array
     * @param a the array
     * @return the mean
     */
    public static double mean(double[] a) {
        double sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
        }
        return sum / (double) a.length;
    }
}

Related

  1. std(long[] array)
  2. stdarr(int[] a, double avg)
  3. stddev(Collection a)
  4. stdDev(Collection coll)
  5. stddev(double sum, double sqSum, int numberValues)
  6. stddev(double[] arr)
  7. stdDev(double[] array)
  8. stdDev(double[] data)
  9. stddev(double[] observations)