Sinus of the Inverse Index Series

Let’s consider an infinite mathematical succession defined by:

\[t_i = k \cdot \sqrt{i} \cdot \sin\left(\frac{1}{i^2}\right)\]

We wish to compute the sum of these terms (ie. computer the series) till its “good enough” without exceeding a given limit of iterations.

Please implement the following Python function in the sininv_series module (sininv_series.py file):

sininv_series(k, ntmax, eps):

such that

given

  • k, a float, with the coeficient.

  • ntmax, an int such that ntmax >= 1, with the maximum number of iterations.

  • \(eps\), a float with the tolerance.

returns two values which are:

  1. A float with the sum of the terms the given succession until either the difference between consecutive terms is smaller than the given eps or the number of terms added to this sum reached ntmax.

  2. An int with the number of terms added.

Note

Notice that the term that makes the difference smaller than the tolerance is not added.

For example:


>>> s, n = sininv_series(1, 100, 0.001)
>>> round(s, 6) == 1.996784 and n == 19
True

>>> s, n = sininv_series(1, 10, 0.001)
>>> round(s, 6) == 1.832619 and n == 10
True

>>> s, n = sininv_series(0.1, 100, 0.001)
>>> round(s, 6) == 0.171977 and n == 7
True

>>> s, n = sininv_series(10, 100, 0.001)
>>> round(s, 6) == 21.594708 and n == 47
True

Doctests are available at the sininv_series.test file.