Skip to content

Instantly share code, notes, and snippets.

@jvranish
Created April 25, 2012 02:00
Show Gist options
  • Save jvranish/2485500 to your computer and use it in GitHub Desktop.
Save jvranish/2485500 to your computer and use it in GitHub Desktop.
Example Implementation of arctan(x)
def arctan(n, x):
if x > 1.0:
return math.pi/2.0 - my_preferred_arctan_implementation(n, 1/x)
else:
return my_preferred_arctan_implementation(n, x)
def continued_faction_arctan(n, x):
x2 = x*x
d = n * 2 + 1
for k in range(n, 0, -1):
f = k * 2 - 1
d = f + k*k*x2/d
return x / d
def taylor_arctan(n, x):
approx = 0
for k in xrange(n):
j = 2 * k + 1
approx += ( (-1)**k * x**j ) / j
return approx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment