>>  <<  Ndx  Usr  Pri  JfC  LJ  Phr  Dic  Rel  Voc  !:  wd  Help  Dictionary

25. Polynomials in Terms of Roots

The product */y-r is called a polynomial in terms of the roots r, because it can also be expressed as a polynomial applied to the argument y, and because r is the list of roots or zeros of the resulting function. For example:

   */y-r [ y=: 7 [ r=: 2 3 5 [ x=: 7 6 5 4 3 2
40

   pp=: +//.@(*/)
   c=: pp/monomials=: (- ,. 1:) r
   cfr=: [: pp/ - ,. 1:            NB. Coefficients from roots
   pir=: */@(]-[)"1 0              NB. Polynomial in terms of roots

  ,.&.>(r;monomials;c;(cfr r);(c&p. y);(r pir x))
+-+----+---+---+--+--+
|2|_2 1|_30|_30|40|40|
|3|_3 1| 31| 31|  |12|
|5|_5 1|_10|_10|  | 0|
| |    |  1|  1|  |_2|
| |    |   |   |  | 0|
| |    |   |   |  | 0|
+-+----+---+---+--+--+
Since the last (highest order) coefficient produced by cfr is necessarily 1, the function pir cannot produce a general polynomial, but it can if provided with a multiplier. We therefore re-define cfr and pir to apply to a boxed list of multiplier and roots as follows:
   CFR=: (* cfr)&>/
   PIR=: CFR@[ p. ]

   CFR 3;r
_90 93 _30 3

   (3;r) PIR x
120 36 0 _6 0 0
We now illustrate the use of a polynomial in approximation:
   ]ce=: ^ t. i. 7                 NB. First seven terms of Taylor series for exponential
1 1 0.5 0.166667 0.0416667 0.00833333 0.00138889

   (^ - ce&p.) _1 _0.5 0 0.5 1     NB. Comparison with exponential
_0.000176114 _1.45834e_6 0 1.65264e_6 0.000226273

   pD ce                           NB. The exponential function equals its own derivative
1 1 0.5 0.166667 0.0416667 0.00833333



>>  <<  Ndx  Usr  Pri  JfC  LJ  Phr  Dic  Rel  Voc  !:  wd  Help  Dictionary