Question: Problem 4: It is known that an approximate value of the constant can be computed using the following mathematical series: (-1) 2n + 1 no

Problem 4: It is known that an approximate value of the constant can be computed using the following mathematical series: (-1)" 2n + 1 no where N is a positive integer. The tasks to be achieved in this work are as follows: 1) Write a Python script called interactiveApprox.py, which, when executed, will request from the user to enter a value for N and then will compute an approximate value of i using the above formula 2) Modify your above written code in a way to compute an approximate value of it with a tolerance of 10-6. That is, the error difference between the exact value of n and its approximate value computed using the above formula is equal to 10-6. Here, note that the upper bound of the summation (i.e. the constant N is not fixed). As such, it is required to keep on accumulating summation terms up until the tolerance of 10-6 is reached. At the end, your program should display three messages as follows. The first message should display the exact value of T. The second message should display the approximate value of Tt as computed using the above-provided formula and, finally, the third message should display the total number of terms used in the summation in order to reach the required error tolerance. 3) Modify your code in such a way to compute the approximate value of at for values of N that vary in the range [0; 100). Each time an approximate value is computed, the program will have to compute the percent relative error (i.e. the ration of the difference between the exact and approximate value of it to the exact value of this latter multiplied by 100) and print a table showing this error as a function of N. Note that the percent relative error should be rounded to only two decimal digits after the decimal point. An example output for the first four values of N is as follows: N Error 0 1 2 3 27.32% 15.12% 10.35% 7.84% N Hints: 1) In order to obtain the exact value of nt you would need to instally and import the numpy library into your code. The installation has been already done before as shown in class. In order to import this library into your code, you will need to start your code with import numpy. Then, throughout your code to extract the exact value of at using numpy, you will need to use the command numpy.pi. Just in case where, for some technical difficulties, you are not able to install the numpy package on your PC, you may use the exact value of pi as follows: pi = 3.141592653589793. 2) Assume having a floating point variable var. In order to round the printed value of var to a number of x digits after the decimal point, the print command will have to be modified as follows: print("8.xf" % var)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
