Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

language: Scheme Code provided: (define (cubert x) (define (cube y)(* y y y)) (define (good-enough? guess x) ( < (abs (- (cube guess) x)) 0.001))

language: Scheme 

Code provided:

(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))

a. 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.

b. Using the new-if procedure as shown below. Replace the use of if in cbrt-iter with new-if. Does the new version work? Explain why or why not.

(define (new-if predicate consequent alternate) (cond (predicate consequent) (else alternate))) 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 9 For Linux UNIX And Windows Advanced Database Administration Certification Certification Study Guide

Authors: Roger E. Sanders, Dwaine R Snow

1st Edition

1583470808, 978-1583470800

More Books

Students also viewed these Databases questions

Question

What is cultural tourism and why is it growing?

Answered: 1 week ago

Question

Does it have correct contact information?

Answered: 1 week ago