📁
SICP
  • README
  • Building Abstractions With Procedures
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
Powered by GitBook
On this page
  • 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
  • Use this formula to implement a cube-root procedure analogous to the square- root procedure. (In section Section 1.3.4 [1-3-4], page 69 we will see how to implement Newton’s method in general as an abstraction of these square-root and cube-root procedures.)

Was this helpful?

  1. Building Abstractions With Procedures

8

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+2y3\frac{x/y^2+2y}{3}3x/y2+2y​

Use this formula to implement a cube-root procedure analogous to the square- root procedure. (In section Section 1.3.4 [1-3-4], page 69 we will see how to implement Newton’s method in general as an abstraction of these square-root and cube-root procedures.)

(define (cube-root lastGuess guess x)
    (if (good-enough? lastGuess guess)
        guess
        (cube-root guess (improve-cube-root guess x) x)
)
)

(define (improve-cube-root guess x)
    (/
        (+
            (/ x (* guess guess))
            (* 2 guess)
        )
    )
    3
)

(define (good-enough? lastGuess guess)
    (< (abs (- lastGuess guess)) 0.001)
)
(cube-root 100 1 27)
Previous7Next9

Last updated 4 years ago

Was this helpful?