Maclaurin series

We are given the two following Maclaurin series that correspond respectively to the development of functions \(\frac{1}{1-x}\) and arctangent:

\(\sum_{n=0}^{k} x^{n} = 1 + x + x^{2} + x^{3} + \cdots\)

\(\sum_{n=0}^{k}(-1)^{n} \frac{x^{2n+1}}{2n+1} = x - \frac{x^{3}}{3} + \frac{x^{5}}{5} - \frac{x^{7}}{7} + \cdots\)

Save all function into file maclaurin.py.

  1. Given a real value x as \(-1 \leq x \leq 1\) and another positive real value epsilon which is the tolerance, write the function series1() to calculate the sum of terms of the first given series. The summation must stop when two consecutive terms are equal with a tolerance epsilon, in other words, when the absolute value of the difference between them is less than epsilon. Examples:

    >>> round(series1(0.8, 0.001), 1)
    5.0
    >>> round(series1(-0.6, 0.0001), 3)
    0.625
    

    Note

    You can download the file with tests maclaurin1.txt

  2. Write the function series2() analogous to function series1() but using the second given series. Examples:

    >>> round(series2(1, 0.0001), 4)
    0.7854
    >>> round(series2(0.2, 0.0001), 4)
    0.1974
    
    

    Note

    You can download the file with tests maclaurin2.txt

Solution

A solution of these functions is provided in the maclaurin.py