C# 计算标准偏差相当于Excel中的STDEV函数实例

作者:袖梨 2022-06-25

 

 代码如下复制代码

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;

    }

 

相关文章

精彩推荐