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

  1.    parfra(nf,cf,cg,xn,a,cfi,rem)
  2.  
  3.       /*function to express a rational algebraic fraction with the */
  4.       /*numerator of lower degree than the denominator as the      */
  5.       /*sum of component fractions whose denominators are          */
  6.       /*factors of the denominator of the original fraction        */
  7.       /*in the form                                                */
  8.       /*        f(x)/((x-xn)*g1(x)) = a/(x-xn)+f1(x)g1(x).         */
  9.  
  10.       int nf;
  11.       float cf[],cg[],xn,*a,cfi[],*rem;
  12.  
  13.     {
  14.       int i,k,m,mf;
  15.       float ax,fmag[50],fx1,gx1,xp;
  16.       double pow();
  17.  
  18.       cg[nf] = 0.;
  19.       fx1 = cf[0];
  20.       gx1 = cg[0];
  21.  
  22.       for(i = 0;i <= nf-1; i++)
  23.       {
  24.       mf = i + 1;
  25.       xp = mf;
  26.       fx1 += cf[mf]*pow(xn,xp);
  27.       gx1 += cg[mf]*pow(xn,xp);
  28.  
  29.       }
  30.       ax = fx1/gx1;
  31.  
  32.       for(i = 0;i <= nf-1; i++)
  33.         fmag[i] = cf[i] - (ax * cg[i]);
  34.  
  35.       fmag[nf] = cf[nf];
  36.       cfi[nf-1] = fmag[nf];
  37.       k = nf;
  38.       m = nf - 1;
  39.  
  40.       for(i = 0;i <= m-1; i++)
  41.       {
  42.       k = k - 1;
  43.       cfi[k-1] = cfi[k] *xn + fmag[k] ;
  44.       }
  45.       *rem = cfi[0]*xn + fmag[0];
  46.       *a = ax;
  47.    }
  48.  
  49.