Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (def func #(- (* % % %) 1))
- (def func' #(* 3 (* % %)))
- (def eps 1e-8)
- (defn eps-eq? [a b] (> eps (abs (- a b))))
- (defn eps-zero? [a] (eps-eq? a 0))
- (defn eps-root? [a] (eps-zero? (func a)))
- (defn n-iterations [start n]
- (reduce (fn [x _]
- (if (eps-root? x)
- (reduced x)
- (- x (/ (func x) (func' x)))))
- start
- (range n)))
Add Comment
Please, Sign In to add comment