Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syntax for solving system of differential equations in sympy

Tags:

sympy

I am new to sympy and in the process of learning it. I was browsing through the documentation and questions in stack exchange regarding symbolically solving a system of differential equations with initial conditions using sympy.

I have a simple system of ODE-s

( dV/dt )  = -(  1 / RC ) * ( V(t) ) + I(t)/C

( dI/dt )  = -( R1 /  L ) * ( I(t) ) - ( 1 / L) * V(t) + Vs/L

with initial conditions V(0) = V0 and I(0) = I0

I browsed through a lot of questions in stack exchange and not successful in finding an appropriate answer. It would be of great help if somebody can show me a syntax to enter a system of coupled differential equations with initial conditions.

like image 888
Swaminathan Narayanaswami Avatar asked Oct 03 '14 03:10

Swaminathan Narayanaswami


1 Answers

System of ODEs support is only in the development version of SymPy. It will be added in 0.7.6. The syntax would be

V, I = symbols("V I", cls=Function)
RC, t, C, Vs, L, R1, V0, I0 = symbols("RC t C Vs L R1 V0 I0")
system = [Eq(V(t).diff(t), -1/RC*V(t) + I(t)/C), Eq(I(t).diff(t), -R1/L*I(t) - 1/L*V(t) + Vs/L)]
ics = {V(0): V0, I(0): I0}
dsolve(system, [V(t), I(t)], ics=ics)

It seems that there is a bug that prevents this from working in the current SymPy master, unless I mistyped something (https://github.com/sympy/sympy/issues/8193).

like image 142
asmeurer Avatar answered Nov 14 '22 15:11

asmeurer