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
returns two values which are:
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.