Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132948 views
License: OTHER
1
type Polynom = [Double]
2
3
add :: Polynom -> Polynom -> Polynom
4
add a [] = a
5
add [] a = a
6
add (x:xs) (y:ys) = (x+y) : add xs ys
7
8
eval :: Polynom -> Double -> Double
9
eval [] x = 0
10
eval (p:ps) x = p + x * (eval ps x)
11
-- alternativ:
12
eval p x = foldr (\element rest ->element+x*rest) 0 p
13
14
deriv :: Polynom -> Polynom
15
deriv [] = []
16
deriv p = zipWith (*) [1..] (tail p)
17