////// 求出数据平均值,并保留三位小数 /// /// 数据集合 ///public static double average(List Valist) { double sum = 0; foreach (double d in Valist) { sum = sum + d; } double revl = System.Math.Round(sum / Valist.Count, 3); return revl; } /// /// 求数据集合标准差 /// /// ///public static double stdev(List ValList) { double avg = average(ValList); double sumstdev = 0; foreach (double d in ValList) { sumstdev = sumstdev + (d - avg) * (d - avg); } double stdeval = System.Math.Sqrt(sumstdev); return System.Math.Round(stdeval, 3); } /// /// 相关系数,要求两个集合数量必须相同 /// /// 数组一 /// 数组二 ///public double correl(List array1, List array2) { //数组一 double avg1 = average(array1); double stdev1 = stdev(array1); //数组二 double avg2 = average(array2); double stdev2 = stdev(array2); double sum = 0; for (int i = 0; i < array1.Count && i < array2.Count; i++) { sum = sum + ((array1[i] - avg1) / stdev1) * ((array2[i] - avg2) / stdev2); } return Math.Round(sum, 3); }