Alternate Distance 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} = (-1)^{i+1} \frac{1+\sqrt{ {x_i}² + {x_{i-1}}² } }{2} \pi\)
Implement the following two Python functions (following the order is recommended) in the module adist_succ (file adist_succ.py).
The first function is:
- adist_term(xim1, xi, i)¶
such that
For exemple:
>>> xim1, xi, i = -1, 1, 2 >>> x = adist_term(xim1, xi, i) >>> round(x, 4) -3.7922 >>> xim1, xi, i = xi, x, i+1 >>> x = adist_term(xim1, xi, i) >>> round(x, 4) 7.7313 >>> xim1, xi, i = xi, x, i+1 >>> x = adist_term(xim1, xi, i) >>> round(x, 4) -15.0973
Note
Python standard modules such as math may be imported and used.
Doctests are available at the adist_term.test file.
The second function is:
- adist_t4t5(a, b)¶
such that
For exemple:
>>> a, b = -1, 1 >>> adist_t4t5(a, b) -7.366 >>> a, b = 0, 10 >>> adist_t4t5(0, 10) -27.0554
Note
This function implementation must call the previous function as many times as needed.
Doctests for validation are available at the adist_t4t5.test file.