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 閱讀(272) 評(píng)論(0)  編輯  收藏 所屬分類: 個(gè)人學(xué)習(xí)日記sicp
          主站蜘蛛池模板: 赞皇县| 连云港市| 潍坊市| 遂溪县| 锡林浩特市| 呼图壁县| 静海县| 周口市| 长岛县| 凤山县| 温州市| 宣汉县| 平原县| 苏尼特右旗| 黔东| 巫山县| 辽宁省| 和硕县| 连云港市| 田东县| 鹿泉市| 瓦房店市| 贞丰县| 科尔| 长春市| 公主岭市| 永兴县| 德庆县| 四会市| 黑水县| 达州市| 庆云县| 永善县| 嘉鱼县| 绵竹市| 新沂市| 和静县| 万盛区| 凌源市| 叶城县| 祁东县|