2
我想找到解決以下微分方程的一種優雅的方式:Sympy:求解微分方程
from sympy import *
init_printing()
M, phi, t, r = symbols('M phi t r')
eq = Eq(-M * phi(t).diff(t), Rational(3, 2) * m * r**2 * phi(t).diff(t) * phi(t).diff(t,t))
我假設島(T)爲.diff(t)不爲零。因此縮短了左側和右側。
這是我如何得到解決:
# I assume d/dt(phi(t)) != 0
theta = symbols('theta')
eq = eq.subs({phi(t).diff(t, 2): theta}) # remove the second derivative
eq = eq.subs({phi(t).diff(t): 1}) # the first derivative is shortened
eq = eq.subs({theta: phi(t).diff(t, 2)}) # get the second derivative back
dsolve(eq, phi(t))
如何解決這個更優雅?