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.
Given a real value
xas \(-1 \leq x \leq 1\) and another positive real valueepsilonwhich is the tolerance, write the functionseries1()to calculate the sum of terms of the first given series. The summation must stop when two consecutive terms are equal with a toleranceepsilon, in other words, when the absolute value of the difference between them is less thanepsilon. 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.txtWrite the function
series2()analogous to functionseries1()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