Chiel
Chiel

Reputation: 6194

Solve differential equation with SymPy

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

enter image description here

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

enter image description here

but SymPy gives

enter image description here

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)

Upvotes: 3

Views: 4643

Answers (1)

user6655984
user6655984

Reputation:

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)

Upvotes: 4

Related Questions