1.35
(define golden-ratio 
    (fixed-point (lambda (x) (+ 1 (/ 1 x))) 1.0))

golden-ratio
;; 1.6180327868852458
;; 1.36

(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)))
      (display guess)
      (newline)
      (if (close-enough? guess next)
          next
          (try next))))
  (try first-guess))

(fixed-point (lambda (x) (/ (log 1000) (log x))) 4)
;; 4
;; 4.9828921423310435
;; 4.301189432497896
;; 4.734933901055578
;; 4.442378437719527
;; 4.632377941509957
;; 4.505830646780214
;; 4.588735606875765
;; 4.533824356566502
;; 4.569933524181419
;; 4.546075272637248
;; 4.561789745175653
;; 4.551417836654131
;; 4.558254212070262
;; 4.553744140202578
;; 4.556717747893265
;; 4.554756404545319
;; 4.5560497413912975
;; 4.5551967522618035
;; 4.555759257615811
;; 4.555388284933278
;; 4.555632929754932
;; 4.555471588998784
;; 4.555577989320218
;; 4.555507819903776
;; 4.555554095154945
;; 4.555523577416557
;; 4.555543703263474
;; 4.555530430629037
;; 4.555539183677709

(fixed-point (lambda (x) (average x (/ (log 1000) (log x)))) 4)
;; 4
;; 4.491446071165521
;; 4.5449746509755515
;; 4.553746974742814
;; 4.555231425802502
;; 4.555483906560562
;; 4.5555268862194875
;; 4.5555342036887705
;; 1.37
신고

티스토리 툴바