home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / program / language / bob / !ArmBob / progs / main / interpoly < prev   
Encoding:
Text File  |  1995-01-12  |  614 b   |  27 lines

  1. /* Calculate the coefficients of an
  2.    integral polynomial using Newton's
  3.    method of repeated differences */
  4.  
  5. /* Alter this by hand - a polynomial
  6.    of degree < 8 */
  7. f(x)
  8. { return ((1-x)*(1+x)); }
  9.  
  10. main()
  11. {
  12.  max = 8;
  13.  c = newvector(max);
  14.  for (i = 0; i < max; i++)
  15.   c[i] = f(i);                // get values of f at 0, 1, ...
  16.  for (i = 1; i < max; i++)
  17.   for (j = max-1; j >= i; j--)
  18.     {
  19.      c[j] -= c[j-1];         // get repeated differences
  20.      c[j] /= i;
  21.     }
  22.  for (i = max-2; i >= 0; i--)
  23.   for (j = i; j < max-1; j++)
  24.     c[j] -= i*c[j+1];        // get coefficients
  25.  print(poly2str(c,"x"),"\n");
  26. }
  27.