home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / STEXTN.C < prev    next >
Encoding:
Text File  |  1984-08-04  |  975 b   |  46 lines

  1.       stextn (n,c,d,x,y,aa,bb,rate)
  2.  
  3.       /*this subroutine determines the intercept, slope and growth rate*/
  4.       /*of an exponential trend of the type y = aa*(c**(aa*x)).*/
  5.  
  6.       int n;
  7.       float c,d,x[],y[],*aa,*bb,*rate;
  8.  
  9.      {
  10.  
  11.       int i;
  12.       float sx,sy,sxy,sxx,fn,a,b;
  13.       extern double exp(),log(),pow();
  14.  
  15.       sx = sy = sxy = sxx = 0.;
  16.  
  17.       for (i = 0; i <= n-1; i++)
  18.       {
  19.         if (d == 0)
  20.           y[i] = log(y[i])*0.43429;
  21.         else
  22.           y[i] = log(y[i]);
  23.         sx = sx + x[i];
  24.         sy = sy + y[i];
  25.         sxy = sxy + x[i]*y[i];
  26.         sxx = sxx + x[i]*x[i];
  27.       }
  28.  
  29.       fn = n;
  30.       b = (fn*sxy - sx*sy)/(fn*sxx - sx*sx);
  31.       a = (sy*sxx - sx*sxy)/(fn*sxx - sx*sx);
  32.  
  33.       if (d ==0)
  34.       {
  35.         *aa = pow(10.,a);
  36.         *bb = b/(log(c) * 0.43429);
  37.       }
  38.       else
  39.       {
  40.         *aa = exp(a);
  41.         *bb = b/log(c);
  42.       }
  43.       *rate = pow(c,*bb) - 1.;
  44.  
  45.      }
  46.