Answered step by step
Verified Expert Solution
Question
1 Approved Answer
language = scheme (define (good-enough? guess x) ( (define (square x) ( * x x)) a. [5 marks] Newton's method for cube roots is based
language = scheme (define (good-enough? guess x) ((define (square x) ( * x x))
a. [5 marks] 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 givern by the value: (x/y2+2y)/3 Use this formula to implement a cube-root procedure analogous to the square-root procedure from the lecture notes. b. [3 marks] 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-enoughl 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 wil need to define these various good-enough functions yourself. c. [2 marks] 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))) a. [5 marks] 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 givern by the value: (x/y2+2y)/3 Use this formula to implement a cube-root procedure analogous to the square-root procedure from the lecture notes. b. [3 marks] 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-enoughl 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 wil need to define these various good-enough functions yourself. c. [2 marks] 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started