Here you can find the source of variance(double[] a)
Parameter | Description |
---|---|
a | the array. |
public static double variance(double[] a)
//package com.java2s; //License from project: Apache License public class Main { /**/*w w w. java 2s . c o m*/ * 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; } }