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
评论列表
文章目录