I'm trying to calculate the decimal places of pi with Ramanujan's formula. but with this code I'm getting the same output for all values of n, which it shouldn't. from math import sqrt, factorial as f sum=0 n=0 k=(2*sqrt(2)/9801) while n<=100000: sum=sum+((f(4*n))*(1103+(26390*n)))/(((f(n))**4)*(396**(4*n))) y=1/(k*sum) print('%.60f' % y) n=n+1 where am I doing wrong? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

I'm trying to calculate the decimal places of pi with Ramanujan's formula. but with this code I'm getting the same output for all values of n, which it shouldn't. from math import sqrt, factorial as f sum=0 n=0 k=(2*sqrt(2)/9801) while n<=100000: sum=sum+((f(4*n))*(1103+(26390*n)))/(((f(n))**4)*(396**(4*n))) y=1/(k*sum) print('%.60f' % y) n=n+1 where am I doing wrong?

17th Sep 2016, 4:33 AM
Abhishek Chauhan
Abhishek Chauhan - avatar
4 Answers
+ 1
If you look at the first two results, you'll notice that they are different. From this you can assume that after n is 2, the change in the sum is negligible. It surprised me how fast it became negligible. Each time n increases, the new result for the infinite series formula shrinks by ^8. So there is nothing wrong, just that the change gets smaller really fast. You'll need alot more than just 60 decimal places to see the change in all of those results. If you do that, you may want to increase the precision with modules that handle decimals better. Look at the Decimal module.
17th Sep 2016, 10:33 AM
Gershon Fosu
Gershon Fosu - avatar
0
ok Thanks. I'll see Decimal module. you look really mature in coding maths calculations like this. I thought I'm smart. but I was unable to find flaw in this and you did. Respect for ya👍
17th Sep 2016, 3:56 PM
Abhishek Chauhan
Abhishek Chauhan - avatar
0
hi abhishek i have something related to it please help me
19th Sep 2016, 12:35 AM
Nish Patel
Nish Patel - avatar
0
send me ur email i can send u the question
19th Sep 2016, 12:35 AM
Nish Patel
Nish Patel - avatar