home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / NAORDR.C < prev    next >
Encoding:
Text File  |  1984-06-26  |  874 b   |  39 lines

  1.    naordr(n,f,eps,m,k)
  2.  
  3.       /*this function computes the successive differences of a function */
  4.       /*calculated at equal intervals of the argument until the         */
  5.       /*differences are essentially zero and gives the order of the     */
  6.       /*polynomial which will be fit the data.                          */
  7.  
  8.       int n,*m,*k;
  9.       float f[],eps;
  10.    {
  11.       unsigned iz;
  12.       int i,j;
  13.       float a;
  14.       double fabs();
  15.  
  16.       *k = 0;
  17.       *m = n - 1;
  18.  
  19.       for(j = 0;j <= n-2; j++)
  20.       {
  21.        iz = 1;
  22.  
  23.        for(i = 0;i <= *m; i++)
  24.        {
  25.         a = f[i + 1] - f[i];
  26.         if(f[i] != 0.0)
  27.         {
  28.          if(fabs(a/f[i]) >= eps) iz = 0;
  29.         }
  30.         f[i] = a;
  31.        }
  32.       if(iz == 1)
  33.         {*m = j -1;
  34.          return;}
  35.       *m = *m - 1;
  36.       }   /* end of j loop */
  37.       *k = 1;
  38.     }
  39.