a. An infinite continued fraction is an expression of the form
f = N₁ ------------- D₁ + N₂ ----------- D₂ + N₃ ----------- D₃ + ...
As an example, one can show that the infinite continued fraction expansion with the
all equal to 1 produces
is the golden ratio (described in section 1.2.2). One way to approximate an infinite continued fraction is to truncate the expansion after a given number of terms. Such a truncation -- a so-called
-term finite continued fraction -- has the form
N₁ --------------- D₁ + N₂ ----------- + Nk ------- Dk
are procedures of one argument (the term index
) that return the
of the terms of the continued fraction. Define a procedure
such that evaluating
(cont-frac n d k)
computes the value of the
-term finite continued fraction. Check your procedure by approximating
(cont-frac (lambda (i) 1.0) (lambda (i) 1.0) k)
or successive values of
. How large must you make
in order to get an approximation that is accurate to 4 decimal places?
b. If your
procedure generates a recursive process, write one that generates an iterative process. If it generates an iterative process, write one that generates a recursive process.
There are no comments yet.
You must log in to post a comment.Login
(define (test k) (cont-frac (lambda (i) 1.0) (lambda (i) 1.0) k)) (check-equal? (round (* 1000 (test 100))) 618.0)