Author Topic: It's PI Day!  (Read 4102 times)

0 Members and 1 Guest are viewing this topic.

Offline Joey_21

  • 28
    • http://denebsystem.cjb.net/
Quote
Originally posted by CP5670
:wtf:

oh wait I think I know what is going on; the series is not absolutely convergent, and after some one million terms they start to oscillate between positive and negative values, so that may well be skewing the result. Try something like 50000 terms and see if that works any better.


50000 terms: -49999.30685281944
5000 terms: -4999.30685281944
500 terms: -499.30685281944

Notice any pattern? :p

Edit: 50000 + -49999.30685281944 = ln(2) :wtf:
« Last Edit: March 14, 2003, 02:07:42 pm by 34 »

 

Offline CP5670

  • Dr. Evil
  • Global Moderator
  • 212
hmm there is definitely something wrong there. Mathematica seems to be giving the right answer, but if I am reading it correctly that java function looks correct as well. The only thing I can think of now is something funny with the logarithm base...

 

Offline Joey_21

  • 28
    • http://denebsystem.cjb.net/
I did this test:

Code: [Select]

System.out.println(Math.log(2.718281828459045));


...and it returned 1.0

Another way of interpreting my loop above:

Code: [Select]

sum = 0;
i = 1;
while (i <= 9999999)
{
sum = sum + (i * Math.log(1 + 1/i) + 1/(2*i) - 1);
i = i + 1;
}

 

Offline Razor

  • 210
Quote
Originally posted by CP5670



 


Woah :eek: I understand it all.
« Last Edit: March 14, 2003, 02:20:27 pm by 581 »

 

Offline CP5670

  • Dr. Evil
  • Global Moderator
  • 212
A loss of "machine precision" maybe then? (e.g. where the log(1+1/k) gets very small and k gets very large) still, I doubt that would account for this much error. seems to work for me...

Code: [Select]
In[33]:= NSum[k Log[1+1/k]+1/(2k)-1,{k,1,Infinity}]
Out[33]= 0.3696692985404519

In[34]:= N[EulerGamma/2+1-1/2 Log[2Pi]]
Out[34]= 0.3696692992460937


Well, at any rate, I have a proof of the exact result. :D

 

Offline Joey_21

  • 28
    • http://denebsystem.cjb.net/
Hmm... what programming language is that? or is that a language?


Anyway, here's a nice infinite approximation I like...



It makes a nice graph when I do 1/that.



;7
« Last Edit: March 14, 2003, 02:33:23 pm by 34 »

 

Offline Hippo

  • Darth water-horse
  • 211
  • Grazing.
    • All Hands to War
lol, PI was the answer to a bonous question on a math test i had today... its also Einsteins birthday...
VBB Survivor -- 387 Posts -- July 3 2001 - April 12 2002
VWBB Survivor -- 100 Posts -- July 10 2002 - July 10 2004

AHTW

 

Offline CP5670

  • Dr. Evil
  • Global Moderator
  • 212
Quote
Hmm... what programming language is that? or is that a language?


I did that with Mathematica 4.2, which is a bit similar to C++ but with some different syntax and stuff.

  

Offline Joey_21

  • 28
    • http://denebsystem.cjb.net/
Stupid integer datatype!!!!! :mad: :mad:

I had 'i' defined as an integer in the code so when it was being divided by or whatever it would do integer division and just leave the whole part of the result and left the fractional portion off.

That's java for ya... :doubt:

C++ does the same thing! I probably wouldn't have ever realized this until looking over the code in good ole VB4. :thepimp:
« Last Edit: March 14, 2003, 05:29:54 pm by 34 »

 

Offline Kamikaze

  • A Complacent Wind
  • 29
    • http://www.nodewar.com
yay.. pi... 3.1415926535897932384626... I only remember that far, bah :p

Coincidental, today I finished a good math book I was reading named Godel, Escher, Bach: The Eternal Golden Braid. It's about various things like formal systems, strange loops, AI, genetics, Godel's theorem and Godel numbers ;7
Science alone of all the subjects contains within itself the lesson of the danger of belief in the infallibility of the greatest teachers in the preceding generation . . .Learn from science that you must doubt the experts. As a matter of fact, I can also define science another way: Science is the belief in the ignorance of experts. - Richard Feynman

 

Offline Sesquipedalian

  • Atankharz'ythi
  • 211
May I have a large container of coffee?  Thank you!

3.141592653

You get two extra digits for being polite.
Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

The Scroll of Atankharzim | FS2 syntax highlighting

 

Offline Sesquipedalian

  • Atankharz'ythi
  • 211
« Last Edit: March 14, 2003, 06:57:44 pm by 448 »
Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

The Scroll of Atankharzim | FS2 syntax highlighting

 

Offline Anaz

  • 210
Quote
Originally posted by Joey_21
Stupid integer datatype!!!!! :mad: :mad:

I had 'i' defined as an integer in the code so when it was being divided by or whatever it would do integer division and just leave the whole part of the result and left the fractional portion off.

That's java for ya... :doubt:

C++ does the same thing! I probably wouldn't have ever realized this until looking over the code in good ole VB4. :thepimp:


...which is why you typecast it as a float...
Arrr. I'm a pirate.

AotD, DatDB, TVWP, LM. Ph34r.

You WILL go to warpstorm...

 

Offline Joey_21

  • 28
    • http://denebsystem.cjb.net/
Quote
Originally posted by Analazon


...which is why you typecast it as a float...


I suppose... I had kinda forgotten about integer division though because I don't like to make it a part of regular calculations. :)

 

Offline CP5670

  • Dr. Evil
  • Global Moderator
  • 212
Sesq: rofl :D :D

I have 41 digits of that one. :p 3.1415926535897932384626433832795028841971

Quote
I had 'i' defined as an integer in the code so when it was being divided by or whatever it would do integer division and just leave the whole part of the result and left the fractional portion off.


Ah, that would explain it. I was really puzzled about the multiplication by 10 thing; it must have been because the sum gave 1 every time after some point, and the log(2) must have come in from the first term.

Quote

Anyway, here's a nice infinite approximation I like...




That is actually an exact value of the gamma function if you do it forever; many books I have seen initially define the function with that product. The nice thing about this is that it is one of those products obtained with the weierstrass factor theorem, which all converge for all values of the function; that's always nice... :yes:

BTW here are the graphs of three functions closely related to the gamma function; can anyone recognize what they are? ;7

« Last Edit: March 14, 2003, 09:59:34 pm by 296 »

 

Offline Sesquipedalian

  • Atankharz'ythi
  • 211
So, CP, did you intentionally name your campaign such that it would be abbreviated to pi, or was it mere deliciously fitting happenstance?
Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

The Scroll of Atankharzim | FS2 syntax highlighting

 

Offline CP5670

  • Dr. Evil
  • Global Moderator
  • 212
Actually that particular thing was just coincidence. I couldn't think of anything really good for the campaign title, so I decided to do Procyon (something) since the majority of it takes place there. I picked insurgency for the second word because just about all other synonyms for "political rebellion" were already taken by other campaigns. sorry, I'm no good with these names. :p