matrices.py 文件源码

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

项目:simupy 作者: sixpearls 项目源码 文件源码
def system_from_matrix_DE(mat_DE, mat_var, mat_input=None, constants={}):
    """
    Construct a symbolic DynamicalSystem using matrices. See
    riccati_system example.

    Parameters
    ----------
    mat_DE : sympy Matrix
        The matrix derivative expression (right hand side)
    mat_var : sympy Matrix
        The matrix state
    mat_input : list-like of input expressions, optional
        A list-like of input expressions in the matrix differential equation
    constants : dict, optional
        Dictionary of constants substitutions.

    Returns
    -------
    sys : DynamicalSystem
        A DynamicalSystem which can be used to numerically solve the matrix
        differential equation.
    """
    vec_var = list(set(sp.flatten(mat_var.tolist())))
    vec_DE = sp.Matrix.zeros(len(vec_var), 1)

    iterator = np.nditer(mat_DE, flags=['multi_index', 'refs_ok'])
    for it in iterator:
        i, j = iterator.multi_index
        idx = vec_var.index(mat_var[i, j])
        vec_DE[idx] = mat_DE[i, j]

    sys = DynamicalSystem(vec_DE, sp.Matrix(vec_var), mat_input,
                          constants_values=constants)
    return sys
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号