[VA] SRC #010 - Pi Day 2022 Special
|
03-16-2022, 08:50 AM
Post: #6
|
|||
|
|||
RE: [VA] SRC #010 - Pi Day 2022 Special
Thanks Valentin for this interesting reading. Relations between pi and e always intrigued me.
(03-15-2022 03:11 PM)Ángel Martin Wrote: As you guys know I'm "stuck" in the 41 world [...] and sure enough my FOCAL routines did not work at all. Really? HP-41 user code can't do it? Let's see: Maybe it's better to transform Valentin's expression with log and then compute the exponential at the end. Using pseudo algebraic language (I'm not comfortable with graphic equation editors), with ln as the natural log: PN = exp(3/2) * Prod(n=2,N,e*(1-1/n²)^n²) / (1+1/(2*N)-1/(8*N²)) becomes ln(PN) = 3/2 + Sum(n=2,N,1+n²*ln(1-1/n²)) - ln(1+1/(2*N)-1/(8*N²)) e doesn't appear explicitly any more, but of course it does at the end when computing exp(ln(PN)). Here is the corresponding HP-41/42 program, using the here highly useful LN1+X function that preserves the accuracy for small 1/n² quantities to some extend: 01*LBL "PN2" 02 "RUNNING" 03 AVIEW 04 STO 00 ; N 05 1 06 - 07 STO 01 ; control loop 1..N-1 08 0 09*LBL 00 ; sum loop <--- 10 RCL 01 11 1 12 + ; n=2..N 13 X^2 14 ENTER^ 15 1/X 16 CHS 17 LN1+X 18 * 19 1 20 + 21 + 22 DSE 01 23 GTO 00 ; sum endloop --^ 24 RCL 00 25 2 26 * 27 1/X 28 RCL 00 29 X^2 30 8 31 * 32 1/X 33 - 34 LN1+X ; correction factor 35 - 36*LBL 01 ; final result 37 1.5 38 + 39 E^X 40 CLD 41 END and results for the HP-41: 10.00000000 RUN RUNNING 3.141844397 *** 100.0000000 RUN RUNNING 3.141592946 *** 200.0000000 RUN RUNNING 3.141592701 *** 300.0000000 RUN RUNNING 3.141592670 *** 400.0000000 RUN RUNNING 3.141592651 *** best result 500.0000000 RUN RUNNING 3.141592685 *** Not bad for this ancient 10-digit machine, isn't it? So thanks again Valentin for this contribution to the fascinating pi, and Ángel for giving me the opportunity to write a HP-41 code, something I'm rarely doing - I'm a HP-71B man - but the HP-41 language is so deeply buried in my mind since 40 years that it was very natural. J-F |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)