pi is 4*arctangens(1) and you could use this series to evaluate it:
pi = sumof[n=0 to infinity]( 4/(2*n+1) - 4/(2*n+2))
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]
To approach this from a totally different angle, you could try the so-called Montecarlo method, based on statistical sampling.
If you inscribe a circle in a square -so that the sides of the square are tengent to the circle- then if you randomly "throw" a point inside the square, the probability that it lands inside the circle is the ratio of the areas:
(Pi * r2) / (4 * r2)
so that by sampling a large number of points the ratio of those that fall in to the total number tends to Pi / 4.
For example:
VB Code:
Randomize
'Initialize counters
Total = 0
In = 0
'Pick any large number for N
N = 10000
For i = 1 To N
x = Rnd
y = Rnd
Total = Total + 1
'Compute (squared) distance to origin
Dist2 = x*x + y*y
'Check if the point is inside (compare with radius = 1)
If Dist2 <= 1 Then In = In + 1
Next
Pi = 4 * In / Total
The shame is this method has a very slow convergence so it's not particularly useful for this calculation, but sometimes the MC method is the only possible or more convenient way to go.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
I attach an EXCEL file that I use as an introduction to simulation techniques in my classes. It is just a supplement to what Krtxmrtz (seems impossible to pronounce!) said in his last post. It might be interesting especially for those unfamiliar with simulation techniques. It is an experiment attributed to George Buffon (1707 – 1788) http://www-groups.dcs.st-and.ac.uk/~...ns/Buffon.html an ancient French scientist.
One sheet presents a fixed number of iterations depending on the number of coded cells (2,000 precisely). The other can be run for any number you might want in order to increase statistical significance, but needs additional software for this purpose (I suggest Crystal Ball – there is a link in the attached file) or you program a macro yourself for the repetitions (adapting the code given by Krtxmrtz).
Enjoy.
Rui
...este projecto dos Deuses que os homens teimam em arruinar...
What? What? It's easier than some Russian words...!
Btw, it's a very didactic and nice spreadsheet.
Last edited by krtxmrtz; Jun 9th, 2006 at 03:32 PM.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
Fiquei contente por ter gostado das minhas aplicações. Uso sempre este design em formação desde há muitos anos e os formandos gostam. É já uma rotina! Gracias.
Rui
...este projecto dos Deuses que os homens teimam em arruinar...
Fiquei contente por ter gostado das minhas aplicações. Uso sempre este design em formação desde há muitos anos e os formandos gostam. É já uma rotina! Gracias.
Rui
Tant de bo que jo hagues tingut la possibilitat d'estudiar matemàtiques d'aquesta manera quan anava a l'escola, en lloc d'haver de llegir llibres avorrits...
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)