![]() |
SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997 |
![]() |
#23 |
ACE
![]() Join Date: Sep 2002
Location: Kansas City
Posts: 1,274
Downloads: 60
Uploads: 0
|
![]()
Now that we have our variance, the last step is extremely easy. We simply take the square root of variance to give us the Standard Deviation value!!!
Code:
public double CalculateStandardDev(double listOfDoubles) { int sizeOfList = listOfDoubles.size(); double temporarySum = 0; for(int i=0; i<sizeOfList; i++) { temporarySum += listOfDoubles[i]; } double averageOfList = temporarySum / sizeOfList; for(int j=0; j<sizeOfList; j++) { listOfDoubles[j] = pow(listOfDoubles[j] - averageOfList, 2); } double squaredDifference = 0; double variance = 0; for(int k=0; k<sizeOfList; k++) { squaredDifference += listOfDoubles[k]; } variance = squaredDifference / sizeOfList; double standardDeviationValue = sqrt (variance ); return standardDeviationValue; } |
![]() |
![]() |
Thread Tools | |
Display Modes | |
|
|