Imprimir

# A method to calculate Pi using Pythagoras' theorem: one solution for HP41c Last week we put forward a quiz: how to calculate Pi with a calculator. The initial proposition was to prepare a program for HP Prime. I gave as alternative the possibility to create it for other HP calculator; how can it be more appropriated than the HP41c family? As it has been a long time since I last used some modules, I preferred to use only standard operations - not the solve application of the Advantage pack.

As stated, I used the polygon circumscribed in the circumference, doubling each time the number of sides. This method will approach pi “from below”, being its limit when the number of iterations tend to infinite. An alternative solution, that we’ll use in a further installment, will use the “outside” polygon, which will approach the solution “from above”.

The program first find the first polygon side (a square) through a rough Pythagoras’ theorem: given r = ½ of diameter (d), then the side is l12 = r2+r2 = 2r2 => l1 = r*sqrt(2),

From there, if you see the picture, the next polygon side can be calculated as the hypothenuse of a triangle with a side that is half of the previous side, and the other, the difference between the radius and the side of another triangle, this one with the previous half-side and the radius as hypothenuse. This is easier than it sounds:

l(i+1) =sqrt((li/2)^2+(r-sqrt(r2-(li/2)2))^2)

note that (li/2)^2 appears twice - the only clever thing of this program will be to calculate it only once per iteration, and use the stack to keep the other copy. Well, another one-key saving is based on the fact that the square of (li/2)^2-r2 (what we can calculate without exchanging x and y) is equal to the square of r2-(li/2)2.

The program for HP41c is besides (please notice the beautiful printout generated in my iPad's i41cx+ program). I have ointroduced a stop at the beginning of each loop, so that you can see on screen the value at each iteration. From iteration 15, you're only adding rounding errors: the sucession crosses the value of pi and actually diverges! :

Do you dare to attack the “outside polygon” approach? Comentarios: 0
Más sobre:

Solo los usuarios registrados pueden poner comentarios. Identificarse y añadir comentario Regístrese ahora