standard deviation on double type array - Java java.lang

Java examples for java.lang:Math Algorithm

Description

standard deviation on double type array

Demo Code


//package com.java2s;

public class Main {
    public static double std_dev(double a[]) {
        double sum = 0;
        double sq_sum = 0;
        for (int i = 0; i < a.length; ++i) {
            sum += a[i];//from w w w .j av a2  s .co  m
        }
        double mean = sum / a.length;
        for (int i = 0; i < a.length; ++i) {
            sq_sum += Math.pow(a[i] - mean, 2);
        }
        sq_sum = sq_sum / (a.length);
        return Math.sqrt(sq_sum);
    }
}

Related Tutorials