sympy/sympy — pull request #1322 by Krastanov (2012-05-30 21:00:42+00:00)
Title: Staging a linear ODE system solver.

"""Solve a system of ODEs with optional initial conditions.

Initial conditions are supplied as part of the list of equations. For the
moment the preprocessor for initial conditions is quite simple, thus take
care to insure that there are no free variables in the equations
corresponding to initial conditions.

>>> from sympy import ode_system, Symbol, Function
>>> func = Function('f')
>>> gunc = Function('g')
>>> x = Symbol('x')
>>> f = func(x)
>>> f_ = f.diff(x)
>>> f__ = f_.diff(x)
>>> g = gunc(x)
>>> g_ = g.diff(x)
>>> g__ = g_.diff(x)

Simple equation:
>>> sys = [f_+f]
>>> sol = ode_system(sys, [f], x)
>>> sol[f]
C1*exp(-x)

With initial conditions:
>>> sys = [f_+f, func(0)-2]
>>> sol = ode_system(sys, [f], x)
>>> sol[f]
2*exp(-x)

With "boundary" conditions:
>>> sys = [f_+f, func(2)-3]
>>> sol = ode_system(sys, [f], x)
>>> sol[f]
3*exp(2)*exp(-x)

Second order system:
>>> sys = [f__+f]
>>> sol = ode_system(sys, [f], x)
>>> sol[f]
I*C1*exp(-I*x) - I*C2*exp(I*x)

Due to deficiencies in `Derivative` you must jump through hoops to get
initials conditions working here:
>>> sys = [g-f_, f+g_] # The same as [f__+f] just substitute g_ = f__
>>> sol = ode_system(sys, [f, g], x)
>>> sol[f]
I*C1*exp(-I*x) - I*C2*exp(I*x)

Adding the initial conditions:
>>> sys = [g-f_, f+g_, func(0)-1, gunc(0)]
>>> sol = ode_system(sys, [f, g], x)
>>> sol[f]
exp(I*x)/2 + exp(-I*x)/2
"""