Here you can find the source of std(double[] a)
Parameter | Description |
---|---|
a | the array. |
public static double std(double[] a)
//package com.java2s; //License from project: Apache License public class Main { /**/* www . j a v a 2 s .c o m*/ * Returns the standard variance. * * @param a the array. * @return the standard variance. */ public static double std(double[] a) { return std(a, a.length); } /** * Returns the standard variance. * * @param a the array. * @param n the total number of elements. * @return the standard variance. */ public static double std(double[] a, int n) { return Math.sqrt(variance(a, n)); } /** * Returns the variance. * * @param a the array. * @return the variance. */ public static double variance(double[] a) { return variance(a, a.length); } /** * Returns the variance. * * @param a the array. * @param n the total number of elements. * @return the variance. */ public static double variance(double[] a, int n) { double avg = mean(a, n); double sq = 0.0; for (double v : a) { double d = v - avg; sq += d * d; } return sq / (n - 1.0); } /** * Returns the mean. * * @param a the array. * @return the mean. */ public static double mean(double[] a) { return mean(a, a.length); } /** * Returns the mean. * * @param a the array. * @param n the total number of elements. * @return the mean. */ public static double mean(double[] a, int n) { double avg = 0.0; for (double v : a) { avg += v; } return avg / n; } }