14 lines
351 B
Plaintext
14 lines
351 B
Plaintext
(def tolerance 0.00001)
|
|
(defn fixed-point [f first-guess]
|
|
(defn close-enough? [v1 v2]
|
|
(< (math/abs (- v1 v2))
|
|
tolerance))
|
|
(defn try-it [guess]
|
|
(let [next (* 0.5 (+ guess (f guess)))]
|
|
(if (close-enough? guess next)
|
|
next
|
|
(try-it next))))
|
|
(try-it first-guess))
|
|
|
|
(print (fixed-point (fn [x] (+ 1 (/ 1 x))) 1.0))
|