read

a.

[CODE]
; Recursive
(define (product-r term a next b)
  (if (> a b)
      1
      (* (term a) (product-r term (next a) next b))))

; Iterative
(define (product term a next b)
  (define (iter a result)
    (if (> a b)
        result
        (iter (next a) (* result (term a)))))
  (iter a 1))

; Factorial
> (product (lambda (x) x) 1 (lambda (x) (+ x 1)) 5)
120

; Approximations to phi
(define (phi-term x) (/
                      (* (* 2 x) (* 2 (+ x 1)))
                      (square (+ 1 (* 2 x)))))
(define (phi-next x) (+ x 1))
> (product phi-term 1 phi-next 20)
75557863725914323419136/95064880114531295493525
[/CODE]
4 를 곱해보면 결과가 약 3.1792124971865316373887583652071 로 근사해짐을 알 수 있다.

b.

위에 풀어놨음.

Blog Logo

Ki Sung Bae


Published

Image

Gsong's Blog

Developer + Entrepreneur = Entreveloper

Back to Overview