|Re: AGM (HP-33S & HP-15C)|
Message #20 Posted by Gerson W. Barbosa on 14 Oct 2010, 7:55 p.m.,
in response to message #19 by Namir
A0001 LBL A 001-42,21,11 f LBL A
A0002 ENTER 002- 36 ENTER
A0003 Rv 003- 33 Rv
A0004 x<>y 004- 34 x<>y
A0004 + 005- 40 +
A0006 LASTx 006- 43 36 g LST x
A0007 R^ 007- 43 33 g R^
A0008 * 008- 20 *
AOO09 SQRTx 009- 11 SQRTx
A0010 x<>y 010- 34 x<>y
A0011 2 011- 2 2
A0012 / 012- 10 /
A0013 x>y? 013-43,30, 7 g TEST 7
A0014 GTO A 014- 22 11 GTO A
A0015 RTN 015- 43 32 g RTN
These are my short 33s and 15C versions. The difference to my first draft is only the test, x>y instead of x#y, which sometimes would cause endless loops. I wrongly assumed a tolerance factor might be a better solution. Anyway, I think this has been a good exercise ...
Still under test: AGM(7,8) loops forever on the HP-33s (but not on the 15C). Will test on the 42S.
Doesn't work on the HP-42S either, for (7,8); does work on Free42 Decimal, however. Perhaps an accuracy issue. The intermediate means increase towards the theoretical result so that after a few iterations two successive means should be the same. In most cases the one in register X gets slightly greater than the one in register Y (when they not converge to the same result), but in the (7,8) example this never happens.
Edited: 15 Oct 2010, 6:52 a.m. after one or more responses were posted