Series¶
Let’s consider the following mathematical succession parameterized by the real number constant \(a\):
\[x_{i+1} = \frac{-1^{i+1} a sin(x_i)}{x_i/2}\]
Implement the following two Python functions (following the order is recommended) in the module series12 (file series12.py).
The first function is:
For exemple:
>>> x = calc_term(0.1, 1, 0.1) >>> x 0.1997 >>> x = calc_term(0.1, 2, 0.1997) >>> x -0.1987 >>> x = calc_term(0.1, 3, -0.1987) >>> x 0.1987
Note
Python standard modules such as math may be imported and used.
Doctests are available at the calc_term-test.txt file.
The second function is:
For exemple:
>>> sum4terms(0.1, 0.1) -0.1 >>> sum4terms(1.0, 1.0) -1.07 >>> sum4terms(0.5, 0.25) -0.78 >>> sum4terms(0.4, 2) 1.7
Note
This function implementation must call the previous function as many times as needed.
Doctests for validation are available at the sum4terms-test.txt file.