Here you can find the source of variances(double[] data)
private static double[] variances(double[] data)
//package com.java2s; //License from project: Open Source License public class Main { private static double[] variances(double[] data) { double sum = 0; double sumsquare = 0; int len = data.length; double mean = 0; double[] variances = new double[len]; for (int i = 0; i < len; ++i) { sum += data[i];/*from w w w . j av a 2 s . c o m*/ sumsquare += data[i] * data[i]; mean = sum / (i + 1); variances[i] = sumsquare / (i + 1) - mean * mean; } return variances; } }