(a) The following is an infinite product expression: 11 13 17 X 19 23 29 31 X X X X X X 8 12 12 16 20 24 28 32 ㅠ 3 4 4 = 54 1 π = 1+ 2 XX 700 In this formula, the numerators are the primes > 2, while each denominator is the multiple of 4 closest to the numerator. Write a function pi_euler1(n) which computes the value of the first n terms in the product. For example, pi_euler1 (3) should return 3.28125. (b) The next formula is an infinite sum: 1 1 1 1 1 1 1 +=+ + + + + 4 5 6 7 8 9 3 1 1 1 + + 10 11 12 1 13 In this formula, each fraction 1/n has a sign (+) determined by: the first two terms have positive signs; after that, if the denominator is a prime of the form 4m - 1 (for example, n = 3, 7, 11, ...), the sign is positive; if the denominator is a prime of the form 4m + 1 (for example, n = 5, 13, 17,...), the sign is negative; if the denominator is a composite number, then the sign is equal to the product of the signs corresponding to its factors (for example, n = 9 = 3 × 3, so its sign is positive (a positive times a positive), while n = 10 = 5 x 2, so its sign is negative (a negative times a positive)). Write a function pi_euler2(n) which computes the value of the first n terms of this expression. For example, pi_euler2 (2) should return 1.5. (c) Compute the errors for both Euler expressions, as in part 1, again for n=1 to 500. Plot a graph showing the errors for both Euler expressions, together with the errors for the previous three approximations from part 1, on the same graph. Comment briefly on the convergence of the Euler methods. (d) Recall the Monte Carlo method, from week 6 (section 6.2.2), for approximating . Suppose we choose a point (x, y) randomly (with uniform distribution) in the unit square. The probability that it lies inside a circle of diameter 1 contained in the unit square is equal to the area of that circle, or π/4. So this Monte Carlo method works as follows: (i) Generate a large number M of points (x, y) with both x and y uniformly distributed random variables in [0, 1]. You can use the module random to do this, as this module contains a function (also called random) which returns a number from the uniform distribution on [0, 1]. (ii) For each (x,y) produced, check whether it lies inside a circle of diameter 1 centred at (0.5, 0.5). Let
(a) The following is an infinite product expression: 11 13 17 X 19 23 29 31 X X X X X X 8 12 12 16 20 24 28 32 ㅠ 3 4 4 = 54 1 π = 1+ 2 XX 700 In this formula, the numerators are the primes > 2, while each denominator is the multiple of 4 closest to the numerator. Write a function pi_euler1(n) which computes the value of the first n terms in the product. For example, pi_euler1 (3) should return 3.28125. (b) The next formula is an infinite sum: 1 1 1 1 1 1 1 +=+ + + + + 4 5 6 7 8 9 3 1 1 1 + + 10 11 12 1 13 In this formula, each fraction 1/n has a sign (+) determined by: the first two terms have positive signs; after that, if the denominator is a prime of the form 4m - 1 (for example, n = 3, 7, 11, ...), the sign is positive; if the denominator is a prime of the form 4m + 1 (for example, n = 5, 13, 17,...), the sign is negative; if the denominator is a composite number, then the sign is equal to the product of the signs corresponding to its factors (for example, n = 9 = 3 × 3, so its sign is positive (a positive times a positive), while n = 10 = 5 x 2, so its sign is negative (a negative times a positive)). Write a function pi_euler2(n) which computes the value of the first n terms of this expression. For example, pi_euler2 (2) should return 1.5. (c) Compute the errors for both Euler expressions, as in part 1, again for n=1 to 500. Plot a graph showing the errors for both Euler expressions, together with the errors for the previous three approximations from part 1, on the same graph. Comment briefly on the convergence of the Euler methods. (d) Recall the Monte Carlo method, from week 6 (section 6.2.2), for approximating . Suppose we choose a point (x, y) randomly (with uniform distribution) in the unit square. The probability that it lies inside a circle of diameter 1 contained in the unit square is equal to the area of that circle, or π/4. So this Monte Carlo method works as follows: (i) Generate a large number M of points (x, y) with both x and y uniformly distributed random variables in [0, 1]. You can use the module random to do this, as this module contains a function (also called random) which returns a number from the uniform distribution on [0, 1]. (ii) For each (x,y) produced, check whether it lies inside a circle of diameter 1 centred at (0.5, 0.5). Let
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 5 steps with 5 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY