Home:ALL Converter>Can we prioritise SymPy over SciPy while solving well posed differential equations?

Can we prioritise SymPy over SciPy while solving well posed differential equations?

Ask Time:2021-05-07T14:32:20         Author:Lakshman

Json Formatter

Till now, I haven't faced any issue while solving well-posed differential equations problems using sympy only in python such as

  1. 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)
  1. 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)
  1. 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)
  1. 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.

Author:Lakshman,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/67430010/can-we-prioritise-sympy-over-scipy-while-solving-well-posed-differential-equatio
yy