Bending bits...

Bytes and Words...

Polynomial values in Haskell

For a polynomial p of degree N, this function returns the value:

\begin{equation} p_{0}*x^{N-1}+p_{1}*x^{N-2}+...+p_{N-2}*x+p_{N-1} \end{equation}
evalPoly::Double->[Double]->Double
evalPoly n xs=sum $ map (\e->e*n**fromIntegral ((length xs)-1-(fromJust $ elemIndex e xs))) xs

Usage:

>evalPoly 3 [-19,7,-4,6]
-456.0
>evalPoly 5 [3,0,1]
76.0