Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Unfortuantely, desolve_system doesn't take a solution_dict parameter -- you can do desolve_system?? to see that it doesn't take that keyword argument. Luckily, it's easy to make such a function that returns the solutions in a dictionary.

def desolve_system_dict(*args, **kwds):
    use_dict = kwds.pop('solution_dict', False)
    solution = desolve_system(*args, **kwds)
    if use_dict:
        return dict((eq.lhs(), eq.rhs()) for eq in solution)
    else:
        return solution

Then you can use it like this:

sage: t = var('t')
sage: x = function('x', t)
sage: y = function('y', t)
sage: de1 = diff(x,t) + y - 1 == 0
sage: de2 = diff(y,t) - x + 1 == 0
sage: desolve_system_dict([de1, de2], [x,y])
[x(t) == (x(0) - 1)*cos(t) - (y(0) - 1)*sin(t) + 1,
 y(t) == (x(0) - 1)*sin(t) + (y(0) - 1)*cos(t) + 1]
sage: desolve_system_dict([de1, de2], [x,y], solution_dict=True)
{y(t): (y(0) - 1)*cos(t) + (x(0) - 1)*sin(t) + 1, 
 x(t): -(y(0) - 1)*sin(t) + (x(0) - 1)*cos(t) + 1}