View Single Post
Old 10-28-14, 05:43 PM   #25
Chad
ACE
 
Join Date: Sep 2002
Location: Kansas City
Posts: 1,274
Downloads: 60
Uploads: 0
Default

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;
}
__________________
Chad is offline   Reply With Quote