连分数

连分数是指形式如$f=\frac{N_1}{D_1+\frac{N_2}{D_2+\frac{N_3}{D3+\cdots}}}$

给定的参数是2个procedure,用来返回$N_i$和$D_i$

(define (cont-frac-iter n d k)
  (define (cont-frac-iter-in s n d k)
    (define new-s (/ (n k) (+ (d k) s)))
    (if (= k 1)
      new-s
      (cont-frac-iter-in new-s n d (- k 1))))
  (cont-frac-iter-in 0 n d k))

使用的思想是迭代

posted on 2012-09-14 21:29  mathlover  阅读(185)  评论(0编辑  收藏  举报

导航