home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / autopsp.zip / REGRESS / LRSET.CPP < prev    next >
C/C++ Source or Header  |  1995-07-02  |  2KB  |  95 lines

  1. // LRSet
  2. // Method definition for the LRSet class
  3.  
  4. #include "lrset.h"
  5.  
  6. LRSet::LRSet(void)
  7. {
  8.   B0=0;
  9.   B1=0;
  10. }
  11.  
  12. void LRSet::AddList(LList *ReadList)
  13. {
  14.  
  15. }
  16.  
  17. void LRSet::AddFile(char *filename)
  18. {
  19.   FILE *input;
  20.   char *next_num;
  21.   char line[80];
  22.  
  23.   double x;
  24.   double y;
  25.  
  26.   if(NULL==(input=fopen(filename,"rt"))){
  27.     printf("Unable to open requested data file.\n");
  28.     printf("Program aborts.\n");
  29.     exit(1);
  30.   }
  31.  
  32.   Restart();                    // Start at start of list.
  33.   fgets(line, 80, input);     // Read a line of input.
  34.   do{
  35.  
  36.     if (line[0]!='\n' && line[0]!=NULL){
  37.       x=atof(line);
  38.       next_num=strchr(line,' ');
  39.       y=atof(next_num);
  40.  
  41.       AddNode(x,y);
  42.     }
  43.     fgets(line, 80, input);     // Read a line of input.
  44.   } while (!feof(input));
  45.   fclose(input);
  46. }
  47.  
  48. void LRSet::AddNode(double x, double y)
  49. {
  50.   DataPoint *temp;
  51.  
  52.   Add(new DataPoint,LL_ADD_AFTER);
  53.   Next();
  54.   temp=(DataPoint*)Retrieve(LL_DATA);
  55.   temp->x=x;
  56.   temp->y=y;
  57. }
  58.  
  59. void LRSet::CalcLR(void)
  60. {
  61.   DataPoint *temp;
  62.  
  63.   double est_act_sum=0;
  64.   double est_sqrd_sum=0;
  65.   double est_sum=0;
  66.   double act_sum=0;
  67.  
  68.   double est_ave=0;
  69.   double act_ave=0;
  70.  
  71.  
  72.   Restart();                    // Start at start of list.
  73.   do{
  74.     temp=(DataPoint*)Retrieve(LL_DATA);
  75.  
  76.     est_sum+=temp->x;
  77.     act_sum+=temp->y;
  78.  
  79.     est_act_sum+=(temp->x * temp->y);
  80.     est_sqrd_sum+=(temp->x * temp->x);
  81.  
  82.     Next();
  83.                                   // Count objects until out of objects
  84.   } while (AtEnd == FALSE);
  85.  
  86.   est_ave=est_sum / NumNodes;
  87.   act_ave=act_sum / NumNodes;
  88.  
  89.   B1=est_act_sum - (NumNodes * (est_ave * act_ave));
  90.   B1/=est_sqrd_sum - (NumNodes * (est_ave * est_ave));
  91.  
  92.   B0=act_ave - (B1 * est_ave);
  93. }
  94.  
  95.