transient_sources.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:SpicePy 作者: giaccone 项目源码 文件源码
def pwl(pairs, t):
    """
    PWL describes a piecewise linear waveform

    :param pairs: a 2D list. Each rom is a pair [time, value]
    :param t: array with times where the function has to be evaluated
    :return: the function values at times defined in t
    """

    # convert pairs to np.array is necessary
    if isinstance(pairs, list):
        pairs = np.array(pairs)

    # check pairs format
    if pairs.ndim == 1:
        pairs.shape = (-1,2)

    # get pairs
    x = []
    y = []
    for xk, yk in pairs:
        x.append(xk)
        y.append(yk)

    # create linear interpolator
    fun = interp1d(x, y, bounds_error=False, fill_value=(y[0], y[-1]), assume_sorted=True)
    # interpolation
    out = fun(t)

    return out
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号