+1.
Now leaving the "simplicity" of having MAGM divided by AGM, at the cost of calculation time, for calculating ellipse perimeter, and lets show what I call "GaussKummer-like" with "AGM functional turbo boosting". If I remember it was already posted in this forum for HP15c. Now for HP41. NO APPROXIMATION: only limitation to the available precision with HP41.
Code:
; calcul ellipse perimeter GaussKummer like with AGM exact function for
; "convergence boosting"
;
;Inputs
; a ENTER b ENTER XEQ PERE12
; a and b: half parameter of the ellipse
;
;Outputs
; results in stack X:perimeter
;
;Modules used
; None
;
;use R 07..11
;keep free Reg 00-06 if use with SOL from MATH from other programs
; in case this program would be used for example for finding the "a" if
; the "perimeter" and the "b" are given
;
;create raw file with "rpncomp --raw-output PERE12.TXT", upload
; in V41 emulator and store into virtual drive pyILPER
;
;under CC BY SA CreativeCommons 4.0 floppy @ https://www.hpmuseum.org/forum/
;
;idea from here
; https://www.hpmuseum.org/forum/thread-5820-post-171326.html#pid171326
;
;change log
; date 2023 04 15 creation and release (based on PEREL6 simplified program)
;
;comment
; all an bn R0xn are from the "n" loop
; all with "N" are updated parameter in the new loop
;
LBL "PERE12"
X=0? ; in case a = 0 this is a flat ellipse
GTO 01
STO 07 ; b in 07
X<>Y
X=0? ; in case b = 0 this is a flat ellipse
GTO 01
STO 08 ; a in 08
X^2
X<>Y
X^2
+
STO 09 ; an^2 + bn^2 in R09
1
STO 10 ; 1 in R10n
;
LBL 00 ; X Y Z T
RCL 08 ; an
RCL X ; an an
RCL 07 ; bn an an
* ; bn*an an
SQRT ; SQRT(an*bn)=bN an
X<> 07 ; bn an
; ... R07 = bN
RCL 07 ; bN bn an
X=Y?
SF 00
RDN ; bn an
- ; an-bn
2 ; 2 an-bn
ST* 10 ; 2 an-bn
; ... R10N= 2*R10n
/ ; (an-bn)/2
ST- 08 ; (an-bn)/2
; ... R08N=aN=an-(an-bn)/2=(an+bn)/2
X^2 ; ((an-bn)/2)^2
RCL 10 ; R10N ((an-bn)/2)^2
* ; R10N*((an-bn)/2)^2
ST- 09 ; R10N*((an-bn)/2)^2
; ... R09N = R09n- R10N*((an-bn)/2)^2
FC?C 00
GOTO 00
RCL 09
RCL 07
/
PI
*
RTN
LBL 01 ;in case b or a = 0 flat ellipse it goes here out
+
4
*
RTN
END
Just tested on an HP41CX. Printing w/o comment (in order to see the length).
Code:
01*LBL "PERE12"
02 X=0?
03 GTO 01
04 STO 07
05 X<>Y
06 X=0?
07 GTO 01
08 STO 08
09 X^2
10 X<>Y
11 X^2
12 +
13 STO 09
14 1
15 STO 10
16*LBL 00
17 RCL 08
18 RCL X
19 RCL 07
20 STO T
21 *
22 SQRT
23 STO 07
24 RDN
25 -
26 CHS
27 2
28 ST* 10
29 /
30 ST- 08
31 X^2
32 RCL 10
33 *
34 ST- 09
35 RDN
36 X#Y?
37 GTO 00
38 1/X
39 RCL 09
40 *
41 PI
42 *
43 RTN
44*LBL 01
45 +
46 4
47 *
48 RTN
49 .END.
Now latest shortest version on HP41 (no check of flat ellipse; no modules required)
Code:
01*LBL "PERE12"
02 STO 07
03 X^2
04 X<>Y
05 STO 08
06 X^2
07 +
08 STO 09
09 1
10 STO 10
11*LBL 00
12 RCL 08
13 RCL X
14 RCL 07
15 STO T
16 *
17 SQRT
18 STO 07
19 RDN
20 -
21 CHS
22 2
23 ST* 10
24 /
25 ST- 08
26 X^2
27 RCL 10
28 *
29 ST- 09
30 RDN
31 X#Y?
32 GTO 00
33 1/X
34 RCL 09
35 *
36 PI
37 *
38 RTN
39 END