Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2341749
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:05:31

 class point
   {
   public:
   point(float xx=0,float yy=0){ X=xx; Y=yy;}
   float GetX() { return X;}
   float GetY() { return Y;}
   friend float linefit( point l_point[],int n_point);
   private:
   float X,Y;
   };
   //End of point.h
   #include
   #include
   float linefit(point l_point[],int n_point)
   {
     float av_x,av_y;
     float 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     {
      av_x+=l_point[i].X/n_point;
      av_y+=l_point[i].Y/n_point;
      }
      for(i=0;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);
       }
      cout<<"This line can be fitted by y=ax+b."<      cout<<"a="<      cout<<"b="<      return float (L_xy/sqrt(L_xx*L_yy));
      }
      void main()
      {
      point l_p[10]={ point (6,10),point(14,20),point(26,30),
      point(33,40),point(46,50),point(54,60),point(67,70),
      point(75,80),point(84,90),point(100,100) };
      float r=linefit(l_p,10);
      cout<<"Line coefficient r="<      }
      //End
编译时错!请帮我解决!


--------------------next---------------------
#include
#include
class point
{
   public:
   point(float xx=0,float yy=0){ X=xx; Y=yy;}
   float GetX() { return X;}
   float GetY() { return Y;}
   friend float linefit( point l_point[],int n_point);
   private:
   float X,Y;
};


   float linefit(point l_point[],int n_point)
   {
     float av_x,av_y;
     float 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     {
      av_x+=l_point[i].X/n_point;
      av_y+=l_point[i].Y/n_point;
      }
      for(int i=0;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);
       }
      cout<<"This line can be fitted by y=ax+b."<      cout<<"a="<      cout<<"b="<      return float (L_xy/sqrt(L_xx*L_yy));
      }
void main()
     {
      point l_p[10]={ point (6,10),point(14,20),point(26,30),
      point(33,40),point(46,50),point(54,60),point(67,70),
      point(75,80),point(84,90),point(100,100) };
      float r=linefit(l_p,10);
      cout<<"Line coefficient r="<     }


--------------------next---------------------

阅读(980) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~