Re: Horner scheme function ?
- To: mathgroup at smc.vnet.net
- Subject: [mg4539] Re: [mg4414] Horner scheme function ?
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Wed, 7 Aug 1996 04:17:45 -0400
- Sender: owner-wri-mathgroup at wolfram.com
kraft at emma.bauwesen.uni-dortmund.de (Manfred Krafczyk) [mg4414] Horner scheme function ? writes >does anybody know where I can find a Mathematica >function that returns the Horner representation > of a polynomial ... ? Manfred: HornerForm::usage = "HornerForm[poly,x] give the HornerForm for the polynomial poly in x"] HornerForm[poly_,x_] := Fold[(#1 x + #2 )&,0, Reverse[CoefficientList[poly,x]]] Check: p[x_] = Sum[ Random[Integer,{-9,9}] x^n, {n,0,5}] 2 3 4 5 -5 - 9 x - x + 4 x - 7 x - 8 x HornerForm[p[x],x] -5 + x (-9 + x (-1 + x (4 + (-7 - 8 x) x))) HornerForm[x^3 + x^4,x] 3 x (1 + x) Allan Hayes hay at haystack.demon.co.uk ==== [MESSAGE SEPARATOR] ====