You can approximate n by using the following summation:
n=4(1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ..... + (-1)i + 1/2i - 1
Write a program that displays the n value for i = 10000, 20000, … and 100000.
Program Output:
3.1414926535900345
3.1415426535898248
3.141559320256462
3.1415676535897985
3.1415726535897814
3.141575986923102
3.141578367875482
3.1415801535897496
3.1415815424786238
3.1415826535897198
#function for finding the approximate number
def pi_approx(n):
#adding number to n variable
return 4*sum([((-1)**i)/(2*i+1) for i in range(10000)])
Comments
Leave a comment