Question

Using Javas Biglnteger / BigDouble import java.math), Python, solve the following algorithm by Ramanujan and Chudnovsky in s

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans:

Initially calculate the factorial of n:

def fact(n):
if n == 0:
return 1
else:
factorial = fact(n-1)
ans = n * factorial
return ans

Then calculate the value for pi using the below function:

def pi_value():
total = 0
i= 0
first_term = 2 * math.sqrt(2) / 9801
start = True
while start == True:
numerator = float(fact(4*i) * (1103 + 26390 * i))
denominator = float(fact(i)**4) * 396**(4*i)
final_term = first_term * float(numerator/denominator)
total =total+ final_term
i =i + 1
if final_term < 1e-15:
start == False
print("The value of pi is:" )
break
return 1 / total

print(pi_value())
------------------------------------------------------------------------------------------------------------------------------------------------------------

Output

import math Window Help Python 3.6.5 (v3.6.5:f59c0932b 4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win3 def fact

Add a comment
Know the answer?
Add Answer to:
Using Java's Biglnteger / BigDouble import java.math), Python, solve the following algorithm by Ramanujan and Chudnovsky...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please fix this code so it compiles import java.math.BigDecimal; import java.lang.Math; public class Sequence { public...

    Please fix this code so it compiles import java.math.BigDecimal; import java.lang.Math; public class Sequence { public static BigDecimal fact( int n ) { BigDecimal result = BigDecimal.ONE; while (n > 0) { result = result.multiply(new BigDecimal(n + "")); n--; } return result; } public static BigDecimal pow( BigDecimal a, int b ) { BigDecimal result = a; if(b == 0) { return BigDecimal.ONE; } while ( b > 1 ) { result = result.multiply(new BigDecimal(a + "")); b--; System.out.print("\n" +...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT