【问题标题】:Coefficent Matrix in Python - Group elementsPython中的系数矩阵 - 组元素
【发布时间】:2014-06-25 22:53:16
【问题描述】:

我在 Python 中使用 Sympy 获得了这个矩阵:

> Matrix([[-THETA*l*m2*omega**2*cos(omega*t) + X*k*cos(omega*t) -
> X*omega**2*(m1 + m2)*cos(omega*t)], [THETA*g*cos(omega*t) -
> THETA*l*omega**2*cos(omega*t) - X*omega**2*cos(omega*t)]])

我现在需要找到如下表达式:

[coefficient matrix]*(unknowns vectors)

我的(未知向量)在哪里:

Matrix([[X],[THETA]]).

我尝试使用 Sympy 的求解、简化和收集,但没有成功(我只能得到错误或 [] 返回)。

【问题讨论】:

    标签: python matrix sympy coefficients


    【解决方案1】:

    Jacobian

    In [16]: a.jacobian(Matrix([X, THETA]))
    Out[16]:
    ⎡              2                                2              ⎤
    ⎢k⋅cos(ω⋅t) - ω ⋅(m₁ + m₂)⋅cos(ω⋅t)      -l⋅m₂⋅ω ⋅cos(ω⋅t)     ⎥
    ⎢                                                              ⎥
    ⎢             2                                      2         ⎥
    ⎣           -ω ⋅cos(ω⋅t)             g⋅cos(ω⋅t) - l⋅ω ⋅cos(ω⋅t)⎦
    
    In [17]: a.jacobian(Matrix([X, THETA]))*Matrix([X, THETA])
    Out[17]:
    ⎡              2              ⎛              2                   ⎞⎤
    ⎢- THETA⋅l⋅m₂⋅ω ⋅cos(ω⋅t) + X⋅⎝k⋅cos(ω⋅t) - ω ⋅(m₁ + m₂)⋅cos(ω⋅t)⎠⎥
    ⎢                                                                 ⎥
    ⎢             ⎛                2         ⎞      2                 ⎥
    ⎣       THETA⋅⎝g⋅cos(ω⋅t) - l⋅ω ⋅cos(ω⋅t)⎠ - X⋅ω ⋅cos(ω⋅t)        ⎦
    
    In [22]: a
    Out[22]:
    ⎡              2                              2                   ⎤
    ⎢- THETA⋅l⋅m₂⋅ω ⋅cos(ω⋅t) + X⋅k⋅cos(ω⋅t) - X⋅ω ⋅(m₁ + m₂)⋅cos(ω⋅t)⎥
    ⎢                                                                 ⎥
    ⎢                                 2               2               ⎥
    ⎣     THETA⋅g⋅cos(ω⋅t) - THETA⋅l⋅ω ⋅cos(ω⋅t) - X⋅ω ⋅cos(ω⋅t)      ⎦
    

    顺便说一句,如果您使用thetaTheta(不是全部大写),SymPy 会将其打印为实际的希腊字母 theta:

    In [24]: symbols('theta')
    Out[24]: θ
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 2021-07-10
      • 2019-03-31
      • 1970-01-01
      相关资源
      最近更新 更多