q_vec, omega_vec, q1, q2, q3, w1, w2, w3 = \
sym.symbols('q_vec, omega_vec, q1, q2, q3, w1, w2, w3')
q_0_dot_str = '.5 * dot(q_vec, omega_vec)'
q_0_dot_symp = sym.sympify(q_0_dot_str)
q_0_dot_symp = q_0_dot_symp.subs([(q_vec, sym.Matrix([q1, q2, q3]), \
(omega_vec, sym.Matrix([w1, w2, w3]).T))])
q_0_dot_fcn = lambdify((q1, q2, q3, w1, w2, w3), q_0_dot_symp, 'numpy')
-或者-
q_0_dot_str = '.5 * dot(q_vec, omega_vec)'
q_0_dot_symp = sym.sympify(q_0_dot_str)
q_0_dot_symp = q_0_dot_symp.subs([(q_vec, sym.Matrix([q1, q2, q3]), \
(omega_vec, sym.Matrix([w1, w2, w3]).T))])
q_0_dot_symp = q_0_dot_symp.xreplace([{q_vec: sym.Matrix([q1, q2, q3])},\
{omega_vec: sym.Matrix([w1, w2, w3]).T}])
q_0_dot_fcn = lambdify((q1, q2, q3, w1, w2, w3), q_0_dot_symp, 'numpy')
但这些都不起作用。当我评估以下内容时:
q_0_dot_fcn(1,2,3,4,5,6)
我得到:
0.5*omega_vec*q_vec
而不是在我为符号矩阵中的符号变量提供的值中进行替换(然后得到一个实际的 m=numerical 结果)。