Convergence

Consider the following mathematical succession:

\(x_{0} = ...\)

\(x_{1} = ...\)

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

We know that it converges for some initial values \(x_{0}, x_{1}\). For example, for \(x_0 = 7.0\) and \(x_1 = 3.0\) it converges to \(4.0\).

A function is required such that given two initial values and a tolerance, it approximates the convergence value of the sucession. Implement the following Python function in the conv_mp21 module (file conv_mp21.py):

conv_mp21(x_0, x_1, ne)

such that

given

  • x_0, x_1 two float initial values for which our succession converges

  • ne, a int such that 1 <= ne < 10.

returns the convergence value with a \(1/10^{ne}\) tolerance. To get the convergence value this must be rounded to ne decimals.

Since the exact convergence value is not known, a way to determine that our approximation is good enough would be the \(abs(t_{i}-t_{i-1})/2.0 <= 1/10^{ne}\).

The following doctests show some examples:

>>> c = conv_mp21(7.0, 3.0, 2)
>>> c == 4.0
True

>>> c = conv_mp21(7.0, 3.0, 6)
>>> c == 4.0
True

>>> c = conv_mp21(1.5, -0.5, 4)
>>> c == 0.0
True

>>> c = conv_mp21(1.0, -1.0, 4)
>>> c == -0.5
True

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