read

[CODE]
(define (fixed-point f first-guess)
  (define (close-enough? v1 v2)
    (display v1)
    (newline)
    (< (abs (- v1 v2)) tolerance))
  (define (try guess)
    (let ((next (f guess)))
      (if (close-enough? guess next)
          next
          (try next))))
  (try first-guess))

(define tolerance 0.00001)
[/CODE]

> (fixed-point (lambda (x) (/ (log 1000) (log x))) 3)
3
6.287709822868153
3.757079790200296
5.218748919675315
4.180797746063314
4.828902657081293
4.386936895811029
4.671722808746095
4.481109436117821
4.605567315585735
4.522955348093164
4.577201597629606
4.541325786357399
4.564940905198754
4.549347961475409
4.5596228442307565
4.552843114094703
4.55731263660315
4.554364381825887
4.556308401465587
4.555026226620339
4.55587174038325
4.555314115211184
4.555681847896976
4.555439330395129
4.555599264136406
4.555493789937456
4.555563347820309
4.555517475527901
4.555547727376273
4.555527776815261
4.555540933824255
4.555532257016376

With average damping
[CODE]
(define (fixed-point f first-guess)
  (define (close-enough? v1 v2)
    (display v1)
    (newline)
    (< (abs (- v1 v2)) tolerance))
  (define (try guess)
    (let ((next (f guess)))
      (if (close-enough? guess next)
          next
          (try next))))
  (try first-guess))

(define tolerance 0.00001)

(define (average x y) (/ (+ x y) 2))

[/CODE]
> (fixed-point (lambda (x) (average x (/ (log 1000) (log x)))) 3)
3
4.643854911434076
4.571212264484558
4.558225323866829
4.555994244552759
4.555613793442989
4.5555490009596555
4.5555379689379265
4.55553609061889
>

Average damping 사용 시 근사 값을 훨씬 빨리 찾는 것을 알 수 있다.

Blog Logo

Ki Sung Bae


Published

Image

Gsong's Blog

Developer + Entrepreneur = Entreveloper

Back to Overview