/ Published in: Java
this simple program will calculate the SD(standard deviation) for the given input. Know more theory about standard deviation @ Standard Deviation Calculator
Expand |
Embed | Plain Text
public class StandardDeviation{ public static double mean ( double[] data ) { double mean = 0; final int n = data.length; if ( n < 2 ) for ( int i=0; i<n; i++ ) mean += data[i]; mean /= n; double sum = 0; for ( int i=0; i<n; i++ ) { final double v = data[i] - mean; sum += v * v; } } public static double sd ( double[] data ){ final int n = data.length; if ( n < 2 ) double avg = data[0]; double sum = 0; for ( int i = 1; i < data.length; i++ ) { double newavg = avg + ( data[i] - avg ) / ( i + 1 ); sum += ( data[i] - avg ) * ( data [i] -newavg ) ; avg = newavg; } } { double[] data = { 10, 100 , 50}; } }
You need to login to post a comment.
