• 数学计算公式


            /// <summary>
            /// 求出数据平均值,并保留三位小数
            /// </summary>
            /// <param name="Valist">数据集合</param>
            /// <returns></returns>
            public static double average(List<double> Valist)
            {
                double sum = 0;
                foreach (double d in Valist)
                {
                    sum = sum + d;
                }
                double revl = System.Math.Round(sum / Valist.Count, 3);
                return revl;
            }
            /// <summary>
            /// 求数据集合标准差
            /// </summary>
            /// <param name="ValList"></param>
            /// <returns></returns>
            public static double stdev(List<double> 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);
            }
            /// <summary>
            /// 相关系数,要求两个集合数量必须相同
            /// </summary>
            /// <param name="array1">数组一</param>
            /// <param name="array2">数组二</param>
            /// <returns></returns>
            public double correl(List<double> array1, List<double> 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);
            }
    

      

  • 相关阅读:
    java NIO的基本用法
    BufferedReader源码分析
    FileInputStream读中文乱码问题
    Java使用IO流对同一个文件进行读写操作
    php表格--大数据处理
    tp5--模型关联
    tp5 -- join注意事项
    表单外部提交
    网站防止sql注入
    微信网页授权报code been used, hints: [ req_id: XYv1Ha07042046 ]
  • 原文地址:https://www.cnblogs.com/Aamir-Ye/p/4561205.html
Copyright © 2020-2023  润新知