The following editor will bring you an articleC# Calculating the standard deviation is equivalent to the STDEVfunction example in Excel. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.
The examples are as follows:
public static float StDev(float[] arrData) //计算标准偏差 { float xSum = 0F; float xAvg = 0F; float sSum = 0F; float tmpStDev = 0F; int arrNum = arrData.Length; for (int i = 0; i < arrNum; i++) { xSum += arrData[i]; } xAvg = xSum / arrNum; for (int j = 0; j < arrNum; j++) { sSum += ((arrData[j] - xAvg) * (arrData[j] - xAvg)); } tmpStDev = Convert.ToSingle(Math.Sqrt((sSum / (arrNum - 1))).ToString()); return tmpStDev; }
The above is the detailed content of C# code example for calculating standard deviation equivalent to STDEV function in Excel. For more information, please follow other related articles on the PHP Chinese website!