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
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
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.