-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-36.scm
59 lines (57 loc) · 1.21 KB
/
1-36.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
;加入打印功能
(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)))
(newline)
(display guess)
(if (close-enough? guess next)
next
(try next))))
(try first-guess))
;without average damping
(fixed-point (lambda (x) (/ (log 1000) (log x))) 4)
;4
;4.9828921423310435
;4.301189432497896
;4.734933901055578
;4.442378437719526
;4.632377941509958
;4.505830646780212
;4.588735606875766
;4.533824356566501
;4.56993352418142
;4.546075272637246
;4.561789745175654
;4.55141783665413
;4.5582542120702625
;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
;Value: 4.555539183677709
;with average damping
;x=(log(1000)+log(x))/2
(fixed-point (lambda (x) (/ (+ x (/ (log 1000) (log x))) 2)) 4)
;4
;4.491446071165521
;4.544974650975552
;4.553746974742814
;4.555231425802502
;4.555483906560562
;4.5555268862194875
;Value: 4.5555342036887705