Question: Need help writing this code in Scheme, Racket. Thank you! (a) Write a function (fin-alt-series k) that, given a positive integer k, returns the sum
Need help writing this code in Scheme, Racket. Thank you!

(a) Write a function (fin-alt-series k) that, given a positive integer k, returns the sum of the first k terms of the infinite series: 1 3 5 79 Observe that signs alternate in this series; one easy way to implement an alternating sign is to use the function (-1) hich is 1 when is even, and -1 when is odd. As with the problem above, you could use the built-in Scheme function (expt which returns r* (and so provides a straight forward way to compute (-1)). Depending on how you wrote your code, Scheme may have produced eract output of the form ag. To coerce Scheme to give you an approximation in decimal form, change the constant 4 in your code to 4.0 (b) Use your function to sum the first 100 terms of this series (c) Now compute the sum of the first 100,000 terms. Does this number look (roughly) familiar? (d) Consider the definition of your last function To compute the 100,000 terms, ho many calls to expt were made? What are the actual values passed to each call? (e) Revise the function you just wrote to eliminate the repeated invocations of expt. (Your function should not use expt at all but somehow compute the signs on its own.) You can introduce a helper function with more arguments if you wish! Your revised function should be named fin-alt-series-2 (a) Write a function (fin-alt-series k) that, given a positive integer k, returns the sum of the first k terms of the infinite series: 1 3 5 79 Observe that signs alternate in this series; one easy way to implement an alternating sign is to use the function (-1) hich is 1 when is even, and -1 when is odd. As with the problem above, you could use the built-in Scheme function (expt which returns r* (and so provides a straight forward way to compute (-1)). Depending on how you wrote your code, Scheme may have produced eract output of the form ag. To coerce Scheme to give you an approximation in decimal form, change the constant 4 in your code to 4.0 (b) Use your function to sum the first 100 terms of this series (c) Now compute the sum of the first 100,000 terms. Does this number look (roughly) familiar? (d) Consider the definition of your last function To compute the 100,000 terms, ho many calls to expt were made? What are the actual values passed to each call? (e) Revise the function you just wrote to eliminate the repeated invocations of expt. (Your function should not use expt at all but somehow compute the signs on its own.) You can introduce a helper function with more arguments if you wish! Your revised function should be named fin-alt-series-2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
