问题
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.
回答1:
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).
来源:https://stackoverflow.com/questions/26172733/syntax-for-solving-system-of-differential-equations-in-sympy