Post Reply 
Perimeter of the Ellipse (HP-15C)
05-26-2021, 08:56 PM (This post was last modified: 05-27-2021 11:28 AM by Albert Chan.)
Post: #5
RE: Perimeter of the Ellipse (HP-15C)
(01-19-2020 11:00 PM)Albert Chan Wrote:  \(\large p(a,b) = 2× \left( p({a+b \over 2}, \sqrt{ab}) - {\pi a b \over AGM(a,b)}\right)\)

In other words, calculate ellipse perimeter from a much less eccentric ellipse.

Code:
from math import sqrt, pi
def p(a, b, pi2=2*pi):
    'perimeter of ellipse, a>0, b>0, order does not matter'
    ab = a*b
    r = sqrt(ab)
    if r==b: return pi2*r, pi2/r
    p2, k = p((a+b)/2, r)
    return 2*p2-k*ab, k     # perimeter, 2*pi/agm(a,b)

>>> p(20,10)
(96.884482205476857, 0.43130312949992861)

With AGM, convergence is quadratic:

p(20, 10)
→ p(15.0, 14.142135623730951)
→ p(14.571067811865476, 14.564753151219703)
→ p(14.56791048154259, 14.567910139395549)
→ p(14.56791031046907, 14.567910310469069)

Last ellipse is practically a circle, thus return 2πr ≈ 91.532880019049259
Code then unwind back to the top, for p(20, 10) ≈ 96.884482205476857

Edit: code return (perimeter, 2*pi/agm(a,b))

>>> m = 0.5 # elliptic parameter m, 0 < m < 1
>>> [x/4 for x in p(1, sqrt(1-m))] # E(m), K(m)
[1.3506438810476749, 1.8540746773013719]

This may be why Matlab have ellipke that return both kinds of elliptic integrals.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Perimeter of the Ellipse (HP-15C) - Albert Chan - 05-26-2021 08:56 PM



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