代码如下 | 复制代码 |
publicstaticfloatStDev(float[] arrData)//计算标准偏差 { floatxSum = 0F; floatxAvg = 0F; floatsSum = 0F; floattmpStDev = 0F; intarrNum = arrData.Length; for(inti = 0; i < arrNum; i++) { xSum += arrData[i]; } xAvg = xSum / arrNum; for(intj = 0; j < arrNum; j++) { sSum += ((arrData[j] - xAvg) * (arrData[j] - xAvg)); } tmpStDev = Convert.ToSingle(Math.Sqrt((sSum / (arrNum - 1))).ToString()); returntmpStDev; } |