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:

calc_term\((a, i, x_i)\)
takes
\(a\), float value,
\(i\), positive int value,
\(x_i\), float value representing an angle expressed in radians
returns
\(x_{i+1}\) according to the above definition, as a float value rounded to 4 decimals.

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:

sum4terms\((a, x_0)\)
takes \(a, x_0\), float values where \(x_0\) is the first term of the succession
returns a float with the addition of the first 4 terms of the above succession, being \(x_0\) the first of them. The float is rounded to 2 decimals.

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.