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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With