 Can you calculate Pi using a Solver? - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: Can you calculate Pi using a Solver? (/thread-14132.html) Pages: 1 2 3 Can you calculate Pi using a Solver? - EdS2 - 12-09-2019 01:12 PM I'm wondering what approaches there might be for computing Pi using one of the Solvers on the various HP calculators. Of course, no trig functions allowed! Let's call this a mini-challenge, unless it turns out to be so easy and obvious that it's a nano-challenge. RE: Can you calculate Pi using a Solver? - SlideRule - 12-09-2019 01:44 PM Reference: Using A Minicalculator to Find An Approximate Value for Π, E. J. Bolduc (University of Florida) "One of the many ways to use a minicalculator in a classroom is in the calculation of an approximate value for n using a variation of the method of Archimedes … if a circle of radius 1 is chosen, then the area of any inscribed polygon is less than Π and the area of any circumscribed polygon is greater than n. He finally arrived at the fact that 3(10/17) < Π < 3(1/7). We can use the idea that, as the numbers of sides of an inscribed polygon increases, the perimeter of the polygon approaches the circumference of the circle and the ratio of the perimeter to the diameter of the circle is an approximation for Π … We now have our iterative formula, S’ = √2r² - r√4r² - S²" I leave the recursion and subsequent calculation to the reader, but after nine iterations, the equation yields 3.141592… BEST! SlideRule RE: Can you calculate Pi using a Solver? - jthole - 12-09-2019 01:50 PM This does not answer your question directly, but on the back of my 12C I have a sticker with "355 / 113". For my purposes, that is good enough RE: Can you calculate Pi using a Solver? - toml_12953 - 12-09-2019 01:56 PM (12-09-2019 01:44 PM)SlideRule Wrote:  Reference: Using A Minicalculator to Find An Approximate Value for Π, E. J. Bolduc (University of Florida) "One of the many ways to use a minicalculator in a classroom is in the calculation of an approximate value for n using a variation of the method of Archimedes … if a circle of radius 1 is chosen, then the area of any inscribed polygon is less than Π and the area of any circumscribed polygon is greater than n. He finally arrived at the fact that 3(10/17) < Π < 3(1/7). We can use the idea that, as the numbers of sides of an inscribed polygon increases, the perimeter of the polygon approaches the circumference of the circle and the ratio of the perimeter to the diameter of the circle is an approximation for Π … We now have our iterative formula, S’ = √2r² - r√4r² - S²" I leave the recursion and subsequent calculation to the reader, but after nine iterations, the equation yields 3.141592… BEST! SlideRule Here's a simple BASIC version from Problems for Computer Solution by Stephen J. Rogowski: Code: ```50 PRINT "ARCHIMEDEAN DETERMINATION OF PI!" 60 PRINT 70 PRINT "NO. OF SIDES","INSCR PER","CIRCUM PER" 80 PRINT 100 FOR X=2 TO 15 105   LET N=2^X 110   LET D=360/N 120   LET T=3.1415927*(D/180) 130   LET A=2*N*SIN(T/2) 140   LET B=2*N*TAN(T/2) 150   PRINT N,A/2,B/2 155   IF A=B THEN GOTO 170 160 NEXT X 170 END``` RE: Can you calculate Pi using a Solver? - Valentin Albillo - 12-09-2019 03:35 PM (12-09-2019 01:12 PM)EdS2 Wrote:  I'm wondering what approaches there might be for computing Pi using one of the Solvers on the various HP calculators. Of course, no trig functions allowed! Let's call this a mini-challenge, unless it turns out to be so easy and obvious that it's a nano-challenge. If your Solver has Square Root and Factorial, this one from Ramanujan converges very fast and it's quite simple, few bytes to program it and only a few terms to add up for full precision... ... and no trigs used, as requested, just basic arithmetic. Once you get 1/Pi just invert it with 1/x Regards. V. RE: Can you calculate Pi using a Solver? - Csaba Tizedes - 12-09-2019 03:53 PM Code: `120   LET T=    3 . 1 4 1 5 9 2 7      *(D/180)` WHAT? Code: ```120   LET T=3.1415927*(D/180) 130   LET A=2*N*SIN(T/2) 140   LET B=2*N*TAN(T/2) 155   IF A=B THEN GOTO 170 170 END``` Err... this looks like a checking how precise the arithmetics of that computer... BTW: HP32SII - a fraction finder Code: ```--------------------- LBL Q   RCL P   RCL / Q   RCL - K   STO D        //D=P/Q-K   ABS   RCL E   X>=Y?        //E>=ABS(D)? RTN            //Yes, end of the program   RCL D           X<0?         //P/QB THEN 20``` >RUN 3.14040401902 3.1415926456 3.1415926536 3.14159265359 RE: Can you calculate Pi using a Solver? - EdS2 - 12-11-2019 10:29 AM Ah, always interesting to get some unexpected results - thanks everyone! In some, then, we see a 'sigma' function being used to do most of the work, and the solver is only needing to cope with a simple transformation like reciprocal or square root. I hadn't realised a 'sigma' function might be to hand - of course these offerings are valid, for the machines which offer 'sigma'. For the first submission, the iterative one posted by sliderule, is there a way to render this as a Solver problem? Quote:We now have our iterative formula, S’ = √2r² - r√4r² - S² Likewise, for the AGM method posted by Albert Chan, is there a way to get a Solver to do the work, rather than a program? RE: Can you calculate Pi using a Solver? - toml_12953 - 12-11-2019 11:50 AM (12-09-2019 03:53 PM)Csaba Tizedes Wrote:   Code: `120   LET T=    3 . 1 4 1 5 9 2 7      *(D/180)` WHAT? Code: ```120   LET T=3.1415927*(D/180) 130   LET A=2*N*SIN(T/2) 140   LET B=2*N*TAN(T/2) 155   IF A=B THEN GOTO 170 170 END``` Err... this looks like a checking how precise the arithmetics of that computer... It shows that both an inscribed and circumscribed polygon approach PI as the number of sides increases. I agree it was poorly named. RE: Can you calculate Pi using a Solver? - Albert Chan - 12-11-2019 01:09 PM (12-11-2019 11:50 AM)toml_12953 Wrote:  It shows that both an inscribed and circumscribed polygon approach PI as the number of sides increases. We can do this with right triangles, starting from a hexagon ("radius" = side = 2S = 1) 10 N=6 @ S=.5 20 H=SQRT(1-S*S) @ A=N*S @ B=A/H 30 DISP N,A,B 40 N=N+N @ S=.5*SQRT(S^2+(1-H)^2) 50 IF ARUN  6                    3                    3.46410161514  12                   3.10582854122        3.21539030916  24                   3.13262861328        3.1596599421  48                   3.13935020304        3.14608621512  96                   3.14103195089        3.14271459965  192                  3.14145247229        3.14187304999  384                  3.14155760792        3.14166274706  768                  3.14158389215        3.1416101766  1536                 3.14159046322        3.14159703431  3072                 3.141592106          3.14159374877  6144                 3.1415925167         3.14159292739  12288                3.14159261938        3.14159272205  24576                3.14159264504        3.14159267071  49152                3.14159265146        3.14159265788  98304                3.14159265306        3.14159265467  196608               3.14159265346        3.14159265386  393216               3.14159265356        3.14159265366  786432               3.14159265357        3.1415926536  1572864              3.14159265359        3.1415926536  3145728              3.14159265359        3.14159265359``` Edit: line 40 may be replaced with simpler formula (approx. same accuracy) 40 N=N+N @ S=S/SQRT(H+H+2) RE: Can you calculate Pi using a Solver? - Roland57 - 12-11-2019 05:49 PM Hi, May be it is too easy, but what about this pi = 2 * integral(1 / sqr(1-x*x), x, 0, 1) It gives 3.141592(48348) on the iOS prime-emulator Roland RE: Can you calculate Pi using a Solver? - Albert Chan - 12-11-2019 08:00 PM (12-11-2019 05:49 PM)Roland57 Wrote:  pi = 2 * integral(1 / sqr(1-x*x), x, 0, 1) It gives 3.141592(48348) on the iOS prime-emulator Some calculators have problem with singularity at the limits. We can do this instead: pi = 6 asin(.5) = integrate(6 / sqrt(1-x*x), x = 0 .. 0.5) or, to speed it up a bit ... pi = 4 atan(1) = integrate(4 / (1+x*x), 0, 1) RE: Can you calculate Pi using a Solver? - EdS2 - 12-12-2019 08:18 AM ah yes, like summation, integration certainly has ways to reach pi. I'm still curious about the solver though. If any HP calculator's solver worked in the complex domain (and I imagine none do) then Euler's identity would give a route to pi. (By the solver, I mean the facility which takes a function of one variable and finds a value of that variable which makes the function zero.) As we know that pi isn't algebraic, it might be that we know there's no way to do this. But finding a fixed point of a recurrence feels a bit like finding a zero of a function, so I wonder if that could be a way. RE: Can you calculate Pi using a Solver? - EdS2 - 12-12-2019 11:24 AM I found a couple of not-great examples of the sort of thing I might hope exists... There's a good approximation for pi as a root of an 8th order polynomial: 0=1−1635840576x−343853312x^2 +60576043008x^3 +1865242664960x^4 −16779556159488x^5 +37529045696512x^6 −29726424956928x^7 +6181548457984x^8 And there's a bad approximation as a solution to x=(1+1/x)^(x+1) Here's a quartic: 0=16-160x+168600x^2-841000x^3+250625x^4 RE: Can you calculate Pi using a Solver? - SlideRule - 12-12-2019 02:12 PM (12-12-2019 11:24 AM)EdS2 Wrote:  I found a couple of not-great examples of the sort of thing I might hope exists... An excerpt from PI a source book, Springer (2e), 96-40196, © 2000 [attachment=7919] The PDF title says it all. BEST! SlideRule RE: Can you calculate Pi using a Solver? - EdS2 - 12-12-2019 03:02 PM Thanks! Also of interest (and relevant) is The Quest for Pi, a 16 page paper by BBP. (I'm still not sure how to get the solver to make use of this kind of iterative approach. Merely evaluating an expression doesn't feel like it's making proper use of a solver.)