Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Recall from class the definition of nuber-sum, which computes the s of the first nmbers (define (number sum n) (if (= n 0) (+
1. Recall from class the definition of nuber-sum, which computes the s of the first nmbers (define (number sum n) (if (= n 0) (+ n (number-su (- n 1)))) (a) Adapt the function to one named (even-sum n) that oomputes the sum of the first n even numbers (rb that the first even number is 0). So (even-sum 4) should return 12, (b) Evaluate your function at 1, 2, 3, 4, 5, 6, and 7. What does this sequence of umbers look (c) Adapt the function into (sum-froa-to a b) that it computes the sum of the all integers the sum of the first 4 even numbers: 0 +2+4+6.) like, and does that make sense? from a to b, so (sum-fro-to 3 5) should evaluate to 12. If a is greater that b, it should evaluate to 0 2. Write a recursive function (diff-prod k) that, given a positive integer k >1, computes the product 3(- 1-1) k-1 (Experiment with the results for some various values of k; this might suggest a spl non- recursive way to forulate this function.) 3. i=0 (a) Write a Scheme function (finite-sum-of-povers z k) that evaluates to the sum of the first k+1 terms in the above sum (that is, the sum from 0 to k). You can use Scheme'ts expt function, as (expt z n) evaluates to z (b) We will now measure how large k needs to be in the above function to provide a good approximation of the infinite sm You will write a Scheme function (terms-needed z tol) that will evaluate to thember of terms in the infinite sum needed to be within tol, that is, the smallest k such that the difference between and (finite-sum-of -povers z k) is less than tol. You can assume for this function that 0 1, computes the product 3(- 1-1) k-1 (Experiment with the results for some various values of k; this might suggest a spl non- recursive way to forulate this function.) 3. i=0 (a) Write a Scheme function (finite-sum-of-povers z k) that evaluates to the sum of the first k+1 terms in the above sum (that is, the sum from 0 to k). You can use Scheme'ts expt function, as (expt z n) evaluates to z (b) We will now measure how large k needs to be in the above function to provide a good approximation of the infinite sm You will write a Scheme function (terms-needed z tol) that will evaluate to thember of terms in the infinite sum needed to be within tol, that is, the smallest k such that the difference between and (finite-sum-of -povers z k) is less than tol. You can assume for this function that 0
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