I am trying to write a function to calculate the standard deviation of a vector. I thought I had done it correctly but I get a standard deviation calculation that is not exactly accurate.
so here is what I have:
double deviation (vector <int> stat, double avg)
{ double e = 0;
for (int i = 0; i < stat.size(); ++i)
{e += (stat[i]-avg)*(stat[i]-avg);
}
double v = e/stat.size();
return sqrt(v);
}
Any suggestions as to what might be wrong would be helpful!
Thank you!!!