Home > Backend Development > C#.Net Tutorial > C# code example for calculating standard deviation equivalent to STDEV function in Excel

C# code example for calculating standard deviation equivalent to STDEV function in Excel

黄舟
Release: 2017-03-24 11:47:14
Original
2479 people have browsed it

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;
    }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template