import math

def f(x, k):
    return math.exp (x/k)- k*math.sin(x) 

def positives (a, b, d, k):
    x = a
    summ = 0
    n = 0
    while x <= b:
        y = f (x, k)
        if y > 0:
            summ = summ + y
            n = n +1
        x = x + d
    if n != 0 :
        return summ / n
    else:
        return 0.0

def localmax (a, b, d, k):
    lmax = []
    x1, x2, x3 = a, a + d, a + 2*d
    y1, y2, y3 = f(x1, k), f(x2, k), f(x3, k)
    while x3 <= b:
        if y1 < y2 > y3:
            lmax.append((x2, y2))
        x1, x2, x3 = x2, x3, x3+d
        y1, y2, y3 = y2, y3, f(x3, k)
    return lmax

def fposneg (a, b, k, n):
    d = (b-a)/(n-1)
    x = a
    npos =0
    nneg =0
    while x <= b:
        y = f (x, k)
        if y >= 0:
            npos = npos + 1
        else:
            nneg = nneg + 1
        x = x + d
    return npos, nneg
