5 hours ago

my attempt to do the exercises in sicp.

## Monday, June 30, 2008

### sicp exercise 1.35

; 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.

(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 (phi x) (+ 1 (/ 1 x)))

(display (rationalize(fixed-point phi 1) 0.0001)) (newline)

Subscribe to:
Post Comments (Atom)

## No comments:

Post a Comment