Post Reply 
Perimeter of Ellipse
04-12-2023, 07:22 PM (This post was last modified: 04-16-2023 12:26 PM by floppy.)
Post: #31
RE: Perimeter of Ellipse
Exact formula for ellipse perimeter calculation? "Yes".

Via division of 2 infinite iterated functions MAGM and AGM (I dont call them elliptic functions; other does).
http://www.ams.org/notices/201208/rtx120801094p.pdf

On your calc, you just stop the AGM and MAGM routines when the delta of the iteration result is good enough for you (I stop when it is E-8; one time I tried E-9 but it went undefinitively and suppose this is due to the HP41 calculation approximation making a convergence unstable. A 128bit PC would give an outstanding precision).

Code for HP41 standard below (no SandMath ROM or other modules required) which can be overtaken for other computer.
The documentation should make possible a full understanding of the "iterated" behaviour.

Since everything can be improved.. any suggestion to improve the code is welcome.

Use case:
10
ENTER
6
XEQ ALPHA ELPER ALPHA
51.05399775

Update1:
- code revisited/simplified since the convergence is stable on HP41 and an exit criteria like E-8 not mandatory
- file upload redone

Code:
; Ellipse perimeter calculation according MAGM and AGM
;
; under CC BY SA CreativeCommons 4.0 floppy @ https://www.hpmuseum.org
;
; change log
;  2023 04 16 creation
;
; verification https://www.mathsisfun.com/geometry/ellipse-perimeter.html

; Register overwritten
;   00  a then later a**2..
;   01  b then later b**2..
;   02  zn   parameter
;   03  AGM  temporary result
;   
LBL "ELPER" 
;                    X   Y   Z   T
STO 00            ;  a   b
                  ;  ... a in R00  
X=0?
GOTO 00
X<>Y
X=0?
GOTO 00
STO 01            ; ... b in R01
CF 00             ;  clear the flag 00 used in AGM
XEQ 01            ; "AGM"
STO 03            ; ... agm in R03
0
STO 02
RCL 00
X^2 
STO 00            ; a^2
                  ; R00 content modified
RCL 01
X^2
STO 01            ; b^2
                  ; R01 content modified
CF 00
XEQ 02            ; "MAGM"
RCL 03
/
2
*
PI
*
RTN
;
; MAGM calculation with recursive function
;   http://www.ams.org/notices/201208/rtx120801094p.pdf
;
; under CC BY SA CreativeCommons 4.0 floppy @ https://www.hpmuseum.org
;
LBL 02  
;                   X            Y           Z              T
;                   an           bn  
+
2
/                ; (an+bn)/2
RCL 00
RCL 01
RCL 02           ; zn            bn          an          (an+bn)/2
ST- Y
ST- Z           ;  zn           an-zn      bn-zn         (an+bn)/2
X<> Z           ;  bn-zn        an-zn        zn          (an+bn)/2
*               ;  (an-zn)*(bn-zn)    zn    (an+bn)/2    (an+bn)/2
SQRT            ;  SQRT((an-zn)*(bn-zn))    zn    (an+bn)/2    (an+bn)/2
+               ;  (SQRT(an-zn)*(bn-zn))+zn  (an+bn)/2     (an+bn)/2   (an+bn)/2
STO 01          ;  bN         (an+bn)/2     (an+bn)/2   (an+bn)/2
                ;  ... bN in R01
LASTX           ;  (SQRT(an-zn)*(bn-zn))   bN   (an+bn)/2   (an+bn)/2
RCL 02          ;  zn    (SQRT(an-zn)*(bn-zn))   bN      (a+b)/2
-
CHS             ;  zn-(SQRT(an-zn)*(bn-zn))  bN  (an+bn)/2   (an+bn)/2
STO 02          ;  zN           bN          (an+bn)/2      (an+bn)/2
RDN             ;  bN          (an+bn)/2      (an+bn)/2     zN
ENTER           ;  bN           bN          (an+bn)/2   (an+bn)/2
X<> Z           ;  (an+bn)/2    bN          bN          (an+bn)/2
STO 00          ;  aN           bN          bN          aN
X=Y?
SF 00           ; convergence according cal precision achieved
FC?C 00
GOTO 02
RTN
;
; AGM calculation with recursive function
;   https://de.wikipedia.org/wiki/Arithmetisch-geometrisches_Mittel
;
LBL 01           ;  X   Y    Z    T
;                   a   b
STO Z            ;  a   b    a
X<>Y             ;  b   a    a
ST+ Z            ;  b   a    a+b
STO T            ;  b   a    a+b  b
*                ;  ba  a+b  b    b
SQRT             ;  sqrt(ba) a+b  b   b
R^               ;  b  sqrt(ba) a+b  b 
X=Y?
SF 00            ; convergence according cal precision achieved
RDN              ;  sqrt(ba) a+b  b   b
X<>Y
2
/                ; (a+b)/2  SQRT(ab)  b   b
;                    =a        =b   below..
FC?C 00
GOTO 01
RTN
;
LBL 00
+
4
*
RTN
END


Attached File(s)
.txt  ELPER.TXT (Size: 3.07 KB / Downloads: 1)

HP71B 4TH/ASM/Multimod, HP41CV/X/Y & Nov64d, PILBOX, HP-IL 821.62A & 64A & 66A, Deb11 64b-PC & PI2 3 4 w/ ILPER, VIDEO80, V41 & EMU71, DM41X
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Perimeter of Ellipse - Joe Horn - 03-05-2016, 04:19 PM
RE: Perimeter of Ellipse - Wes Loewer - 03-06-2016, 11:55 AM
RE: Perimeter of Ellipse - Wes Loewer - 03-06-2016, 02:16 PM
RE: Perimeter of Ellipse - Joe Horn - 03-07-2016, 03:34 PM
RE: Perimeter of Ellipse - ggauny@live.fr - 07-11-2019, 05:02 PM
RE: Perimeter of Ellipse - TASP - 03-06-2016, 02:40 PM
RE: Perimeter of Ellipse - parisse - 03-06-2016, 06:42 PM
RE: Perimeter of Ellipse - SlideRule - 03-07-2016, 01:16 PM
RE: Perimeter of Ellipse - parisse - 03-09-2016, 08:39 AM
RE: Perimeter of Ellipse - Albert Chan - 03-24-2019, 12:42 PM
RE: Perimeter of Ellipse - Albert Chan - 01-19-2020, 03:56 AM
RE: Perimeter of Ellipse - Albert Chan - 01-19-2020, 11:00 PM
RE: Perimeter of Ellipse - Albert Chan - 01-21-2020, 05:16 PM
RE: Perimeter of Ellipse - Albert Chan - 01-23-2020, 01:40 PM
RE: Perimeter of Ellipse - Albert Chan - 06-05-2020, 03:28 AM
RE: Perimeter of Ellipse - Albert Chan - 08-01-2020, 12:31 PM
RE: Perimeter of Ellipse - Albert Chan - 06-06-2020, 05:12 PM
RE: Perimeter of Ellipse - hazem - 04-11-2023, 09:43 PM
RE: Perimeter of Ellipse - rprosperi - 04-12-2023, 01:53 AM
RE: Perimeter of Ellipse - hazem - 04-13-2023, 02:06 PM
RE: Perimeter of Ellipse - floppy - 04-13-2023, 02:20 PM
RE: Perimeter of Ellipse - Werner - 04-12-2023, 05:43 AM
RE: Perimeter of Ellipse - rprosperi - 04-12-2023, 12:44 PM
RE: Perimeter of Ellipse - floppy - 04-12-2023 07:22 PM
RE: Perimeter of Ellipse - Albert Chan - 04-13-2023, 05:23 PM
RE: Perimeter of Ellipse - floppy - 04-15-2023, 06:21 PM



User(s) browsing this thread: 4 Guest(s)