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 閱讀(276) 評(píng)論(0)  編輯  收藏 所屬分類: 個(gè)人學(xué)習(xí)日記sicp
          主站蜘蛛池模板: 华安县| 綦江县| 云龙县| 景泰县| 嘉峪关市| 犍为县| 台安县| 灌南县| 前郭尔| 梁河县| 庄浪县| 璧山县| 大竹县| 礼泉县| 万源市| 都匀市| 永善县| 德庆县| 宁德市| 平谷区| 武宣县| 化州市| 葫芦岛市| 搜索| 阿拉善右旗| 黔西县| 德安县| 区。| 宁阳县| 本溪市| 邵阳市| 白河县| 梨树县| 广水市| 玉门市| 新疆| 台南县| 建德市| 厦门市| 蕲春县| 辰溪县|