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)
)))
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)
)))
本文介绍了一种使用牛顿法来求解立方根的方法,并给出了具体的实现代码。该方法基于一个公式,如果y是x的立方根的一个近似值,则更好的近似值可以通过特定的计算得出。
4205

被折叠的 条评论
为什么被折叠?



