<

8f81a0f09ac5 "Newton method"

(defn newton
   [f fprime tol max-iteration x]
   (if (<= max-iteration 0)
     nil
     (let [y (f x)
           yprime (fprime x)
           x-new (- x (/ y yprime))]
       (if (<= (Math/abs(- x-new x)) (* tol (Math/abs x-new)))
         x-new
         (newton f fprime tol (dec max-iteration) x-new)))))

(newton #(- (* % %) 2) #(* 2 %) 0.00000001 20 100)
;; => 1.4142135623730951