I find the following code for perimeter (or circumference of ellipse):

12*Integral(sqrt((-8*_x**2/9 + 1)/(-_x**2 + 1)), (_x, 0, 1))

This means the calculation depends on numerical integration which is very 
time consuming.

I am attaching a file containing Python sympy code to calculate numerical 
value of perimeter of ellipse to hundreds of decimal places. It computes 
value of 
perimeter of Ellipse for 800 decimals in less than 1 second on my computer.

Please incorporate in sympy after necessary modification if you find it 
suitable.

Regards

Panna Lal Patodia
[email protected], [email protected]


-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/e5022c0a-366a-4163-ba01-dcf489243f9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
# Computes Perimeter of Ellipse very fast correct to hundreds of places
# Written by Panna Lal Patodia ([email protected], [email protected])
# On November 3, 2017

from sympy import *

def peri(a, b, pr):
	import sympy
	tol = N(10**(-pr), pr)
	s = 0.0
	m = 1.0
	x = max(a,b)
	y = min(a,b)
	while (abs(x - y) > tol):
		t = (x + y) / 2
		y = N(sympy.sqrt(x * y), pr)
		x = t
		m *= 2
		s += N(m * (x - y) * (x - y), pr)
		#print(x-y, tol)
	p = N(sympy.pi * ((a + b) * (a + b) - s) / (x + y), pr)
	return p

print(peri(3, 1, 800))

Reply via email to