Series 4

Consider the following mathematical succession:

\(x_0 = 7\)

\(x_1 = 3\)

\(x_{n+1} = \frac{2*x_n+x_{n-1}}{3}\)

It is well know that this succession converges to 4.0.

Implement the following Python function in the series4 module (file series4.py):

series4(eps, r)

such that given

  • eps, a float such that 0 < eps < 1.

  • r, an int

returns the list of all terms of the succession that are more than eps apart from 4.0. The terms to be included in the list must be rounded to r decimals (notice that the rounding should always be done after the comparison).

Desa la funció al fitxer series4.py i puja’l a Atenea. Els següents doctests mostren exemples del que ha de fer la funció:

For exemple:

>>> l = series4(0.1, 2)
>>> l
[7, 3, 4.33, 3.89]

>>> l = series4(0.1, 4)
>>> l

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