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
          主站蜘蛛池模板: 保康县| 沁水县| 许昌县| 清徐县| 织金县| 东安县| 静海县| 揭阳市| 纳雍县| 北川| 巫溪县| 凉城县| 洛阳市| 鱼台县| 琼结县| 中山市| 自治县| 九江市| 太湖县| 昌平区| 白朗县| 从化市| 永寿县| 文昌市| 安丘市| 河西区| 惠州市| 新巴尔虎左旗| 青冈县| 宕昌县| 南汇区| 镇康县| 浮山县| 增城市| 墨脱县| 崇明县| 江西省| 宜春市| 武胜县| 天等县| 成都市|