Till now, I haven't faced any issue while solving well-posed differential equations problems using sympy only in python such as
- Solving a second order linear differential equation:
import matplotlib.pyplot as plt
from sympy import dsolve, symbols, Function, Eq
t= symbols('t')
x= symbols('x',cls=Function)
deq =Eq(x(t).diff(t,t)+2*t**2*x(t).diff(t)+x(t),0)
sol =dsolve(deq, x(t))
print(sol)
- Solving an initial-valued problem:
from sympy import dsolve, symbols, Function, Eq, pprint
t = symbols('t')
x = symbols('x', cls = Function)
deq = Eq(x(t).diff(t)+t*x(t), t**3)
sol = dsolve(deq, n=8, ics={x(0):1})
pprint(sol)
- Solving a system of differential equations:
from sympy import dsolve, Eq, Function, symbols
t= symbols('t')
x= symbols('x',cls=Function)
y = symbols('y',cls=Function)
deq = (Eq(x(t).diff(t),x(t)*y(t)*sin(t)),Eq(y(t).diff(t),y(t)*2*sin(t)))
sol = dsolve(deq1, [x(t),y(t)])
print(sol)
- Solving a differential equation and plotting a particular integral curve:
from matplotlib import pyplot as plt
from sympy import dsolve, Eq, symbols, Function
import numpy as np
t = symbols('t')
x = symbols('x', cls=Function)
deqn4 = Eq(2*(t-1)*x(t).diff(t),3*t**2+4*t+2)
sol4 = dsolve(deqn4, x(t))
print(sol4)
t = np.arange(-2.2,2.2,.2)
x = np.arange(-2,4.2,.2)
T, X = np.meshgrid(t,x)
Z = X**2 -2*X -T**3 -2*T**2 -2*T
fig, ax = plt.subplots()
CS = ax.contour(T, X,Z, [3])
I know that scipy is more flexible than the sympy, but results of sympy looks more fascinating as per my tittle experience of solving dynamical system problems using python.