Solution to Exercise 1.39:

`(define (cont-frac n d k)`

(define (iter i sub-expr)

(if (= i 0)

sub-expr

(iter (- i 1) (/ (n i) (+ (d i) sub-expr)))))

(iter (- k 1) (/ (n k) (d k))))

```
```

`(define (tan-cf x k)`

(let ((x-squared-negated (- (* x x))))

(cont-frac (lambda (i) (if (= i 1) x x-squared-negated))

(lambda (i) (- (* 2 i) 1))

k)))

Advertisements