def interpolate_value(x, y, t):
    """Find the value of x: y(x) = t."""
    if t > max(y) or t < min(y):
        raise RuntimeError('t outside of [%f, %f]' % (min(y), max(y)))
    for j in range(1, len(x)):
        x0 = x[j - 1]
        y0 = y[j - 1]
        x1 = x[j]
        y1 = y[j]
        if (y0 - t) * (y1 - t) < 0:
            return x0 + (t - y0) * (x1 - x0) / (y1 - y0)
