在Sympy中使用动力学符号的微分方程

时间:2017-09-12 04:53:26

标签: python sympy symbolic-math differential-equations

在Sympy,我试图解决这样的微分方程:

from sympy import *
from sympy.physics.vector import dynamicsymbols
x = dynamicsymbols('x')
diffeq = Eq(x(t).diff(t), x(t))
dsolve(diffeq, x(t))

但是返回

TypeError                           Traceback (most recent call last)
<ipython-input-10-8a45d7148b24> in <module>()
      1 x = dynamicsymbols('x')
----> 2 diffeq = Eq(x(t).diff(t), x(t))
      3 dsolve(diffeq, x(t))

TypeError: 'x' object is not callable

据我了解,dynamicsymbols创建了t的函数,那么如何在微分方程中使用它呢?

1 个答案:

答案 0 :(得分:1)

Sympy docs are a bit confusing作为

的输出
print(x)

实际上是

x(t)

然而,这并不意味着要致电x(t)

from sympy import *
from sympy.physics.vector import dynamicsymbols
x = dynamicsymbols('x')
diffeq = Eq(diff(x, Symbol('t')), x)
dsolve(diffeq, x)   # Eq(x(t), C1*exp(t))