简体   繁体   中英

Solve differential equation with SymPy

I have the following differential equation that I would like to solve with SymPy

在此处输入图片说明

This differential equation has the implicit solution (with h(0) = [0,1) and t = [0, inf) )

在此处输入图片说明

but SymPy gives

在此处输入图片说明

which other packages such as Maxima are able to find. With SymPy I am unable, however. Is there a way to do so? My code is

import sympy as sp
sp.init_printing(use_unicode=True)
h = sp.symbols('h', function=True)
t = sp.symbols('t')
eq = sp.Eq(sp.Derivative(h(t),t), (1 - h(t))**sp.Rational(4,3) / h(t))
sp.dsolve(eq)

SymPy leaves the integral unevaluated because it is unsure about the sign of 1-y in the integral.

The differential equation has a singularity at h=1, and its behavior depends on what side of 1 we are. There isn't a way to say that h(t) < 1, but one can substitute h(t) = 1 - g(t) where g is a positive function:

g = sp.symbols('g', function=True, positive=True)
eq1 = eq.subs(h(t), 1 - g(t))
print(sp.dsolve(eq1))

This returns an explicit solution of the ODE (actually three of them, as SymPy solves a cubic equation). The first one of those looks reasonable.

Eq(g(t), (-2*(C1 + t)/(sqrt(-8*(C1 + t)**3 + 729) + 27)**(1/3) - (sqrt(-8*(C1 + t)**3 + 729) + 27)**(1/3))**3/27)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM