Guest User

Untitled

a guest
Apr 18th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (def func #(- (* % % %) 1))
  2. (def func' #(* 3 (* % %)))
  3. (def eps 1e-8)
  4.  
  5. (defn eps-eq? [a b] (> eps (abs (- a b))))
  6. (defn eps-zero? [a] (eps-eq? a 0))
  7. (defn eps-root? [a] (eps-zero? (func a)))
  8.  
  9. (defn n-iterations [start n]
  10.   (reduce (fn [x _]
  11.             (if (eps-root? x)
  12.               (reduced x)
  13.               (- x (/ (func x) (func' x)))))
  14.           start
  15.           (range n)))
Add Comment
Please, Sign In to add comment