• js计算散点图方程式


    //pointArrayX,pointArrayY 为两个数组,分别为x轴对应的点和y轴对应的点
    function getEquationPara(pointArrayX, pointArrayY) {
        var abr = [];
        var xavg = eval(pointArrayX.join("+")) / pointArrayX.length;
        var yavg = eval(pointArrayY.join("+")) / pointArrayY.length;
        var a, b, r;
        var xysum = 0, xxsum = 0;
        var divider = 0, dividend = 0, xxavgsum = 0, yyavgsum = 0;
        for (var i = 0; i < pointArrayX.length; i++) {
            xysum += pointArrayX[i] * pointArrayY[i];
            xxsum += pointArrayX[i] * pointArrayX[i];
            dividend += (pointArrayX[i] - xavg) * (pointArrayY[i] - yavg);
            xxavgsum += (pointArrayX[i] - xavg) * (pointArrayX[i] - xavg);
            yyavgsum += (pointArrayY[i] - yavg) * (pointArrayY[i] - yavg);
        }
        b = (xysum - pointArrayX.length * xavg * yavg) / (xxsum - (pointArrayX.length * xavg * xavg));
        a =fomatFloat(PointFloat(yavg - b * xavg,4),3);//fomatFloat--四舍六入方法,查看详细
    if (a==0) { a = "0.0"; } b = fomatFloat(b, 4); divider = fomatFloat(Math.sqrt(xxavgsum) * Math.sqrt(yyavgsum), 5); r = dividend / divider; abr.push(a); abr.push(b); abr.push(r.toString().substr(0, 6)); return abr; }

      function PointFloat(src, pos) {

         return Math.round(src * Math.pow(10, pos)) / Math.pow(10, pos);
      }

     
  • 相关阅读:
    Scrapy-02-item管道、shell、选择器
    django类视图的装饰器验证
    django禁用csrf
    django admin
    关系型数据库与非关系型数据库
    LINQ.CS
    测试
    测试
    一个测试
    WPF中的Style
  • 原文地址:https://www.cnblogs.com/zjbky/p/4991276.html
Copyright © 2020-2023  润新知