Function sampling ================= In these exercises we want to sample a function `f` in a given interval `[a, b]` and with `d` increments. `a`, `b` and `d` are such that :math:`a < b` and :math:`d < b-a`. Sampling `f` consists in computing points of this function with abscissas beginning with `x=a`, with uniform increments of `d`, and such all of them are less than or equal to `b`. Values `a`, `b` and `d` can be real. Save the following functions into file ``sampling.py``. #. Write the function ``positives(a, b, d, k)`` that returns the average of the function `f` values (ordinates of the sampled points) in the given interval which are positive. Function `f` is defined as: :math:`f(x, k) = e^{\frac{x}{k}} - k sin(x)`, :math:`k >0`. If there is no positive value, this function must return 0.0. Examples: .. literalinclude:: positives.txt :language: python3 :lines: 3- .. note:: More tests can be found in file :download:`positives.txt ` #. Write the function ``localmax(a, b, d, k)`` that returns a list of tuples where each tuple is the coordinates pair `(x, y)` of those points that are local maxima of the function :math:`f(x, k) = e^{\frac{x}{k}} - k sin(x)`, :math:`k >0` in the given interval. A point (x, y) is a local maxima if its ordinate is greater than the ordinate of the previous sampled point and of that of the next one. Examples: .. literalinclude:: localmax.txt :language: python3 :lines: 3- .. note:: More tests can be found in file :download:`localmax.txt ` #. Write the function ``fposneg (a, b, k, n)`` that returns the number of sampled positive or zero values and the number of sampled negative values of function :math:`f(x, k) = e^{\frac{x}{k}} - k sin(x)`, :math:`k >0` in the given interval. In this case ``n`` stands for the number of points to be sampled (including the interval extreme points). Examples: .. literalinclude:: fposneg.txt :language: python3 :lines: 3- .. note:: More tests can be found in file :download:`fposneg.txt ` .. rubric:: Solution Solutions can be found in file :download:`sampling.py `