■ 분산 구하기

----------------------------------------------------------------------------------------------------

using System;

 

#region 분산 구하기 - GetVariance(valueArray, average)

 

/// <summary>

/// 분산 구하기

/// </summary>

/// <param name="valueArray">값 배열</param>

/// <param name="average">평균</param>

/// <returns>분산</returns>

public static double GetVariance(double[] valueArray, double average)

{

    int valueCount = valueArray.Length;

 

    if(valueCount == 0)

    {

        return 0d;

    }

 

    double variance = 0d;

 

    try

    {

        for(int i = 0; i < valueCount; i++)

        {

            variance += Math.Pow(valueArray[i] - average, 2);

        }

    }

    catch(Exception)

    {

        throw;

    }

 

    return variance;

}

 

#endregion

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요