Wednesday, June 3, 2009

Ex-1.35

(define tolerance 0.00001)
(define (fixed-point f first-guess)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance))
(define (try guess)
(let ((next (f guess)))
(if (close-enough? guess next)
next
(try next))))
(try first-guess))

I'm denoting golden ratio by gr. Its given in section-1.2.2 that
gr2 = gr + 1
=> gr = 1 + 1/gr
so gr is fixed point of above transformation.

;compute gr
(fixed-point
(lambda (y) (+ 1 (/ 1 y)))
1.0)
;Value: 1.6180327868852458

No comments:

Post a Comment