2 (:use [clojure.contrib test-is]
5 (defn iterative-improve [good-enough-fn? improve-guess-fn]
7 (let [new-guess (improve-guess-fn guess)]
8 (if (good-enough-fn? guess new-guess)
13 (let [initial-guess 1.0]
15 (fn [old new] (< (Math/abs (- old new)) 0.00001))
16 (fn [guess] (average guess x)))
19 (defn fixed-point [f initial-guess]
21 (fn [old new] (< (Math/abs (- old new)) 0.00001))
26 ;;=> 3.9999942779541016
28 ;;=> 3.9999942779541016
29 user> (fixed-point #(Math/cos %) 1.0)
30 ;;=> 0.7390822985224024
31 user> (fixed-point #(+ (Math/cos %) (Math/sin %)) 1.0)
32 ;;=> 1.2587315962971173