1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
elena-14-01-66 [18.8K]
3 years ago
12

The mathematical constant Pi is an irrational number with value approximately 3.1415928... The precise value of this constant ca

n be obtained from the following infinite sum:
Pi^2 = 8+8/3^2+8/5^2+8/7^2+8/9^2+...
(Pi is of course just the square root of this value.)
Although we cannot compute the entire infinite series, we get a good approximation of the value of Pi' by computing the beginning of such a sum. Write a function approxPIsquared that takes as input float error and approximates constant Pi to within error by computing the above sum, term by term, until the difference between the new and the previous sum is less than error. The function should return the new sum
>>>approxPIsquared(0.0001)
9.855519952254232
>>>approxPIsquared(0.00000001)
9.869462988376474

Computers and Technology
1 answer:
tatiyna3 years ago
6 0

Answer:

I am writing a Python program:

def approxPIsquared(error):

   previous = 8

   new_sum =0

   num = 3

   while (True):

       new_sum = (previous + (8 / (num ** 2)))

       if (new_sum - previous <= error):

           return new_sum

       previous = new_sum

       num+=2    

print(approxPIsquared(0.0001))

Explanation:

I will explain the above function line by line.

def approxPIsquared(error):  

This is the function definition of approxPlsSquared() method that takes error as its parameter and approximates constant Pi to within error.

previous = 8     new_sum =0      num = 3

These are variables. According to this formula:

Pi^2 = 8+8/3^2+8/5^2+8/7^2+8/9^2+...

Value of previous is set to 8 as the first value in the above formula is 8. previous holds the value of the previous sum when the sum is taken term by term. Value of new_sum is initialized to 0 because this variable holds the new value of the sum term by term. num is set to 3 to set the number in the denominator. If you see the 2nd term in above formula 8/3^2, here num = 3. At every iteration this value is incremented by 2 to add 2 to the denominator number just as the above formula has 5, 7 and 9 in denominator.

while (True):  This while loop keeps repeating itself and calculates the sum of the series term by term, until the difference between the value of new_sum and the previous is less than error. (error value is specified as input).

new_sum = (previous + (8 / (num ** 2)))  This statement represents the above given formula. The result of the sum is stored in new_sum at every iteration. Here ** represents num to the power 2 or you can say square of value of num.

if (new_sum - previous <= error):  This if condition checks if the difference between the new and previous sum is less than error. If this condition evaluates to true then the value of new_sum is returned. Otherwise continue computing the, sum term by term.

return new_sum  returns the value of new_sum when above IF condition evaluates to true

previous = new_sum  This statement sets the computed value of new_sum to the previous.

For example if the value of error is 0.0001 and  previous= 8 and new_sum contains the sum of a new term i.e. the sum of 8+8/3^2 = 8.88888... Then IF condition checks if the

new_sum-previous <= error

8.888888 - 8 = 0.8888888

This statement does not evaluate to true because 0.8888888... is not less than or equal to 0.0001

So return new_sum statement will not execute.

previous = new_sum statement executes and now value of precious becomes 8.888888...

Next   num+=2  statement executes which adds 2 to the value of num. The value of num was 3 and now it becomes 3+2 = 5.

After this while loop execute again computing the sum of next term using       new_sum = (previous + (8 / (num ** 2)))  

new_sum = 8.888888.. + (8/(5**2)))

This process goes on until the difference between the new_sum and the previous is less than error.

screenshot of the program and its output is attached.

You might be interested in
Why does the position of drawCircle(x, y, r) in the answer choices matter?
Andrei [34K]

Answer:

B and C

Explanation:

xPos and yPos determine the center of the circle, and rad determines the radius of the circle drawn.

It cannot be A because it starts drawing a circle with the center of (4, 1). None of the circles ahve a center at (4, 1). It is B because while it does start at (4, 1), the repeat function adds one to the y and radius. While ti repeats 3 times it ends up drawing all 3 circles. C also works because it starts by drawing the biggest circle and then subtracting the values to make the other two. It cannot be D because in the repeat function it subtracts from the y value and radius too early, it doesn't draw the biggest circle.

6 0
2 years ago
The following method is intended to remove all values from the ArrayList a that have the same value as val; however, this method
Alona [7]

Answer:

ArrayList a contains [2, 3, 3, 3, 4, 5, 3, 2, 1]

Explanation:

Given

The removeValue method

Required

The content of ArrayList a, after the method is called

From the question, we understand that arraylist a is:

a= [2, 3, 4, 3, 3, 4, 4, 5, 4, 3, 2, 1]

val =4

The function fails when the value to be removed appear consecutively in the list.

4 appears in index 5 and 6 of the list. Only one of the 4's will be removed

So, the updated list will be: [2, 3, 3, 3, 4, 5, 3, 2, 1]

6 0
3 years ago
Give two reasons why cloud computing could be detrimental to a company.
dimulka [17.4K]

Security/Insider threats.

As much as cloud computing is good for your organization, just know that someone is looking after your data. The cloud provider does everything for you from maintenance to managing security. The bigger picture here is that users are entrusting their data to someone else. Although the work of cloud providers is to ensure that your data is safe, some are not always looking after your best interests.

Cyber-attacks.

Any time your data is stored on the cloud, you are at a higher risk of cyber-attack. Vulnerabilities such as DDoS attacks might occur and this single point of failure is in the cloud. As cloud computing continues to become more sophisticated, so do cyberattacks. As much as the security is right, hackers will go to any lengths to penetrate the systems.  


3 0
3 years ago
Which of the constraints listed below would be considered a physical constraint
timurjin [86]
Materials

materials are the only physical thing
8 0
2 years ago
Dell Computer uses recycled and recyclable materials in its product and packaging design in an effort to minimize damage to the
RoseWind [281]

Answer:

sustainability

Explanation:

Sustainability -

It refers to the method to meet the needs of the present generation without hampering the needs of the future generation as well , is referred to as sustainability .

The process of sustainability require to follow the concept of reuse and recycle to be safe for the environment .

The process is very safe for the planet , as it environmental friendly .

Hence , from the given scenario of the question ,

The correct answer is sustainability .

6 0
3 years ago
Other questions:
  • What lie does E.D. tell to keep the musical from being canceled? There is a television crew coming to do a story on it. Jake wil
    6·1 answer
  • Suppose your parents are planning to take you
    8·1 answer
  • What pressure will be shown on the high side peessure gauge (ac system on)
    12·1 answer
  • In the LC-3, how many memory words are used to store the string "rainbow"?
    11·1 answer
  • Write a program that has the following String variables: firstName, middleName, and lastName. Initialize these with your first,
    7·1 answer
  • Which document would most likely be written in an informal style?
    12·1 answer
  • Marys total out of pocket costbwere for the year​
    12·1 answer
  • What is the value of the variable result after these lines of code are executed?
    11·1 answer
  • Different algorithms can be made to complete the same task in different ways.
    8·2 answers
  • What steps can you take to secure your private information?.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!