SICP习题1.36解答
Exercise 1.35: Show that the golden ratio [phi] (section Section 1.2.2 [1-2-2],
page 41) is a fixed point of the transformation x |-> 1 + 1/x, and use this fact
to compute [phi] b y means of the fixed-point procedure.
解答:
(define (fixed-point f first-guess counter)
(define (closed-enough? v1 v2)
(< (abs (- v1 v2)) 0.00001))
(let ((next (f first-guess)))
(cond ((closed-enough? next first-guess)
(display next)
(newline)
(display counter))
(else (display next)
(newline)
(fixed-point f next (+ counter 1))))))
(fixed-point (lambda (x) (/ (+ (/ (log 1000) (log x)) x) 2)) 2.0 0) ;采用了平均阻尼
(fixed-point (lambda (x) (/ (log 1000) (log x))) 2.0 0) ;没有采用平均阻尼