struct CPointEx
{
double x;
double y;
};
//--------------------------------------
线性拟合(最小二乘法)bool xyLineFit(CArray<CPointEx,CPointEx> &l_point, int n_point,double &a,double &b,double &r)
{
//TODO: Add your source code here
ASSERT(n_point);
double av_x,av_y;
double l_xx,l_yy,l_xy;
av_x = 0;
av_y = 0;
l_xx = 0;
l_yy = 0;
l_xy = 0;
for(int i = 0;i<n_point;i++)
{
av_x += l_point[i].x;
av_y += l_point[i].y;
}
av_x = av_x / float(n_point);
av_y = av_y/float(n_point);
for(int i = 0;i<n_point;i++)
{
l_xx += (l_point[i].x - av_x)*(l_point[i].x - av_x);
l_yy += (l_point[i].y - av_y)*(l_point[i].y - av_y);
l_xy += (l_point[i].x - av_x)*(l_point[i].y - av_y);
}
a = l_xy/l_xx;
b = av_y - l_xy*av_x/l_xx;
r = l_xy/sqrt(l_xx*l_yy);
return true;
}
------------------------------------
罗先生
--电话: 18928436628 (深圳市南山区)
--QQ: 370756740 / 117446623
--Email:
xyy0215@gmail.com
--------------------------------------
> VC/MFC工业设备控制软件开发
> Modbus/RS232/RS485串口应用开发
> 51/AVR/STM32单片机应用系统开发
> MsSQL/MySQL等数据库应用系统开发
> 开放式多轴运动控制系统开发
> 机电一体化系统集成
=======================================
君子坦荡荡,逍遥游一生... 在行走的路上,寻找幸福...