]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex1_35.clj
Merge branch 'master' of github.com:vu3rdd/sicp
[sicp.git] / src / sicp / ex1_35.clj
1 ;;; show that golden ratio, phi, is a fixed point of the transformation x -> 1 + 1/x
2 ;;; and use this fact to compute phi by means of the fixed point procedure.
3
4 (ns sicp.ex1_35
5   (:use [sicp utils ch1_3]
6         [clojure.contrib test-is]))
7
8 ;;; the fixed point of the transformation x-> 1 + 1/x is the same as
9 ;;; root of x - 1 - 1/x = 0 or x^2 - x - 1 = 0
10 ;;
11 ;;; using the half-interval-method, (and knowing that phi is 1.61...)
12 (comment
13 (half-interval-method (fn [x] (- (* x x) x 1)) 1.0 2.0)
14 ;;;=>  1.61767578125
15 )
16
17 ;;; using fixed point
18 (comment
19 (fixed-point (fn [x] (+ 1 (/ 1 x))) 1.0)
20 ;;;=> 1.6180327868852458
21 )