-
Notifications
You must be signed in to change notification settings - Fork 0
/
sol-1.36.tex
62 lines (61 loc) · 1.79 KB
/
sol-1.36.tex
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
60
61
62
Here is a modified version of `fixed-point` that displays intermediate results:
\begtt\scm
(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 next)
(newline)
(if (close-enough? guess next)
next
(try next))))
(try first-guess))
\endtt
If we apply it to the function $x \mapsto \log(1000)/\log(x)$ with an initial guess of $4$, we see the following displayed values:
\begtt\scm
(fixed-point (lambda (x) (/ (log 1000) (log x))) 4.0)
;Display: 4.9828921423310435
;Display: 4.301189432497896
;Display: 4.734933901055578
;Display: 4.442378437719526
;Display: 4.632377941509958
;Display: 4.505830646780212
;Display: 4.588735606875766
;Display: 4.533824356566501
;Display: 4.56993352418142
;Display: 4.546075272637246
;Display: 4.561789745175654
;Display: 4.55141783665413
;Display: 4.5582542120702625
;Display: 4.553744140202578
;Display: 4.556717747893265
;Display: 4.554756404545319
;Display: 4.5560497413912975
;Display: 4.5551967522618035
;Display: 4.555759257615811
;Display: 4.555388284933278
;Display: 4.555632929754932
;Display: 4.555471588998784
;Display: 4.555577989320218
;Display: 4.555507819903776
;Display: 4.555554095154945
;Display: 4.555523577416557
;Display: 4.555543703263474
;Display: 4.555530430629037
;Display: 4.555539183677709
;Value: 4.555539183677709
\endtt
Instead, with average damping we see that less steps are required:
\begtt\scm
(fixed-point (lambda (x) (average (/ (log 1000) (log x)) x)) 4.0)
;Display: 4.491446071165521
;Display: 4.544974650975552
;Display: 4.553746974742814
;Display: 4.555231425802502
;Display: 4.555483906560562
;Display: 4.5555268862194875
;Display: 4.5555342036887705
;Value: 4.5555342036887705
\endtt