Perimeter of an Ellipse (HP-42S) - Printable Version +- HP Forums ( https://archived.hpcalc.org/museumforum)+-- Forum: HP Museum Forums ( https://archived.hpcalc.org/museumforum/forum-1.html)+--- Forum: Old HP Forum Archives ( https://archived.hpcalc.org/museumforum/forum-2.html)+--- Thread: Perimeter of an Ellipse (HP-42S) ( /thread-244138.html) |

Perimeter of an Ellipse (HP-42S) - Gerson W. Barbosa - 05-24-2013
00 { 48-Byte Prgm }
Exact formula: p = 4*a*E(1-b^2/a^2)where E(x) is the complete elliptic integral of the second kindExample: a = 2, b = 1http://www.wolframalpha.com/input/?i=4*2*E%281-1%2F4%29
Approximate formula: p ~ pi*(a + b)*(4/(4-h) - 3/256*h^2*(4 + h))where h = ((a - b)/(a + b))^2
The approximate formula is a rework of the Infinite Series 2 in this reference, whose terms are a subset of the infinite series SUM(k=0,inf,(h/4)^k), which converges to 4/(4-h). The resulting expression is 4/(4-h) - 3/64*h^2 - 3/256*h^3 - 39/16384*h^4 - 15/65536*h^5 + 185/1048576*h^6 ...This was done by hand and haven't been doublechecked. Anyway, the approximation formula above uses only terms up to h^3. The percent error ranges from 0% (circle) to about 0.1% in the worst case (two coincidental lines). +-----+-----+---------------+---------------+ Thanks Eduardo Duenez for his recent post below.
Re: Perimeter of an Ellipse (HP-42S) - Ernie Brock - 05-24-2013
I don't have an HP-42S, but you may be able to improve on this by computing the line integral from 0 to pi/2 using the numeric integrator on the 42S p = 4 * a * integral(sqrt(1-(a*a-b*b)/(a*a)*sin^2(t), t, 0, pi/2)
BTW quoted "exact" answer for a=3,b=2 should be 15.8654395893 not 15.8654396893
Re: Perimeter of an Ellipse (HP-42S) - Gerson W. Barbosa - 05-24-2013
Problem is numerical integration is rather slow to full accuracy on the HP-42S, but I'll check this later.
Quote:
Fixed, thanks!
Re: Perimeter of an Ellipse (HP-42S) - Gerson W. Barbosa - 05-24-2013
Quote: The drawback is a somewhat long running time, but that's an option. Regards, Gerson.
Re: Perimeter of an Ellipse (HP-42S) - hugh steers - 05-24-2013
Hi. Good stuff! Here's another way i found a while back, using a variation of arithmetic and geometric means. The iteration is fairly rapid and small to code. This program is in C, but i hope you can see the method:
#include <math.h> Re: Perimeter of an Ellipse (HP-42S) - Eduardo Duenez - 05-24-2013
Quote:
The above is not the correct relation between the complete elliptic integral E(x) and the perimeter p(a,b) of the ellipse. The argument "x" (usually denoted k, "the modulus") of E(k) is dimensionless, whereas (a+b)/(a+b(b+1)) is not. The correct relation is p(a,b) = 4*a*E(c/a)where a is the major semiaxis and c = sqrt(a^2-b^2)is the focal semidistance (so c/a is the eccentricity of the ellipse). Note that c/a is dimensionless. Eduardo
EDIT: Coincidentally enough, Hugh Steers' C program above (posted as I was writing this, a few minutes earlier) documents the correct relation as well.
Re: Perimeter of an Ellipse (HP-42S) - Eduardo Duenez - 05-24-2013
The algorithm used in Hugh Steers' C program is (As an academic I feel the urge to always credit original ideas to their source.)
Eduardo
Re: Perimeter of an Ellipse (HP-42S) - Gerson W. Barbosa - 05-24-2013
Quote:
I'd found the formula p(a,b) = 4*a*E(pi/2,e), where e is the eccentricity, sqrt(1 - (b/a)^2)However, trying this on WolframAlpha for a = 3 and b =2 I get 14.567698609052450048.. instead of 15.865439589290589791.. http://www.wolframalpha.com/input/?i=4*3*E%28pi%2F2%2Csqrt%281-%282%2F3%29%5E2%29+%29
Oddly enough my wrong parameter works when the difference between a and b is 1 (at least for integer values) and when a = b or one of the semi-axis is 0, as in all of my examples. I should have tried a = 5 and b = 3, for instance, for which it fails. Gerson.
Re: Perimeter of an Ellipse (HP-42S) - Gerson W. Barbosa - 05-24-2013
Thanks for the C code, Hugh! I am not proficient in C, but this appears to be easier to follow than RPL code. Anyway, my goal is a simple and short approximation formula that is accurate enough for practical cases, something that would give an error of a few meters in the length of the Earth's orbit for instance and takes about 20 or so steps on the HP-42S and no more than 1 second to run. Perhaps the approximate formula above meets this goal, but I haven't checked yet. Other approximate formulas are welcome, in case anyone knows about them (I've found only a few -- it appears measuring ellipses is not a popular sport :-)
Gerson.
Re: Perimeter of an Ellipse (HP-42S) - Ángel Martin - 05-24-2013
To add a log to the fire, here´s the program on the 41 + SandMath: Assumes a in Y and b in X, where ELI2 is the Incomplete Elliptic Integral of the second kind.-
01 LBL "ELIPER" For a=3, b=2 I get: p = 14.56769861 in 1.8 seconds on the CL (gotta love this machine :-)
Cheers, Re: Perimeter of an Ellipse (HP-42S) - Gerson W. Barbosa - 05-24-2013
Hi Ángel, What is the physical meaning of this result? Not the perimeter, I presume. That should be about 15.9, according to the best approximations I've seen. Regards,
Gerson.
Re: Perimeter of an Ellipse (HP-42S) - Ángel Martin - 05-24-2013
This is what happens when rushing thru not paying attention to the details:- I checked the formula and corrected the program accordingly, the result is now as yours: http://www.wolframalpha.com/input/?i=perimeter+of+ellipse
01 LBL "ELIPER" 3, ENTER^, 2, XEQ"ELIPER" --> 15,86543959
Cheers,
Re: Perimeter of an Ellipse (HP-42S) - Gerson W. Barbosa - 05-24-2013
Thanks, Ángel! The parameter required by WolframAlpha is the square of the eccentricity, not the eccentricity. That's what I was doing wrong. Cheers,
Gerson.
Re: Perimeter of an Ellipse (HP-42S) - Eduardo Duenez - 05-24-2013
Quote: I know why. The documentation linked to from Wolfram Alpha is inconsistent with Mathematica's definition. What Wolfram Alpha's EllipticE(.) takes as an argument is the modulus k *squared*, and *not* k (in other words the eccentricity *squared*). The convention used by W.Alpha is the one used by the function elliptic_ec(m) in venerable open-source program Maxima as correctly documented at: http://maxima.sourceforge.net/docs/manual/en/maxima_16.html Try: http://maxima-online.org/#?in=4*3*elliptic_ec%20(5.0%2F9)%0A%20%09
Eduardo
Re: Perimeter of an Ellipse (HP-42S) - Gerson W. Barbosa - 05-24-2013
Quote: Yes, we'd just found that out too (see my reply to Ángel above). Thanks again! Gerson.
Re: Perimeter of an Ellipse (HP-42S) - Ángel Martin - 05-25-2013
Exactly, so beating this dead horse just once more, this is the correct syntax for WolframAlpha: 4*3*E(pi/2,(1-(2/3)^2) ) [url:http://www.wolframalpha.com/input/?i=4*3*E%28pi%2F2%2C%281-%282%2F3%29^2%29+%29] Best, ÁM
Re: Perimeter of an Ellipse (HP-42S) - Thomas Klemm - 05-26-2013
In your program
Kind regards |