Series

Let’s consider the following mathematical succession parameterized by the real number constants \(k_1, k_2\):

\[x_{i+1} = \left| \frac{k_1 + sin(x_i)}{2*e^{k_2 x_i}} \right|\]

Implement the following Python functions (following the order is recommended) in the module series11 (file series11.py).

The first function is:

calc_term\((k_1, k_2, x_i)\)
takes \(k_1, k_2, x_i\) float values, where \(x_i\) is an angle expressed in radians
returns \(x_{i+1}\) according to the above definition, as a float rounded to 4 decimals.

For exemple:


>>> x = calc_term(0.1, 0.1, 4.0)
>>> x
0.2201

>>> x = calc_term(0.1, 0.1, x)
>>> x
0.1557

>>> x = calc_term(0.1, 0.1, x)
>>> x
0.1256

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:

sum3eventerms\((k_1, k_2, x_0)\)
takes \(k_1, k_2, x_0\) float values
returns the addition of the terms \(x_0, x_2, x_4\) of the above succession, as a float value rounded to 3 decimals.

For exemple:


>>> sum3eventerms(0.1, 0.1, 4.0)
4.267

>>> sum3eventerms(0.0, 0.0, 0.0)
0.0

>>> sum3eventerms(-1.0, 1.0, 0.0)
0.384

Note

This function implementation must call the previous function as many times as needed.

Doctests are available at the sum3eventerms-test.txt file.