Exercise 1.8.  Newton's method for cube roots is based on the fact that if y is an approximation to
          the cube root of x, then a better approximation is given by the value
          (x/y2+2y)/3
          Use this formula to implement a cube-root procedure analogous to the square-root procedure. (In
          section 1.3.4 we will see how to implement Newton's method in general as an abstraction of these
          square-root and cube-root procedures.)

          (define (cube x)
            (* x x x))
          (define (square x)
            (* x x ))
          (define (result x y)
           (/ (+ (/ x (square y)) (* 2 y)) 3))
          (define (improve  x guess)
            (result   x guess))
          (define (good-enough?  x guess)
            (< (abs (- (* guess guess guess ) x))0.001))
          (define (sqrt-iter x  guess)
            (if (good-enough?  x guess)
                guess
                (sqrt-iter x (improve  x guess)
                           )))
          posted on 2009-03-06 16:22 lzj520 閱讀(275) 評論(0)  編輯  收藏 所屬分類: 個人學習日記sicp
          主站蜘蛛池模板: 阳高县| 惠安县| 五常市| 宁晋县| 周宁县| 河东区| 嘉义市| 孝义市| 大悟县| 衡山县| 小金县| 陇西县| 鄯善县| 五台县| 大石桥市| 和平县| 宝丰县| 周口市| 洞口县| 长乐市| 瑞昌市| 乡宁县| 柳林县| 山丹县| 长沙县| 郓城县| 昌黎县| 罗甸县| 柏乡县| 高州市| 兴安盟| 简阳市| 台安县| 富源县| 庄河市| 富锦市| 潍坊市| 萨嘎县| 锡林浩特市| 高邑县| 龙口市|