can be approximated by using the following infinite series: =4- π=4 1 1 3 5 1 1 7 9 - +..) 11 Write a program that prints out two versions of the approximation one that goes out to a denominator of 13 and one that goes out of a denominator of 15. Note you will want to use 1.0 for your numerators. In my code I used a decimal version for all of these integers.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
T can be approximated by using the following infinite series:
+-+...)
Write a program that prints out two versions of the approximation one that goes out to a
denominator of 13 and one that goes out of a denominator of 15.
T=4
1
3 5 7 9
Note you will want to use 1.0 for your numerators. In my code I used a decimal version for all of
these integers.
Transcribed Image Text:T can be approximated by using the following infinite series: +-+...) Write a program that prints out two versions of the approximation one that goes out to a denominator of 13 and one that goes out of a denominator of 15. T=4 1 3 5 7 9 Note you will want to use 1.0 for your numerators. In my code I used a decimal version for all of these integers.
Expert Solution
Step 1: Algorithm for Approximating π
  1. Start with two variables:
    • pi_approximation initialized to 0, which will store the running approximation of π.
    • sign initialized to 1, which alternates between 1 and -1 to switch the signs in the series.
  2. For each i in the range from 1 to denominator (inclusive) with a step size of 2 (to consider only odd denominators): a. Add sign * (1.0 / i) to pi_approximation. This updates the approximation according to the series formula. b. Toggle the sign by multiplying sign by -1. This alternates the sign for the next iteration.
  3. Multiply pi_approximation by 4 to obtain the final approximation of π.
  4. Return the value of 4 * pi_approximation as the result of the approximation.
  5. Calculate two approximations using this algorithm:
    • pi_approximation_13 by calling approximate_pi(denominator_13) with denominator_13 as 13.
    • pi_approximation_15 by calling approximate_pi(denominator_15) with denominator_15 as 15.
  6. Print the results with their respective denominators:
    • "Approximation with denominator 13: {pi_approximation_13}"
    • "Approximation with denominator 15: {pi_approximation_15}"

This algorithm uses a loop to calculate the approximation of π using the given infinite series formula and then prints the results for two different denominators.

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education