Pi Approximation – Wait Time and Polygon Signficance

After completing my post yesterday, I thought it would only take a few more lines of code to find the minimum number of sides to produce those 16 digits of pi accurately.  I wrote the lines and got frustrated with the wait time, hence I added more lines to my code to find the wait time for lower sequences of the correct pi calculation.  Currently, my computer has computed the minimum number of sides needed for the regular polygon for all digits between 2-15.  It has take a little over 2 hours.  The wait time is seemingly growing exponentially.  I’m going to post my code to calculate the wait time for a specefic amount of digits in pi in R and the code to find the wait time on your computer for approximating 16 digits of pi.  I’ll repost later with a regression curve to approximate the wait time for approximating pi with my current method.  I’m expecting to ofcourse use a log transformation.

piestimate<-function(r,m,a,d){
1->i
1->q
1->s
repeat{
inscribed.p<-s*sin(2*pi/s)/sin((pi-(2*pi)/s)/2)/2;
circumscribed.p<-s*sin(pi/s)/sin(pi/2-(pi/s));
(inscribed.p+circumscribed.p)/2->estimate;
ifelse(s==m,break,1+q->q);
ifelse(round(estimate,digits=d)==round(a,digits=d),break,1+s->s);
}
return(c(round(estimate,digits=d),s,i))
}
start.string15 <- paste(Sys.time())
piestimate(1,9999999999999999,3.1415926535897932,16)->pi15
start.string15 <- paste(Sys.time())

I haven’t had the last 3 lines start or complete currently, but I’m expecting probably 3-6 hours of run time to find the number of sides needed to accurately approximate 16 digits of pi.

Add-in:

I’m about to finish here at work, but my computer seems to be stumped on approximating more digits soon.  Here is what I have so far:

digits time(seconds) sides (regular circum. and inscr.)
2 0 28
3 0 54
4 0 76
5 1 1050
6 1 1748
7 1 5177
8 1 42805
9 5 53280
10 17 207163
11 56 704426
12 159 1911702
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s