Roots of a function: Difference between revisions

(added Haskell)
Line 361:
<lang haskell>f x = x^3-3*x^2+2*x
 
findRoots start stop step eps = doRoots start where
doRoots [x | x ><- [start, start+step .. stop], =abs [(f x) < eps]</lang>
| abs r < eps = x : doRoots (x+step)
| otherwise = doRoots (x+step)
where r = f x</lang>
Executed in GHCi:
<lang haskell>*Main> findRoots (-1.0) 3.0 0.0001 0.000000001
Anonymous user