competing_reactions.py 文件源码

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

项目:kinpy 作者: dudektria 项目源码 文件源码
def reaction(y0, t, k0, k0r, k1, k1r):
    """
    Wrapper for the reaction.
    It receives an `np.array` `y0` with the initial concentrations and an
    `np.array` `t` with timestamps (it should also include `0`).
    This function solves the corresponding ODE system and returns an `np.array`
    `Y` in which each column represents a chemical species and each line a
    timestamp.
    """
    def dydt(y, t):
        return np.array([
                         -2*v_0(y[0], y[2], y[1])-1*v_1(y[0], y[2], y[3]),
                         -1*v_0(y[0], y[2], y[1]),
                         +1*v_0(y[0], y[2], y[1])-1*v_1(y[0], y[2], y[3]),
                         +1*v_1(y[0], y[2], y[3]),
                         ])

    # 2*A + B <-> C
    def v_0(A, C, B):
        return k0 * A**2 * B**1 - k0r * C**1

    # A + C <-> D
    def v_1(A, C, D):
        return k1 * A**1 * C**1 - k1r * D**1

    return odeint(dydt, y0, t)

# Reaction rates:
# 2*A + B <-> C
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号