KPI Succession

Let’s consider the recursive definition of a mathematical succession parameterized by the real number constants \(a\), \(b\), and \(k\):

\(x_{1} = a\)

\(x_{2} = b\)

\(x_{i+1} = \frac {k \pi} {1+\sqrt{ {x_i}² + {x_{i-1}}² } }\)

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

The first function is:

kpi_next_term(x1, x2, k)

such that

given x1, x2, k float values, where x1, x2, are the values for two consecutive terms, and k is the parameter of our succession

returns a float with the next term of the succession according to the above definition

For exemple:

>>> x1 = x2 = k = 1
>>> x = kpi_next_term(x1, x2, k)
>>> round(x, 4)
1.3013

>>> x1, x2 = x2, x
>>> x = kpi_next_term(x1, x2, k)
>>> round(x, 4)
1.1895

Note

Python standard modules such as math may be imported and used.

Doctests are available at the kpi_next_term.test file.

The second function is:

kpi_term5\((x_1, x_2, k)\)

such that

given
takes \(x_1, x_2\), float values being the first and second terms of the succession respectively
returns a float with the 5th term of the above succession. The float is rounded to 2 decimals.

For exemple:

>>> x1 = x2 = k = 1
>>> kpi_term5(x1, x2, k)
1.137

>>> x1, x2, k = 1, -10, 10
>>> kpi_term5(x1, x2, k)
6.3337

Note

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

Doctests for validation are available at the kpi_term5.test file.