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

  1.    autoco(a,n,l,ans)
  2.  
  3.       /* to find autocovariances of series a for lag 0 to (l - 1) */
  4.  
  5.       int l,n;
  6.       float a[],ans[];
  7.  
  8.    {
  9.       int i,j,ij,nj;
  10.       float ave,ave1,ave2,sum;
  11.  
  12.       ave = 0.;
  13.  
  14.       for(i = 0; i <= n-1; i++)
  15.        ave = ave + a[i];
  16.  
  17.       ave1 = ave/n;
  18.       ave2 = ave1 * ave1;
  19.  
  20.       for(j = 1; j <= l; j++)
  21.       {
  22.        nj = n - j + 1;
  23.        sum = 0.;
  24.  
  25.        for(i = 1; i <= nj; i++)
  26.        {
  27.         ij = i + j - 1;
  28.         sum = sum + a[i-1] * a[ij-1];
  29.        }
  30.        sum = sum / nj;
  31.        ans[j-1] = sum - ave2;
  32.       }
  33.    }
  34.  
  35.