日期:2014-05-17 浏览次数:25830 次
//求方差测试
static void Main(string[] args)
{
float[] data = { 5f, 4f, 8f, 9f };
Console.WriteLine(Vakp(data));
Console.ReadLine();
}
//求方差
static float Vakp(float[] data)
{
return data.Select(a =>(float)Math.Pow((a - GetAve(data)),2)).Sum() / data.Length;
}
//求和
static float GetSum(float[] data)
{
return data.Sum();
}
//求均值
static float GetAve(float[] data)
{
return data.Sum() / data.Length;
}
static float COVAR(float[] array1, float[] array2)
{
var sum = 0f;
var r1 = array1.Select(a => a - GetAve(array1)).ToArray();
var r2 = array2.Select(b => b - GetAve(array2)).ToArray();
for (int i = 0; i < array1.Length; i++)
{
sum += r1[i] * r2[i];
}
return sum / array1.Length;
}