-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsol-1.37.tex
58 lines (57 loc) · 1.35 KB
/
sol-1.37.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
\begitems\style a
* The `cont-frac` procedure can be defined as follows:
\begtt\scm
(define (cont-frac n d k)
(define (term-from j)
(if (> j k)
0
(/ (n j)
(+ (d j) (term-from (+ j 1))))))
(term-from 1))
\endtt
Then we can compute approximations of $1/\phi$:
\begtt\scm
(define (one-over-phi k)
(cont-frac (lambda (i) 1.0)
(lambda (i) 1.0)
k))
(one-over-phi 1)
;Value: 1.0
(one-over-phi 2)
;Value: 0.5
(one-over-phi 3)
;Value: 0.6666666666666666
(one-over-phi 4)
;Value: 0.6000000000000001
(one-over-phi 5)
;Value: 0.625
(one-over-phi 6)
;Value: 0.6153846153846154
(one-over-phi 7)
;Value: 0.6190476190476191
(one-over-phi 8)
;Value: 0.6176470588235294
(one-over-phi 9)
;Value: 0.6181818181818182
(one-over-phi 10)
;Value: 0.6179775280898876
(one-over-phi 11)
;Value: 0.6180555555555556
(one-over-phi 12)
;Value: 0.6180257510729613
(one-over-phi 13)
;Value: 0.6180371352785146
\endtt
We see that a value of $k=11$ is enough to have an approximation that is accurate to $4$ decimal places.
* The above defined `cont-frac` procedure generates a recursive process. Here is one that generates an iterative process:
\begtt\scm
(define (cont-frac n d k)
(define (iter j result)
(if (> j 0)
(iter (- j 1)
(/ (n j)
(+ (d j) result)))
result))
(iter k 0))
\endtt
\enditems