subject

Young Jeanie knows she has two parents, four grandparents, eight great grandparents, and so on. (a) Write a recursive function to compute the number of Jeanie’s ancestors in the nth previous generation. The number of ancestors in each generation back produces a sequence that may look familiar: 2,4,8,16,... For each generation back, there are twice the number of ancestors than in the previous generation back. That is, an = 2an−1. Of course, Jeanie knows she has two ancestors, her parents, one generation back. (b) ’. Specifically, (num-ancestors n) should return: 2 + 4 + 8 +···+ an Use your function in part (a) as a "helper" function in the definition of (num-ancestors n)1. 2. Perhaps you remember learning at some point that 22 7 is an approximation for π, which is an irrational number. In fact, in number theory, there is a field of study named Diophantine approximation, which deals with rational approximation of irrational numbers. (a) In 1910, Srinivasa Ramanujan, an Indian mathematician discovered several infinite series that rapidly converge to π. The series Ramanujan discovered form the basis for the fastest modern algorithms used to calculate π. One such series is
1 π
=
2√2 9801
[infinity] X k=0
(4k)!(1103 + 26390k) (k!)43964k
This series computes an additional eight decimal places of π for each term in the series. Write a Scheme function to calculate π using this series. Your function, (pi-approx k), should take k as a parameter and produce the approximation of π produced by the first k terms in the series. You may use the following skeleton to complete your solution. All you will need to add is the helper function to compute the summation defined above: (define (pi-approx k) ;Recall the definition of factorial from the lecture slides (define (factorial k) (if (= k 0) 1 1Of course, we can use the closed-form solution for the geometric progression to compute num-ancestors (ancestors(n) = 2n+1 − 2) but that doesn’t give us any experience with recursive functions. However, this is a useful fact we can use when testing our functions to ensure they are correct.
1
(* k (factorial (- k 1
;Define a helper function to compute the summation of the terms in the series (define (pi-aux k) ;Take care with the base case, k=0 is a term in the series
)
;Body of the pi-approx function (/ 1 (* (/ (* 2 (sqrt 2)) 9801) (pi-aux (- k 1
)
(b) The Pell numbers are an infinite sequence of integers which correspond to the denominators of the closest rational approximations of √2. The Pell numbers are defined by the following recurrence relation (which looks very similar to the Fibonnacci sequence): Pn =   0 if n = 0 1 if n = 1 2Pn−1 + Pn−2 otherwise Use this recurrence relation to write a recursive function, pell-num, which takes one parameter, n, and returns the nth Pell number. The numerator for the rational approximation of √2 corresponding to a particular Pell number is half of the corresponding number in the sequence referred to as the companion Pell numbers (or Pell-Lucas numbers). The companion Pell numbers are defined by the recurrence relation: Qn =   2 if n = 0 2 if n = 1 2Qn−1 + Qn−2 otherwise (c) Use this recurrence relation to write a function, named comp-pell-num, which returns the nth companion Pell number. (d) Finally write a function that uses the Pell number and companion Pell number functions to compute the nth approximation for√2. Use your new function to compute the approximation for√2 for the sixth Pell and companion Pell numbers. 3. It is an interesting fact the the square-root of any number may be expressed as a continued fraction. For example, √x = 1 + x−1 2 + x−1 2 + x−1 ... Write a Scheme function called new-sqrt which takes two formal parameters x and n, where x is the number we wish to find the square root of and n is the number of continued fractions to compute recursively. Demonstrate that for large n, new-sqrt is very close to the builtin sqrt function.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 21:40
Write c function that can replace all the positive elements to 0 and negative to 1 in undefined length one-dimensional array. test your program in the main program by defining one-dimensional array of 6 elements
Answers: 1
question
Computers and Technology, 22.06.2019 02:00
The word ‘play’ comes with many different interpretations and a variety of definitions. discuss some of the various meanings tied to the word play. why is the concept of play thought to be an important addition to the workplace? do some (brief) research online and give an example of how play in the workplace is being done right.
Answers: 2
question
Computers and Technology, 22.06.2019 06:00
Which of the following is a way that advancements in technology improve humans' ability to measure air quality and protect human health? a. air quality data gathered by new instruments can be used to reduce exposure to pollutants. b. new technologies enable natural and human-made pollution sources to be located and monitored. c. air quality data gathered by new instruments can be used to predict trends in pollution over time. d. new technologies allow governments to make informed decisions about the regulation of pollution. (choose more than one)
Answers: 2
question
Computers and Technology, 23.06.2019 01:40
You have a linux system that has a 1000gb hard disk drive, which has a 90gb partition containing an ext4 filesystem mounted to the / directory and a 4gb swap partition. currently, this linux system is only used by a few users for storing small files; however, the department manager wants to upgrade this system and use it to run a database application that will be used by 100 users. the database application and the associated data will take up over 200gb of hard disk space. in addition, these 100 users will store their personal files on the hard disk of the system. each user must have a maximum of 5gb of storage space. the department manager has made it very clear that this system must not exhibit any downtime as a result of hard disk errors. how much hard disk space will you require, and what partitions would you need to ensure that the system will perform as needed? where would these partitions be mounted? what quotas would you implement? what commands would you need to run and what entries to /etc/fstab would you need to create? justify your answers.
Answers: 3
You know the right answer?
Young Jeanie knows she has two parents, four grandparents, eight great grandparents, and so on. (a)...
Questions
question
Biology, 24.01.2020 09:31
question
Mathematics, 24.01.2020 09:31
Questions on the website: 13722363