(define (fixed-point f first-guess)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance))
(define (try guess)
(display guess)
(newline)
(let ((next (f guess)))
(if (close-enough? guess next)
next
(try next))))
(try first-guess))
;solve x^x = 1000
;without average damping
(fixed-point
(lambda (y) (/ (log 1000) (log y))) 2)
;Value: 4.555532270803653
;steps taken: 34
;with average damping
; y = log(1000)/log(y)
; add y on both side and get following
; y = (log(1000)/log(y) + y)/2
(fixed-point
(lambda (y) (/ (+ y (/ (log 1000) (log y))) 2)) 2)
;Value: 4.555537551999825
;steps-taken: 9
Wednesday, June 3, 2009
Ex-1.36
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment