Java Variance variance(double[] d)

Here you can find the source of variance(double[] d)

Description

variance

License

Open Source License

Declaration

public static double variance(double[] d) 

Method Source Code

//package com.java2s;
// License as published by the Free Software Foundation.        //

public class Main {
    public static double variance(double[] d) {
        // The variance is equal to the mean of the squares minus the square of the mean

        // Mean of squares
        double sum = 0.0;
        for (int i = 0; i < d.length; i++)
            sum += Math.pow(d[i], 2);
        double meanSquares = sum / (double) d.length;

        // Square of mean
        sum = 0.0;//from  w  w  w . j  a v a 2  s .co  m
        for (int i = 0; i < d.length; i++)
            sum += d[i];
        double squareMean = Math.pow(sum / (double) d.length, 2);

        return meanSquares - squareMean;
    }
}

Related

  1. variance(double[] a, int from, int to)
  2. variance(double[] arr)
  3. variance(double[] arr)
  4. variance(double[] array)
  5. variance(double[] array)
  6. Variance(double[] in, double mean)
  7. variance(double[] population)
  8. variance(double[] v)
  9. variance(double[] vals)