Created
April 25, 2012 02:00
-
-
Save jvranish/2485500 to your computer and use it in GitHub Desktop.
Example Implementation of arctan(x)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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