All problems
Arctan Series
Problem
Evaluate the Gregory series for arctan(x) to n terms:
arctan(x) ≈ sum from k = 0 to n-1 of (-1)^k * x^(2k+1) / (2k+1)
The series converges quickly for |x| < 1 but very slowly near x = 1, so partial sums there lag the true value.
Hint
Only odd powers appear; multiply the running power by x squared each step.
Test cases
case 1
in: [0,5]
expected: 0
case 2
in: [0.5,20]
expected: 0.46364760900079693
case 3
in: [-0.5,20]
expected: -0.46364760900079693
case 4
in: [0.25,10]
expected: 0.24497866312685385
case 5
in: [1,10]
expected: 0.7604599047323508
Starter codePython
def arctan_series(x, n):
# Your code here
pass5 test cases · run your code against them in the editor