• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            CG@CPPBLOG

            /*=========================================*/
            隨筆 - 76, 文章 - 39, 評論 - 137, 引用 - 0
            數據加載中……

            我的SICP習題答案(1.29~1.33)

            1.29

            (define (simpson f a b n)
              (define (get-h) (/ (- b a) n))
              (define (get-y k) (f (+ a (* k (get-h)))))
              (define (simpson-term k)
                (cond ((
            = k 0) (get-y k))
                      ((
            = k n) (get-y k))
                      ((
            = (remainder k 20) (* 2.0 (get-y k)))
                      (else (* 
            4.0 (get-y k)))))
              (define (simpson-next k) (+ k 
            1))
              (* (/ (get-h) 
            3.0) (sum simpson-term 0 simpson-next n))) 

            1.30

            (define (sum term a next b)
              (define (iter a result)
                (if (> a b)
                    result
                    (iter (next a) (+ (term a) result))))
              (iter a 
            0))

            1.31

            ;;遞歸
            (define (product-re term a next b)
              (if (> a b)
                  
            1
                  (* (term a)
                     (product-re term (next a) next b))))
            ;;迭代
            (define (product term a next b)
              (define (iter a result)
                (if (> a b)
                    result
                    (iter (next a) (* result (term a)))))
              (iter a 
            1))

            (define (pi-product b)
              (define (pi-term k) (/ (* (- k 
            1) (+ k 1)) k k))
              (define (pi-next k) (+ k 
            2))
              
            ;;(* 4.0 (product-re pi-term 3.0 pi-next b))) ;;遞歸
              (* 4.0 (product pi-term 3.0 pi-next b)))      ;;迭代


            1.32

            (define (sum term a next b)
              (accumulate + 
            0 term a next b))

            (define (product term a next b)
              (accumulate * 
            1 term a next b))

            ;;遞歸
            (define (accumulate-re combiner null-value term a next b)
              (if (> a b)
                  null-value
                  (combiner (term a)
                            (accumulate-re combiner null-value term (next a) next b))))

            ;;迭代
            (define (accumulate combiner null-value term a next b)
              (define (iter a result)
                (if (> a b)
                    result
                    (iter (next a) (combiner (term a) result))))
              (iter a null-value))

            1.33

            (define (filtered-accumulate combiner null-value term a next b filter?)
              (define (iter a result)
                (if (> a b)
                    result
                    (if (filter? (term a))
                        (iter (next a) (combiner (term a) result))
                        (iter (next a) result))))
              (iter a null-value))

            (define (sum-prime a b)
              (define (sum-prime-term k) k)
              (define (sum-prime-next k) (+ k 
            1))
              (filtered-accumulate + 
            0 sum-prime-term a sum-prime-next b prime?))

            (define (relatively-prime-product n)
              (define (relatively-prime? k) (
            = (gcd k n) 1))
              (define (term k) k)
              (define (next k) (+ k 
            1))
              (filtered-accumulate * 
            1 term 2 next (- n 1) relatively-prime?))



            posted on 2008-04-06 16:12 cuigang 閱讀(943) 評論(0)  編輯 收藏 引用 所屬分類: Lisp/Scheme我的SICP答案

            久久久久亚洲AV无码观看| 久久久久国产精品| 精品久久亚洲中文无码| 久久香蕉国产线看观看精品yw| 7777久久久国产精品消防器材| 精品免费久久久久久久| 久久久国产精华液| 97久久超碰成人精品网站| 99久久精品免费看国产免费| 国内精品久久久久影院亚洲| 久久国产成人精品麻豆| 精品久久久久久久久免费影院| 国产精品久久成人影院| 久久一本综合| 日本久久久精品中文字幕| 国产精品99久久久精品无码| 久久综合狠狠色综合伊人| 久久人人爽人人爽人人av东京热 | 四虎国产精品免费久久久| 久久精品国产清自在天天线 | 五月丁香综合激情六月久久| 色综合久久综精品| 成人妇女免费播放久久久| 久久亚洲AV无码精品色午夜麻豆 | 亚洲精品美女久久777777| 久久天天躁狠狠躁夜夜av浪潮| 91精品国产综合久久精品| 中文字幕人妻色偷偷久久| 香蕉99久久国产综合精品宅男自| 中文字幕一区二区三区久久网站| 九九精品99久久久香蕉| 久久久久久久亚洲Av无码| 国产成人精品综合久久久| 久久人人爽人人爽人人片AV高清| 中文字幕无码久久人妻| 久久久久国产精品麻豆AR影院| 狠狠人妻久久久久久综合| 久久国产美女免费观看精品 | 久久99精品久久久久久| 国产成人综合久久综合| 久久中文娱乐网|