Exercise 1.35. Show that the golden ratio (section 1.2.2) is a fixed point of the transformation x 1 + 1/x, and use this fact to compute by means of the fixed-point procedure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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)) | |
| (define f (lambda (x) (+ 1 (/ 1 x)))) | |
| (fixed-point f 1.0) | |