You are viewing a single comment's thread from:

RE: Computation Contest #7 [2 SBI]

in #programming5 years ago

Hi @quantumdeveloper I find this simple method based on integral calculation.
We know that the area of a circle is exactly π if the radius is 1.
And the equation of this circumference is: x^2 + y^2 = 1
So for x positive (x from 0 to 1) : y = sqrt(1-x^2)
I considered a quarter of circumference and calculate its area with an integral, then multiplied the result by 4.
20191202_175537.jpg

I made a short script on Python, here is it the code (calcola means calculate)

code.JPG

The variable n represents the number of intervals in which I divided the x asses from 0 to 1.

And here it is the calculation

ese.JPG

So with 10 milions of intervals I found π correct up to the sixth digit....not enough!!
This method is very slow...I don't recommend it for large calculation
If I find time I will try with another method. A geometrical one!
Bye bye

Sort:  

Don't forget to graph the time you actually need to get this precision.

ok sure, I changed a little bit the code ( I don't know why I make this stupid error ), defining dx as a fix number, so now it is a bit faster, but not so much. :)
And I add a function to calculate the time.
call.JPG

Now I arrived to the 7nt decimal digit correct. (below the approximation there is the time in seconds)

eses.JPG

And the "graph" is:

gra.JPG

x axis : correct digit
y axis : time

Obviously it has an exponential shape, and for sure Python is not indicate to make calculations.

That's me again :)
I made an improvement on my code, changing the method to calculate the integral.
I used the trapezoidal method, and now I got the precision to the 10nt digital digit in less time! (23 seconds)

Cattura.JPG

newes.JPG

fraphes.JPG

Now I wanna try another method.

Coin Marketplace

STEEM 0.27
TRX 0.25
JST 0.039
BTC 96923.38
ETH 3370.74
USDT 1.00
SBD 3.55