Skip to content
DeepForgeby svx
All problems
MediumCalculusca-084

Taylor Series ln(1+x)

Problem

Evaluate the degree-n Taylor polynomial of ln(1 + x) about 0:

P_n(x) = sum from k = 1 to n of (-1)^(k+1) * x^k / k

The series converges for -1 < x <= 1; for x = 1 convergence is slow, so the partial sum may differ noticeably from ln(2).

Hint

Track the running power of x and alternate the sign of each term.

Test cases

case 1
in: [0,10]
expected: 0
case 2
in: [0.5,20]
expected: 0.4054650927341771
case 3
in: [-0.5,20]
expected: -0.6931471370510288
case 4
in: [0.25,15]
expected: 0.22314355132599137
case 5
in: [0.5,4]
expected: 0.4010416666666667
Starter codePython
def ln1p_series(x, n):
    # Your code here
    pass

5 test cases · run your code against them in the editor