C# CSharp计算标准偏差 重复精度 和Excel中的STDEV函数相同

///
/// 计算标准偏差 重复精度
/// C# 计算标准偏差相当于Excel中的STDEV函数
/// Excel中的STDEV函数
///
///
///
public static float CSharp_STDEV(float[] SRCData) //计算标准偏差 重复精度
{

    float Sum_f= 0f;            //求和
    float AVERAGE_f = 0f;       //求平均值
    float Aariance = 0f;        //求方差
    float Result = 0f;
    int arrLength = SRCData.Length;
    for (int i = 0; i < arrLength; i++)
    {
        Sum_f += SRCData[i]; //求和
    }
    AVERAGE_f = Sum_f / arrLength;   //求平均值
    for (int j = 0; j < arrLength; j++)
    {
        Aariance += ((SRCData[j] - AVERAGE_f) * (SRCData[j] - AVERAGE_f));
    }
    Result = Convert.ToSingle(Math.Sqrt((Aariance / (arrLength - 1))).ToString());
    return Result;
}  
    /**************************************************************************************************/

float[] TestBuf = new float[] { 7.6104f, 7.6131f, 7.6131f, 7.6131f, 7.6145f, 7.6145f, 7.6131f, 7.6145f, 7.6131f, 7.6131f, 7.6145f,
7.6145f, 7.6131f, 7.6131f, 7.6131f, 7.6145f, 7.6145f, 7.6145f, 7.6131f, 7.6145f, 7.6131f, 7.6145f,
7.6131f, 7.6145f, 7.6145f, 7.6131f, 7.6145f, 7.6172f, 7.6145f, 7.6131f, 7.6145f, 7.6158f, 7.6145f,
7.6145f, 7.6145f, 7.6145f, 7.6131f, 7.6145f, 7.6131f, 7.6131f, 7.6145f, 7.6131f, 7.6131f, 7.6131f,
7.6158f, 7.6145f, 7.6131f, 7.6131f, 7.6131f, 7.6131f, 7.6131f, 7.6131f, 7.6131f, 7.6145f, 7.6145f,
7.6131f, 7.6145f, 7.6145f, 7.6145f, 7.6131f, 7.6131f, 7.6145f, 7.6131f, 7.6145f, 7.6131f, 7.6131f,
7.6131f, 7.6145f, 7.6158f, 7.6131f, 7.6145f, 7.6131f, 7.6131f, 7.6131f, 7.6145f, 7.6145f, 7.6145f,
7.6131f, 7.6145f, 7.6145f, 7.6145f, 7.6145f, 7.6145f, 7.6131f, 7.6158f, 7.6131f, 7.6131f, 7.6131f,
7.6158f, 7.6131f, 7.6145f, 7.6145f, 7.6131f, 7.6158f, 7.6145f, 7.6145f, 7.6158f, 7.6145f, 7.6145f,
7.6145f, 7.6158f, 7.6145f, 7.6131f, 7.6158f, 7.6131f, 7.6145f, 7.6131f, 7.6145f, 7.6145f, 7.6145f,
7.6145f, 7.6131f, 7.6145f, 7.6145f, 7.6131f, 7.6158f, 7.6131f, 7.6145f, 7.6145f, 7.6145f, 7.6145f,
7.6145f, 7.6145f, 7.6145f, 7.6158f, 7.6158f, 7.6158f, 7.6145f, 7.6145f, 7.6158f, 7.6145f, 7.6145f,
7.6145f, 7.6131f };
float Result_f= CSharp_STDEV(TestBuf);//计算标准偏差
MessageBox.Show(“标准差或重复精度=” + da.ToString());
C# CSharp计算标准偏差 重复精度 和Excel中的STDEV函数相同_第1张图片
C# CSharp计算标准偏差 重复精度 和Excel中的STDEV函数相同_第2张图片

你可能感兴趣的:(程序人生,内容运营,均值算法)