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
What microsoft operating systems started the process of authenticating using password and username
katovenus [111]
<span>What Microsoft operating systems started the process of authenticating using password and username? SYSTEM32!

01000110 01110101 01100011 01101011 00100000 01011001 01101111 01110101                          <===TRANLSATE ME</span>

5 0
2 years ago
Convert 234.43 (base 7) to base 10
miss Akunina [59]

Answer:

123.6326

Explanation:

Given number in base 7 : 234.43

Converting to base 10:

Each digit needs to be multiplied by 7^(position index)

Applying this for all the digits in the number:

=2* 7^2 + 3*7^1 + 4*7^0 + 4*7^-1 + 3*7^-2

=2*49 + 3*7 + 4 + 4/7+3/49

=98 + 21 + 4 + 0.5714 + 0.0612

Separating the integer and fraction parts:

=(98 + 21 + 4) + (0.5714 + 0.0612)

=123.6326

So the base 10 equivalent value for 234.43(base 7) is 123.6326

7 0
2 years ago
Write a program that displays in the title of the window the position of the mouse as the user moves the mouse around the window
12345 [234]
The java program displays these 
4 0
3 years ago
What mistake might you make related to changing the data in a cell that's used in a formula?
scoundrel [369]

Answer:

ojalat sirve

Explanation:

Cuando en una fórmula, en vez de indicar una celda, fila o columna estamos enlazando una hoja de cálculo o libro, debemos hacerlo con comilla simple. Si empleamos otro signo o símbolo separador, la fórmula no entenderá correctamente lo que le estamos indicando.

6 0
2 years ago
Match the academic requirements with the careers. Technical program , bachelors degree, doctorate degree can go with cosmetologi
Evgesh-ka [11]
Technical program - cosmetologist
Bachelors degree - nutritionist
Doctorate degree - molecular biologist
All careers are dependent on the required education for a particular career and the complexity of education to be competent.
8 0
3 years ago
Read 2 more answers
Other questions:
  • Write a program that inputs a line of text and uses a stack object to print the line reversed.
    14·1 answer
  • Your mobile device files can be synchronized using ________. hdmi a secure digital transmission a display adapter a cloud servic
    11·1 answer
  • A local area network works as a ____ network in that clusters of workstations are connected to a central point (hub or switch) t
    6·1 answer
  • The following algorithm computes the average height for a list of basketball player heights. Initialize a variable sum to 0. For
    11·2 answers
  • Find the range of the function for the domain<br>(-4,-2,0, 1.5,4).<br>f(x) = 5x²+ 4<br>​
    13·1 answer
  • What is your favorite food
    11·2 answers
  • Which is a benefit of getting information from a government website?
    15·2 answers
  • What type of photography is represented by a photograph of a dog on a beach ?
    11·1 answer
  • Can you guys help me with this coding assignments?
    10·1 answer
  • How does digital and hybrid computers differ in portability​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!