Most impressive/complex/amazing C-series program?
|
04-13-2018, 12:27 AM
Post: #5
|
|||
|
|||
RE: Most impressive/complex/amazing C-series program?
Hi, brickviking: (04-08-2018 02:29 AM)brickviking Wrote: What's an a.m. routine? I can see some tests in there, and a square root, but the concept's currently beyond me. The code simply computes Pi using the formula: Pi = 2 * 2/sqrt(2) * 2/sqrt(2+sqrt(2)) * 2/sqrt(2+sqrt(2+sqrt(2))) * ... which converges to the 10-digit representation of Pi (3.141592654) using just 17 terms. The algorithm is very clearly seen in this HP-71B equivalent command-line version >FIX 9 @ F=0 @ P=2 @ FOR I=1 TO 17 @ F=SQR(2+F) @ P=2*P/F @ NEXT I @ P 3.141592654 If you want to see the convergence after each term, this simpler implementation I've independently concocted adds an intermediate stop (R/S) and removes the now unneeded test, decreasing the step count from 17 to 14: 01- 35 CLx 02- 36 ENTER 03- 2 2 *04- 34 X<>Y 05- 2 2 06- 40 + 07- 43 21 SQR 08- 10 / 09- 43 36 LSTx 10- 34 X<>Y 11- 2 2 12- 20 * 13- 31 R/S 14- 43,33 04 GTO 04 To run it in any HP-12C, set 9 decimals (f 9), go to the top of program memory (GTO 00), and use R/S to see the converging value after each new term, like this: f 9 GTO 00 R/S -> 2.828427126 R/S -> 3.061467460 R/S -> 3.121445154 R/S -> 3.136548492 R/S -> 3.140331160 --- R/S -> 3.141592648 R/S -> 3.141592652 R/S -> 3.141592654 After pressing R/S sixteen times the value has converged and there's no need to go on, any subsequent R/S would produce the same value (3.141592654) again. Note: the original code in the Code panel has one typo. Step 14 appears like this: 14-43,33 00 RTN but though the keycode is correct, it should read GTO 00 instead of RTN, like this: 14-43,33 00 GTO 00 because that's what the keycode indicates and there's no RTN instruction in the HP-12C's instruction set as there's no subroutine (GSB) capability either. Regards. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)