Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.
public static double stdev(int a[]){
double mean = 0;
int sum = 0;
//1. Work out the Mean (the simple average of the numbers)
for (int i = 0; i < a.length; i++) {
sum += a[i];
if(i == a.length -1){
mean = sum/a.length;
}
}
//2. Then for each number: subtract the Mean and square the result
//GET DIFFERENCE
double variance = 0;
double [] b = new double [a.length];
for (int i = 0; i < a.length; i++) {
//b[i] = Math.sqrt(Math.abs(a[i] - mean));
double diff = Math.abs(a[i] - mean);
b[i] = diff * diff;
}
//3. Then work out the mean of those squared differences.
for (int i = 0; i < b.length; i++) {
variance += b[i]/b.length;
}
//4. Take the square root of that and you are done!
double standardDeviation = Math.sqrt(Math.ceil(variance));
return standardDeviation;
}
double diff = a[i] - mean;
variance += b[i]/(b.length-1);
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Regular Expression Calculator Tester | 2 | 71 | |
"Black Box" Testing of Control System Software | 2 | 49 | |
hibernate example issues from command prompt | 10 | 40 | |
How to convert from xls to xlsx using java | 7 | 35 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
17 Experts available now in Live!