Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

i tried to calculate pi in python following a specific math stuff i found on wikipedia, but it outputted thats not pi

It outputted that is not pi. How to fix?
THIS IS PYTHON

import math

a_one = (23 + 4 * math.sqrt(34))
a = 1 / 2 * a_one

b_one = (19 * math.sqrt(2) + 7 * math.sqrt(17))
b = 1 / 2 * b_one

c = (429 + 304 * math.sqrt(2))

d_one = (627 + 442 * math.sqrt(2))
d = 1 / 2 * d_one


u = (a + (math.sqrt(a**2 - 1))**2) * (b + (math.sqrt(b**2 - 1))**2) * (c + (math.sqrt(c**2 - 1))**2) * (d + (math.sqrt(d**2 - 1)))


pi = (math.log((2 * u)**6 + 24) / math.sqrt(3502))

print(pi)

output=3.4829888487915346

input code and output
math stuff from wikipedia

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried chatgpt for help, it also got the wrong result.

>Solution :

There’s a few mistakes in your u.

u = (a + (math.sqrt(a**2 - 1))**2) * (b + (math.sqrt(b**2 - 1))**2) * (c + (math.sqrt(c**2 - 1))**2) * (d + (math.sqrt(d**2 - 1)))

should be

u = ((a + math.sqrt(a**2 - 1))**2) * ((b + (math.sqrt(b**2 - 1)))**2) * (c + (math.sqrt(c**2 - 1))) * (d + (math.sqrt(d**2 - 1)))

The issue is that you squared the squareroot instead of the whole part between brackets for the equation with a and b. Also, you have a square at c, which should not be there.

I tested it out and running it with the new u gives 3.141592653589793 as the answer.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading