Created
September 18, 2009 20:18
Revisions
-
jimweirich renamed this gist
Sep 18, 2009 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jimweirich revised this gist
Sep 18, 2009 . 1 changed file with 31 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,31 @@ ;; 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 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.) ;; ANSWER ------------------------------------------------------------ (define (cbrt x) (define (square x) (* x x)) ;; New improve formula for cube root. (define (improve guess x) (/ (+ (/ x (square guess)) (* 2 guess)) 3) ) ;; New good enough test for cube root. Using the relative epsilon ;; code from ex1.7. (define (good-enough? guess x) (< (abs (- guess (/ x (square guess)))) (/ guess 1000000)) ) (define (try guess) (if (good-enough? guess x) guess (try (improve guess x)))) (try 1.0)) -
jimweirich created this gist
Sep 18, 2009 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ SICP 1.8 Fork me. Solve me.