Question: Language : Scheme. Modify the algorithm in order to allow a user-defined procedure for good-enough? to be passed in as an argument and used in

Language : Scheme.

Modify the algorithm in order to allow a user-defined procedure for good-enough? to be passed in as an argument and used in the algorithm. The user-defined procedure should be passed into the outer cube-root-finding procedure. E.g. (cbrt my-good-enough1 27). Demonstrate in your test cases that you can calculate the cube root of 27 using differing 'good-enough?' functions that vary the accuracy of the result (you will need to define these various good-enough functions yourself.

(define (cubert x)

(define (cube y)(* y y y))

(define (good-enough? guess x)

(< (abs (- (cube guess) x)) 0.001))

(define (improve x y)

(/ (+ (/ x (* y y))(* 2 y)) 3))

(define (cubert-iter guess x)

(if (good-enough? guess x)

guess

(cubert-iter (improve x guess) x)))

(cubert-iter 1.0 x))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!