Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有一个表达式,例如c1 / (c2*s + c3)我希望 sympy 将表达式转换为一个看起来像C1 / (s + C2)这样的模板,C1 = c1/c2并且C2 = c3/c2.
c1 / (c2*s + c3)
C1 / (s + C2)
C1 = c1/c2
C2 = c3/c2
有没有简单的方法可以做到这一点?
所以你在问“C1 和 C2 必须是什么才能实现这一点?” solve可以回答这个问题:
solve
>>> v = var('c1:4 C1:3 s') >>> expr = c1 / (c2*s + c3) >>> tmpl = C1 / (s + C2) >>> t = tmpl.free_symbols - expr.free_symbols >>> solve(expr - tmpl, t, dict=True) [{C1: c1/c2, C2: c3/c2}]