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

  1.    nalagr(n,x,f,xx,fx)
  2.  
  3.       /*this function approximates a function whose value is given  */
  4.       /*at n points on a n interval of the x axis. The interpolating*/
  5.       /*polynomial is LaGrangian.                                   */
  6.  
  7.       int n;
  8.       float x[],f[],xx,*fx;
  9.  
  10.     {
  11.       int i,j;
  12.       float p;
  13.  
  14.       *fx = 0.;
  15.       for(j = 0; j <= n-1; j++)
  16.       {
  17.        p = f[j];
  18.        for(i = 0; i <= n-1; i++)
  19.        {
  20.         if(j != i)
  21.          p *= (xx - x[i])/(x[j] - x[i]);
  22.        }
  23.        *fx += p;
  24.       }
  25.     }
  26.  
  27.