python最小二乘法线性拟合,最小二乘法求相关系数r

  python最小二乘法线性拟合,最小二乘法求相关系数r

  void fitline(consttcolgp _ array 1 of pnt 2 dthepoints,const STD 33603360 stringthefilename,

  gp_Lin2dtheLine)

  {

  math _ vector ab (1,2,0.0);

  math _ vector ax (1,2,0.0);

  math _ matrix am (1,2,1,2);

  标准_实际aSxi=0.0

  标准asyi=0.0

  标准_实际aSxx=0.0

  标准比例_ real asxy=0.0

  STD:ofstreamedrawfile(文件名);for(standard _ integer I=点数。更低);i=thePoints .上(;我)

  { const gp _ pnt 2d apoint=点。价值(I;

  asxy=apoint。x(* a点。y);

  aDrawFile vpoint p i

  }

  am (1,1)=1这些点。尺寸);

  am (1,2)=aSxi;

  am (2,1)=aSxi;

  am (2,2)=aSxx;

  ab(1)=aSyi;

  ab(2)=aSxy;

  OSD _天文钟;

  心率计。开始(;

  math _ gauss求解器(am;//math _ gaussleatsquareasolver(am;//math _ SVD求解器(am;

  asolver.solve(ab,aX);如果(作为求解器。已完成))

  {

  sandard _ realaa=ax(1;

  sandard _ realab=ax(2);

  gp_pnt2dAP1(0.0,aA);

  gp_pnt2dAP2(-aa/ab,0.0);

  这条线。设置位置(AP1

  这条线。设置方向(gp _ VEC2d)AP1,aP2).XY);

  aDrawFile vaxis l

  AP1.xAP1.y0

  AP2.xAP2.y0:endl

  STD:3360 cout ===============STD:3360 cout ===3360 endl

  ax.dump(标准:3360cout

  }

  心率计。停止(;

  心率计。显示(;

  }intmain())。

  {

  gp _ Lin2d aLine//测试数据一

  pnt 2d点1(1,6)的TCO lgp _ array1of

  apoints1.setvalue(1,gp_pnt2d ) 36.9,181.0);

  apoints1.setvalue(2,gp_pnt2d ) 46.7,197.0);

  apoints1.setvalue(3,gp_pnt2d ) 63.7,235.0);

  apoints1.setvalue(4,gp_pnt2d ) 77.8,270.0);

  apoints1.setvalue(5,gp_pnt2d ) 84.0,283.0);

  apoints1.setvalue(6,gp_pnt2d ) 87.5,292.0);

  fitline(apoints1, fit1.tcl ,aLine);//测试数据2

  pnt 2d点2(0,7)的TCO lgp _ array1of

  apoints2.setvalue(0,gp_pnt2d ) 0.0,27.0);

  apoints2.setvalue(1,gp_pnt2d ) 1.0,26.8);

  apoints2.setvalue(2,gp_pnt2d ) 2.0,26.5);

  apoints2.setvalue(3,gp_pnt2d ) 3.0,26.3);

  apoints2.setvalue(4,gp_pnt2d ) 4.0,26.1);

  apoints2.setvalue(5,gp_pnt2d ) 5.0,25.7);

  apoints2.setvalue(6,gp_pnt2d ) 6.0,25.3);

  apoints2.setvalue(7,gp_pnt2d ) 7.0,24.8);

  fitline(apoints2, fit2.tcl ,aLine);返回0;

  }

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: