def linear_interpol(x, x1, x2, y1, y2):
    """
    Linearly interpolate to point x, between
    the points (x1,y1), (x2,y2)
    """
    assert x1 <= x
    assert x2 >= x
    assert x1 <= x2
    alpha = (x - x1) / (x2 - x1)
    return (1.0 - alpha) * y1 + alpha * y2
