A simple calculation shows that for all Write a program in P

A simple calculation shows that for all:

Write a program in Python and show your work, justify your answer.

Solution

#-------Part 1.1------

#Finding a_n

def a_n(n):

   n=float(n)
   a_n1=(4/(8*n+1))

   a_n2=(2/(8*n+4))

   a_n3=(1/(8*n+5))

   a_n4=(1/(8*n+6))

   a_n=a_n1-a_n2-a_n3-a_n4

   return a_n ;


#Finding smallest integer N....

for N in range(10000): #since it was asked,smallest integer I have taken the range 10000

   a_N1=a_n(N)

   x=(1/15.0)*(a_N1)*(1/16.0)**N

   y=(1/2.0)*(10.0**-12)

   if(x<=y):print \"Smallest integer N=\",N;break;

#----part 1.2--------

pi_N_star=0

for i in range(N):

   pi_N_star=(pi_N_star)+(a_n(i)*(16**-i))

round(pi_N_star,2) #This will roud off the value to 2 decimal precisions-->ex:round(1.0405,2) gives 1.04

print \"Pi_N_star=\",pi_N_star

-------------------------------------------------

output:

Smallest integer N=8

pi_N_star=3.14

A simple calculation shows that for all: Write a program in Python and show your work, justify your answer.Solution#-------Part 1.1------ #Finding a_n def a_n(n

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site