For this problem, you will write a program called PiApproximator that approximates the mathematical constant by...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
For this problem, you will write a program called PiApproximator that approximates the mathematical constant by summing a finite number of terms in a series for it. The series you will use is π = 4- 4.4 4.4 4 + 11 + 415 + ... For this problem, you will use a while loop to keep adding terms as long as the magnitude (or absolute value; for example, the magnitude of -2 is 2; there is a Python function that computes this) of the added term (including the factor of 4) is greater than 1e-6. Your program should output both 1. the approximation at that point, and 2. a count of the number of terms that have been summed in producing that approximation. Notes: We talked about this series in Lecture 7. You can copy the notebook linked here to start: https://colab.research.google.com/drive/1iQil1252K-wmEkILLAFXmPSbfd1zgAh2#scrollTo=ddBziXoNoIzH Hint: you will be changing the for loop to a while loop, using a threshold instead of , adding variables/lines to count the number of terms added, and altering the print statement to print the desired outputs First debug your program using a larger threshold (say 0.01 vs. 1e-6); see the linked PS3 FAQ for more details on this. Turn in: Cut-and-paste of your code, with the output that it produces embedded as comments at the point they are printed out in the program (just cut-and-paste the text output after your print statement(s), then either surround by or put in front of each output line). Make sure to re-run your program after inserting the indicated comments to make sure they are actually only comments and do not affect your program. For this problem, you will write a program called PiApproximator that approximates the mathematical constant by summing a finite number of terms in a series for it. The series you will use is π = 4- 4.4 4.4 4 + 11 + 415 + ... For this problem, you will use a while loop to keep adding terms as long as the magnitude (or absolute value; for example, the magnitude of -2 is 2; there is a Python function that computes this) of the added term (including the factor of 4) is greater than 1e-6. Your program should output both 1. the approximation at that point, and 2. a count of the number of terms that have been summed in producing that approximation. Notes: We talked about this series in Lecture 7. You can copy the notebook linked here to start: https://colab.research.google.com/drive/1iQil1252K-wmEkILLAFXmPSbfd1zgAh2#scrollTo=ddBziXoNoIzH Hint: you will be changing the for loop to a while loop, using a threshold instead of , adding variables/lines to count the number of terms added, and altering the print statement to print the desired outputs First debug your program using a larger threshold (say 0.01 vs. 1e-6); see the linked PS3 FAQ for more details on this. Turn in: Cut-and-paste of your code, with the output that it produces embedded as comments at the point they are printed out in the program (just cut-and-paste the text output after your print statement(s), then either surround by or put in front of each output line). Make sure to re-run your program after inserting the indicated comments to make sure they are actually only comments and do not affect your program.
Expert Answer:
Answer rating: 100% (QA)
Here is the python code to achieve the results mainpy Initialize variables approximation 0 count 0 W... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Show that if ST and g: TU are both surjective functions, then the composition gof: SU is surjective.
-
Demand function for a firm is given as P-100e, if the firm's average cost (AC) is AC 5+50, determine the firm's maximum profit. (5marks).
-
Case Type: Head case Main subjects: Harrasment, Open-Door Policy, Trust Who's Who: Paul Bello, Purchasing Manager Anisa Schumacher, Purchasing Agent Corey Widman, Bellman "May I have a confidential...
-
With only a straightedge and compass, use a number line and the Pythagorean theorem to construct a segment whose length is 2. Measure the segment as accurately as possible, and write your answer in...
-
For the frame and loading shown, determine the reactions at A, B, D, and E. Assume that the surface at each support is frictionless. 80 mm 80 mm 60 mm 60 mm 30 I kN
-
KeyCite this case: United States v. Martinez-Jimenez, 864 F.2d 664 (9th Cir. 1989), what are the citations of the 1995 and 1993 cases listed under Positive History that have a yellow flag? For...
-
Ki Corp. is in liquidation under Chapter 7 of the Federal Bankruptcy Code. The bankruptcy trustee has established a new set of books for the bankruptcy estate. After assuming custody of the estate,...
-
Refer to question 10. Suppose that the consultants fee is $5,000 and the utility function for the owner of Morley Properties can be approximated by the exponential utility function: U(x) = 1 e-x/R...
-
An aluminum wheel rubs against an aluminum plate in such a manner that there is a 51.0 N force of kinetic friction between them, and the relative speed at which the two surfaces slide over each other...
-
NIKE, Inc., with its Canadian headquarters in Thornhill, Ontario, is one of the world's lead- ing manufacturers of athletic shoes and sports apparel. The following activities occurred during a recent...
-
indicste four groups of agents who are suppliers in the loanable funds market and explain why.
-
In what ways do sophisticated feedback loops, involving hormonal, neural, and biochemical signals, orchestrate the precise balance of physiological parameters to sustain homeostasis within...
-
Can you elaborate on the intricate molecular processes governing DNA replication, repair, and recombination, highlighting the role of sophisticated enzymatic machinery, DNA proofreading mechanisms,...
-
How does the interplay between genotype and phenotype, encompassing intricate genetic regulatory networks and epigenetic modifications, contribute to the nuanced expression of traits and the...
-
How do advances in high-throughput sequencing technologies and computational genomics facilitate the comprehensive analysis of genomic landscapes, enabling researchers to decipher the genetic basis...
-
How do the intricate interplays of genotype, epigenetic modifications, and environmental factors shape the phenotypic outcomes observed in complex genetic disorders, and what implications does this...
-
Masomenos, a premier health insurer, was asked by Verycheap Inc. to provide a quote on a health insurance policy for its employees. Masomenos evaluates that Verycheap's employers' projected yearly...
-
Differentiate. y = ln(3x + 1) ln(5x + 1)
-
Compare and contrast the while and for iteration statements.
-
Explain what happens when a C# app attempts to divide one integer by another. What happens to the fractional part of the calculation? How can you avoid that outcome?
-
State whether each of the following is true or false. If false, explain why. a) The default label is required in the switch selection statement. b) The break statement is required in every case of a...
-
The simplified financial statements of two companies, P and Q, are shown in Figure 7.8. Assuming that interest is charged on the long-term loan at 10 per cent per annum, calculate the following...
-
For which sort of business might the ratio of receivables to sales be the lowest (and therefore the debtors collection period the shortest)? A. A market stall selling vegetables. B. An audit firm. C....
-
What is the return on capital employed? A. 39.0% B. 44.9% C. 48.0% D. 17.8% E. 34.0% Using the following balance sheet and income statement Balance sheet m Property 200 Trade payables Plant and...
Study smarter with the SolutionInn App